Skip to content

Commit f4e873d

Browse files
committed
[MIG] auth_session_timeout: Migration to 20.0
Assisted-by: Claude Opus 5.5
1 parent de68667 commit f4e873d

10 files changed

Lines changed: 87 additions & 63 deletions

File tree

‎auth_session_timeout/README.rst‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Inactive Sessions Timeout
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github
24-
:target: https://github.com/OCA/server-auth/tree/19.0/auth_session_timeout
24+
:target: https://github.com/OCA/server-auth/tree/20.0/auth_session_timeout
2525
:alt: OCA/server-auth
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-0-auth_session_timeout
27+
:target: https://translation.odoo-community.org/projects/server-auth-20-0/server-auth-20-0-auth_session_timeout
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=19.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=20.0
3131
:alt: Try me on Runboat
3232

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

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

@@ -91,6 +91,8 @@ Contributors
9191

9292
- Fernando La Chica <fernandolachica@gmail.com>
9393

94+
- Panithan k. <panithank@ecosoft.co.th>
95+
9496
Maintainers
9597
-----------
9698

@@ -104,6 +106,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
104106
mission is to support the collaborative development of Odoo features and
105107
promote its widespread use.
106108

107-
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/19.0/auth_session_timeout>`_ project on GitHub.
109+
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/20.0/auth_session_timeout>`_ project on GitHub.
108110

109111
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

