Skip to content

Commit

Permalink
[MIG] auth_session_timeout: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandresh-SerpentCS authored and astirpe committed Oct 17, 2024
1 parent fe1b8ff commit f2ef556
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 23 deletions.
11 changes: 6 additions & 5 deletions auth_session_timeout/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Inactive Sessions Timeout
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
:target: https://github.com/OCA/server-auth/tree/13.0/auth_session_timeout
:target: https://github.com/OCA/server-auth/tree/14.0/auth_session_timeout
:alt: OCA/server-auth
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-auth-13-0/server-auth-13-0-auth_session_timeout
:target: https://translation.odoo-community.org/projects/server-auth-14-0/server-auth-14-0-auth_session_timeout
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/251/13.0
:target: https://runbot.odoo-community.org/runbot/251/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -56,7 +56,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -79,6 +79,7 @@ Contributors
* Jesse Morgan <[email protected]>
* Dave Lasley <[email protected]>
* Nadia Afakrouch <[email protected]>
* Chandresh Thakkar <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -93,6 +94,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/13.0/auth_session_timeout>`_ project on GitHub.
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/14.0/auth_session_timeout>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions auth_session_timeout/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"LasLabs, "
"Odoo Community Association (OCA)",
"maintainer": "Odoo Community Association (OCA)",
"website": "http://www.github.com/OCA/server-auth",
"website": "https://github.com/OCA/server-auth",
"category": "Tools",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"data": ["data/ir_config_parameter_data.xml"],
"installable": True,
Expand Down
1 change: 0 additions & 1 deletion auth_session_timeout/data/ir_config_parameter_data.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!--
(c) 2015 ACSONE SA/NV, Dhinesh D
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand Down
23 changes: 22 additions & 1 deletion auth_session_timeout/i18n/auth_session_timeout.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -13,11 +13,32 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: auth_session_timeout
#: model:ir.model.fields,field_description:auth_session_timeout.field_ir_config_parameter__display_name
#: model:ir.model.fields,field_description:auth_session_timeout.field_ir_http__display_name
#: model:ir.model.fields,field_description:auth_session_timeout.field_res_users__display_name
msgid "Display Name"
msgstr ""

#. module: auth_session_timeout
#: model:ir.model,name:auth_session_timeout.model_ir_http
msgid "HTTP Routing"
msgstr ""

#. module: auth_session_timeout
#: model:ir.model.fields,field_description:auth_session_timeout.field_ir_config_parameter__id
#: model:ir.model.fields,field_description:auth_session_timeout.field_ir_http__id
#: model:ir.model.fields,field_description:auth_session_timeout.field_res_users__id
msgid "ID"
msgstr ""

#. module: auth_session_timeout
#: model:ir.model.fields,field_description:auth_session_timeout.field_ir_config_parameter____last_update
#: model:ir.model.fields,field_description:auth_session_timeout.field_ir_http____last_update
#: model:ir.model.fields,field_description:auth_session_timeout.field_res_users____last_update
msgid "Last Modified on"
msgstr ""

#. module: auth_session_timeout
#: model:ir.model,name:auth_session_timeout.model_ir_config_parameter
msgid "System Parameter"
Expand Down
18 changes: 16 additions & 2 deletions auth_session_timeout/models/ir_config_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ class IrConfigParameter(models.Model):
@api.model
@tools.ormcache("self.env.cr.dbname")
def _auth_timeout_get_parameter_delay(self):
return int(self.env["ir.config_parameter"].sudo().get_param(DELAY_KEY, 7200,))
return int(
self.env["ir.config_parameter"]
.sudo()
.get_param(
DELAY_KEY,
7200,
)
)

@api.model
@tools.ormcache("self.env.cr.dbname")
def _auth_timeout_get_parameter_ignored_urls(self):
urls = self.env["ir.config_parameter"].sudo().get_param(IGNORED_PATH_KEY, "",)
urls = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
IGNORED_PATH_KEY,
"",
)
)
return urls.split(",")

def write(self, vals):
Expand Down
4 changes: 2 additions & 2 deletions auth_session_timeout/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class IrHttp(models.AbstractModel):
_inherit = "ir.http"

@classmethod
def _authenticate(cls, auth_method="user"):
res = super(IrHttp, cls)._authenticate(auth_method=auth_method)
def _authenticate(cls, endpoint):
res = super(IrHttp, cls)._authenticate(endpoint=endpoint)
if request and request.env and request.env.user:
request.env.user._auth_timeout_check()
return res
8 changes: 6 additions & 2 deletions auth_session_timeout/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def _auth_timeout_check(self):

expired = getmtime(path) < deadline
except OSError:
_logger.exception("Exception reading session file modified time.",)
_logger.exception(
"Exception reading session file modified time.",
)
# Force expire the session. Will be resolved with new session.
expired = True

Expand All @@ -90,7 +92,9 @@ def _auth_timeout_check(self):

if http.request.httprequest.path not in ignored_urls:
if "path" not in locals():
path = http.root.session_store.get_session_filename(session.sid,)
path = http.root.session_store.get_session_filename(
session.sid,
)
try:
utime(path, None)
except OSError:
Expand Down
1 change: 1 addition & 0 deletions auth_session_timeout/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Jesse Morgan <[email protected]>
* Dave Lasley <[email protected]>
* Nadia Afakrouch <[email protected]>
* Chandresh Thakkar <[email protected]>
7 changes: 4 additions & 3 deletions auth_session_timeout/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Inactive Sessions Timeout</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-auth/tree/13.0/auth_session_timeout"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-auth-13-0/server-auth-13-0-auth_session_timeout"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/251/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-auth/tree/14.0/auth_session_timeout"><img alt="OCA/server-auth" src="https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-auth-14-0/server-auth-14-0-auth_session_timeout"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/251/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module was written to be able to kill(logout) all inactive sessions since
a given delay. On each request the server checks if the session is yet valid
regarding the expiration delay. If not a clean logout is operated.</p>
Expand Down Expand Up @@ -404,7 +404,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-auth/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -426,6 +426,7 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<li>Jesse Morgan &lt;<a class="reference external" href="mailto:jmorgan.nz&#64;gmail.com">jmorgan.nz&#64;gmail.com</a>&gt;</li>
<li>Dave Lasley &lt;<a class="reference external" href="mailto:dave&#64;laslabs.com">dave&#64;laslabs.com</a>&gt;</li>
<li>Nadia Afakrouch &lt;<a class="reference external" href="mailto:nadia.afa&#64;gmail.com">nadia.afa&#64;gmail.com</a>&gt;</li>
<li>Chandresh Thakkar &lt;<a class="reference external" href="mailto:cthakkar&#64;opensourceintegrators.com">cthakkar&#64;opensourceintegrators.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -435,7 +436,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/13.0/auth_session_timeout">OCA/server-auth</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/14.0/auth_session_timeout">OCA/server-auth</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
11 changes: 6 additions & 5 deletions auth_session_timeout/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
class EndTestException(Exception):
""" It stops tests from continuing """

pass


class TestResUsers(TransactionCase):
def setUp(self):
Expand All @@ -24,7 +22,7 @@ def setUp(self):

@contextmanager
def _mock_assets(self, assets=None):
""" It provides mocked imports from res_users.py
"""It provides mocked imports from res_users.py
:param assets: (list) Name of imports to mock. Mocks `http` if None
:return: (dict) Dictionary of mocks, keyed by module name
"""
Expand Down Expand Up @@ -74,7 +72,9 @@ def test_session_validity_logout(self):
assets["getmtime"].return_value = 0
with self.assertRaises(SessionExpiredException):
self._auth_timeout_check(assets["http"])
assets["http"].request.session.logout.assert_called_once_with(keep_db=True,)
assets["http"].request.session.logout.assert_called_once_with(
keep_db=True,
)

def test_session_validity_updates_utime(self):
""" It should update utime of session file if not expired """
Expand All @@ -84,7 +84,8 @@ def test_session_validity_updates_utime(self):
assets["getmtime"].return_value = time.time()
self._auth_timeout_check(assets["http"])
assets["utime"].assert_called_once_with(
assets["http"].root.session_store.get_session_filename(), None,
assets["http"].root.session_store.get_session_filename(),
None,
)

@mute_logger("odoo.addons.auth_session_timeout.models.res_users")
Expand Down

0 comments on commit f2ef556

Please sign in to comment.