‎auth_session_timeout/__manifest__.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
{
55
"name": "Inactive Sessions Timeout",
6-
"summary": """
7-
This module disable all inactive sessions since a given delay""",
6+
"summary": "This module disable all inactive sessions since a given delay",
87
"author": "ACSONE SA/NV, "
98
"Dhinesh D, "
109
"Jesse Morgan, "
@@ -14,7 +13,7 @@
1413
"website": "https://github.com/OCA/server-auth",
1514
"category": "Tools",
1615
"development_status": "Production/Stable",
17-
"version": "19.0.1.0.0",
16+
"version": "20.0.1.0.0",
1817
"license": "AGPL-3",
1918
"data": ["data/ir_config_parameter_data.xml"],
2019
"installable": True,
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# (c) 2015 ACSONE SA/NV, Dhinesh D
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

4-
from odoo import api, models, tools
4+
from odoo import api, models
55

66
DELAY_KEY = "inactive_session_time_out_delay"
77
IGNORED_PATH_KEY = "inactive_session_time_out_ignored_url"
@@ -11,32 +11,18 @@ class IrConfigParameter(models.Model):
1111
_inherit = "ir.config_parameter"
1212

1313
@api.model
14-
@tools.ormcache("self.env.cr.dbname")
14+
@api.ormcache("self.env.cr.dbname")
1515
def _auth_timeout_get_parameter_delay(self):
16-
return int(
17-
self.env["ir.config_parameter"]
18-
.sudo()
19-
.get_param(
20-
DELAY_KEY,
21-
7200,
22-
)
23-
)
16+
return self.env["ir.config_parameter"].sudo().get_int(DELAY_KEY, 7200)
2417

2518
@api.model
26-
@tools.ormcache("self.env.cr.dbname")
19+
@api.ormcache("self.env.cr.dbname")
2720
def _auth_timeout_get_parameter_ignored_urls(self):
28-
urls = (
29-
self.env["ir.config_parameter"]
30-
.sudo()
31-
.get_param(
32-
IGNORED_PATH_KEY,
33-
"",
34-
)
35-
)
21+
urls = self.env["ir.config_parameter"].sudo().get_str(IGNORED_PATH_KEY, "")
3622
return urls.split(",")
3723

3824
def write(self, vals):
3925
res = super().write(vals)
4026
if DELAY_KEY == self.key or IGNORED_PATH_KEY == self.key:
41-
self.env.registry.clear_cache()
27+
self.env.transaction.invalidate_ormcache()
4228
return res

‎auth_session_timeout/models/res_users.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from time import time
99

1010
from odoo import api, http, models
11-
from odoo.http import SessionExpiredException
11+
from odoo.http.session import SessionExpiredException, logout, session_store
1212

1313
_logger = logging.getLogger(__name__)
1414

@@ -49,7 +49,7 @@ def _auth_timeout_session_terminate(self, session):
4949
False: session timeout cancelled
5050
"""
5151
if session.db and session.uid:
52-
session.logout(keep_db=True)
52+
logout(session, keep_db=True)
5353
return True
5454

5555
@api.model
@@ -67,7 +67,7 @@ def _auth_timeout_check(self):
6767
# Check if past deadline
6868
expired = False
6969
if deadline is not False:
70-
path = http.root.session_store.get_session_filename(session.sid)
70+
path = session_store().get_session_path(session.sid)
7171
try:
7272
expired = getmtime(path) < deadline
7373
except OSError:
@@ -91,9 +91,7 @@ def _auth_timeout_check(self):
9191

9292
if http.request.httprequest.path not in ignored_urls:
9393
if "path" not in locals():
94-
path = http.root.session_store.get_session_filename(
95-
session.sid,
96-
)
94+
path = session_store().get_session_path(session.sid)
9795
try:
9896
utime(path, None)
9997
except OSError:

‎auth_session_timeout/readme/CONTRIBUTORS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
- Chandresh Thakkar \<<cthakkar@opensourceintegrators.com>\>
77
- [Greenice](https://www.greenice.com):
88
- Fernando La Chica \<<fernandolachica@gmail.com>\>
9+
- Panithan k. \<<panithank@ecosoft.co.th>\>

‎auth_session_timeout/static/description/index.html‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Inactive Sessions Timeout</title>
77
<style type="text/css">
88

99
/*
@@ -374,7 +374,7 @@ <h1>Inactive Sessions Timeout</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:8e98443184c3b0e60db12b9e37347a6f80af392496fb96e8dd0fc0032a93d8b9
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/19.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 image-reference" href="https://translation.odoo-community.org/projects/server-auth-19-0/server-auth-19-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-auth&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/20.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 image-reference" href="https://translation.odoo-community.org/projects/server-auth-20-0/server-auth-20-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-auth&amp;target_branch=20.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This module was written to be able to kill(logout) all inactive sessions
379379
since a given delay. On each request the server checks if the session is
380380
yet valid regarding the expiration delay. If not a clean logout is
@@ -412,7 +412,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
412412
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-auth/issues">GitHub Issues</a>.
413413
In case of trouble, please check there if your issue has already been reported.
414414
If you spotted it first, help us to smash it by providing a detailed and welcomed
415-
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
415+
<a class="reference external" href="https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2020.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
416416
<p>Do not contact contributors directly about support or help with technical issues.</p>
417417
</div>
418418
<div class="section" id="credits">
@@ -439,6 +439,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
439439
<li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
440440
</ul>
441441
</li>
442+
<li>Panithan k. &lt;<a class="reference external" href="mailto:panithank&#64;ecosoft.co.th">panithank&#64;ecosoft.co.th</a>&gt;</li>
442443
</ul>
443444
</div>
444445
<div class="section" id="maintainers">
@@ -450,7 +451,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
450451
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
451452
mission is to support the collaborative development of Odoo features and
452453
promote its widespread use.</p>
453-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/19.0/auth_session_timeout">OCA/server-auth</a> project on GitHub.</p>
454+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-auth/tree/20.0/auth_session_timeout">OCA/server-auth</a> project on GitHub.</p>
454455
<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>
455456
</div>
456457
</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import test_ir_config_parameter
22
from . import test_res_users
3+
from . import test_http
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2026 Ecosoft Co., Ltd. (https://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
import os
5+
import time
6+
7+
from odoo.http.session import session_store
8+
from odoo.tests import HttpCase, tagged
9+
10+
from ..models.ir_config_parameter import DELAY_KEY
11+
12+
13+
@tagged("post_install", "-at_install")
14+
class TestSessionTimeoutHttp(HttpCase):
15+
def setUp(self):
16+
super().setUp()
17+
self.env["ir.config_parameter"].set_int(DELAY_KEY, 60)
18+
self.authenticate("admin", "admin")
19+
20+
def _age_session_file(self, seconds):
21+
path = session_store().get_session_path(self.session.sid)
22+
past = time.time() - seconds
23+
os.utime(path, (past, past))
24+
return path
25+
26+
def test_active_session_kept(self):
27+
path = self._age_session_file(30)
28+
self.make_jsonrpc_request("/web/session/check")
29+
# activity refreshes the session file
30+
self.assertGreater(os.path.getmtime(path), time.time() - 30)
31+
32+
def test_inactive_session_logged_out(self):
33+
self._age_session_file(120)
34+
res = self.url_open("/odoo", allow_redirects=False)
35+
self.assertEqual(res.status_code, 303)
36+
self.assertIn("/web/login", res.headers["Location"])

‎auth_session_timeout/tests/test_ir_config_parameter.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ def setUp(self):
3131
self.param_obj = self.env["ir.config_parameter"]
3232
self.get_param_called = False
3333
test = self
34+
model_cls = type(self.param_obj)
35+
for name in ("get_int", "get_str"):
36+
orig = getattr(model_cls, name)
3437

35-
def get_param(*args, **kwargs):
36-
test.get_param_called = True
37-
return orig_get_param(*args[1:], **kwargs)
38+
def getter(*args, _orig=orig, **kwargs):
39+
test.get_param_called = True
40+
return _orig(*args, **kwargs)
3841

39-
orig_get_param = self.param_obj.get_param
40-
self.patch(type(self.param_obj), "get_param", get_param)
42+
self.patch(model_cls, name, getter)
4143

4244
def test_auth_timeout_get_parameter_delay_cache(self):
4345
"""It should cache the parameter call."""
@@ -54,13 +56,13 @@ def test_auth_timeout_get_parameter_ignored_urls_cache(self):
5456
def test_check_param_writes_clear_delay_cache(self):
5557
self.param_obj._auth_timeout_get_parameter_delay()
5658
self.get_param_called = False
57-
self.param_obj.set_param("inactive_session_time_out_delay", 7201)
59+
self.param_obj.set_int("inactive_session_time_out_delay", 7201)
5860
self.param_obj._auth_timeout_get_parameter_delay()
5961
self.assertTrue(self.get_param_called)
6062

6163
def test_check_param_writes_clear_ignore_url_cache(self):
6264
self.param_obj._auth_timeout_get_parameter_ignored_urls()
6365
self.get_param_called = False
64-
self.param_obj.set_param("inactive_session_time_out_ignored_url", "example.com")
66+
self.param_obj.set_str("inactive_session_time_out_ignored_url", "example.com")
6567
self.param_obj._auth_timeout_get_parameter_ignored_urls()
6668
self.assertTrue(self.get_param_called)

‎auth_session_timeout/tests/test_res_users.py‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,40 @@ def _mock_assets(self, assets=None):
2828
"""
2929
if assets is None:
3030
assets = ["http"]
31+
assets = list(assets) + ["session_store", "logout"]
3132
patches = {name: mock.DEFAULT for name in assets}
3233
with mock.patch.multiple(
3334
"odoo.addons.auth_session_timeout.models.res_users", **patches
3435
) as mocks:
3536
yield mocks
3637

37-
def _auth_timeout_check(self, http_mock):
38+
def _auth_timeout_check(self, assets):
3839
"""It wraps ``_auth_timeout_check`` for easier calling"""
3940
self.db = mock.MagicMock()
4041
self.uid = mock.MagicMock()
4142
self.passwd = mock.MagicMock()
4243
self.path = "/this/is/a/test/path"
43-
get_filename = http_mock.root.session_store.get_session_filename
44-
get_filename.return_value = self.path
44+
get_path = assets["session_store"].return_value.get_session_path
45+
get_path.return_value = self.path
4546
return self.ResUsers._auth_timeout_check()
4647

4748
def test_session_validity_no_request(self):
4849
"""It should return immediately if no request"""
4950
with self._mock_assets() as assets:
5051
assets["http"].request = False
51-
res = self._auth_timeout_check(assets["http"])
52+
res = self._auth_timeout_check(assets)
5253
self.assertFalse(res)
5354

5455
def test_session_validity_gets_session_file(self):
5556
"""It should call get the session file for the session id"""
5657
with self._mock_assets() as assets:
5758
get_params = assets["http"].request.env[""].get_session_parameters
5859
get_params.return_value = 0, []
59-
store = assets["http"].root.session_store
60-
store.get_session_filename.side_effect = EndTestException
60+
store = assets["session_store"].return_value
61+
store.get_session_path.side_effect = EndTestException
6162
with self.assertRaises(EndTestException):
62-
self._auth_timeout_check(assets["http"])
63-
store.get_session_filename.assert_called_once_with(
63+
self._auth_timeout_check(assets)
64+
store.get_session_path.assert_called_once_with(
6465
assets["http"].request.session.sid,
6566
)
6667

@@ -70,8 +71,9 @@ def test_session_validity_logout(self):
7071
get_params = assets["http"].request.env[""].get_session_parameters
7172
get_params.return_value = -9999, []
7273
assets["getmtime"].return_value = 0
73-
self._auth_timeout_check(assets["http"])
74-
assets["http"].request.session.logout.assert_called_once_with(
74+
self._auth_timeout_check(assets)
75+
assets["logout"].assert_called_once_with(
76+
assets["http"].request.session,
7577
keep_db=True,
7678
)
7779

@@ -81,11 +83,8 @@ def test_session_validity_updates_utime(self):
8183
get_params = assets["http"].request.env[""].get_session_parameters
8284
get_params.return_value = 9999, []
8385
assets["getmtime"].return_value = time.time()
84-
self._auth_timeout_check(assets["http"])
85-
assets["utime"].assert_called_once_with(
86-
assets["http"].root.session_store.get_session_filename(),
87-
None,
88-
)
86+
self._auth_timeout_check(assets)
87+
assets["utime"].assert_called_once_with(self.path, None)
8988

9089
@mute_logger("odoo.addons.auth_session_timeout.models.res_users")
9190
def test_session_validity_os_error_guard(self):
@@ -94,14 +93,13 @@ def test_session_validity_os_error_guard(self):
9493
get_params = assets["http"].request.env[""].get_session_parameters
9594
get_params.return_value = 0, []
9695
assets["getmtime"].side_effect = OSError
97-
self._auth_timeout_check(assets["http"])
96+
self._auth_timeout_check(assets)
9897

9998
def test_on_timeout_session_loggedout(self):
10099
with self._mock_assets(["http", "getmtime"]) as assets:
101100
assets["getmtime"].return_value = 0
102101
assets["http"].request.session.uid = self.env.uid
103102
assets["http"].request.session.dbname = self.env.cr.dbname
104103
assets["http"].request.session.sid = 123
105-
assets["http"].request.session.logout = mock.Mock()
106104
self.ResUsers._auth_timeout_check()
107-
self.assertTrue(assets["http"].request.session.logout.called)
105+
self.assertTrue(assets["logout"].called)

0 commit comments

Comments
 (0)