Skip to content

Commit

Permalink
[MIG] auth_session_timeout: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed Nov 23, 2023
1 parent 6cdfd2c commit 914676c
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 83 deletions.
53 changes: 29 additions & 24 deletions auth_session_timeout/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ 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/16.0/auth_session_timeout
:target: https://github.com/OCA/server-auth/tree/17.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-16-0/server-auth-16-0-auth_session_timeout
:target: https://translation.odoo-community.org/projects/server-auth-17-0/server-auth-17-0-auth_session_timeout
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

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.
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.

**Table of contents**

Expand All @@ -40,13 +41,12 @@ regarding the expiration delay. If not a clean logout is operated.
Configuration
=============


Two system parameters are available:

* ``inactive_session_time_out_delay``: validity of a session in seconds
(default = 2 Hours)
* ``inactive_session_time_out_ignored_url``: technical urls where the check
does not occur
- ``inactive_session_time_out_delay``: validity of a session in seconds
(default = 2 Hours)
- ``inactive_session_time_out_ignored_url``: technical urls where the
check does not occur

Usage
=====
Expand All @@ -59,35 +59,40 @@ 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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20auth_session_timeout%0Aversion:%2016.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:%2017.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.

Credits
=======

Authors
~~~~~~~
-------

* ACSONE SA/NV
* Dhinesh D
* Jesse Morgan
* LasLabs

Contributors
~~~~~~~~~~~~
------------

- Cédric Pigeon <[email protected]>
- Dhinesh D <[email protected]>
- Jesse Morgan <[email protected]>
- Dave Lasley <[email protected]>
- Nadia Afakrouch <[email protected]>
- Chandresh Thakkar <[email protected]>
- `Greenice <https://www.greenice.com>`__:

- Fernando La Chica <[email protected]>

- `APSL <https://apsl.tech>`__:

* Cédric Pigeon <[email protected]>
* Dhinesh D <[email protected]>
* Jesse Morgan <[email protected]>
* Dave Lasley <[email protected]>
* Nadia Afakrouch <[email protected]>
* Chandresh Thakkar <[email protected]>
* `Greenice <https://www.greenice.com>`_:
* Fernando La Chica <[email protected]>
- Antoni Marroig <[email protected]>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -99,6 +104,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/16.0/auth_session_timeout>`_ project on GitHub.
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/17.0/auth_session_timeout>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion auth_session_timeout/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"website": "https://github.com/OCA/server-auth",
"category": "Tools",
"development_status": "Production/Stable",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"data": ["data/ir_config_parameter_data.xml"],
"installable": True,
Expand Down
16 changes: 6 additions & 10 deletions auth_session_timeout/models/ir_config_parameter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# (c) 2015 ACSONE SA/NV, Dhinesh D
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, models, tools
from odoo import api, models

DELAY_KEY = "inactive_session_time_out_delay"
IGNORED_PATH_KEY = "inactive_session_time_out_ignored_url"
Expand All @@ -11,7 +11,6 @@ class IrConfigParameter(models.Model):
_inherit = "ir.config_parameter"

@api.model
@tools.ormcache("self.env.cr.dbname")
def _auth_timeout_get_parameter_delay(self):
return int(
self.env["ir.config_parameter"]
Expand All @@ -23,7 +22,6 @@ def _auth_timeout_get_parameter_delay(self):
)

@api.model
@tools.ormcache("self.env.cr.dbname")
def _auth_timeout_get_parameter_ignored_urls(self):
urls = (
self.env["ir.config_parameter"]
Expand All @@ -36,11 +34,9 @@ def _auth_timeout_get_parameter_ignored_urls(self):
return urls.split(",")

def write(self, vals):
res = super(IrConfigParameter, self).write(vals)
self._auth_timeout_get_parameter_delay.clear_cache(
self.filtered(lambda r: r.key == DELAY_KEY),
)
self._auth_timeout_get_parameter_ignored_urls.clear_cache(
self.filtered(lambda r: r.key == IGNORED_PATH_KEY),
)
res = super().write(vals)
self.env.registry.clear_cache()
self._auth_timeout_get_parameter_delay()
self.env.registry.clear_cache()
self._auth_timeout_get_parameter_ignored_urls()
return res
3 changes: 1 addition & 2 deletions auth_session_timeout/models/ir_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@


class IrHttp(models.AbstractModel):

_inherit = "ir.http"

@classmethod
def _authenticate(cls, endpoint):
res = super(IrHttp, cls)._authenticate(endpoint=endpoint)
res = super()._authenticate(endpoint=endpoint)
if (
request
and request.session
Expand Down
1 change: 0 additions & 1 deletion auth_session_timeout/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def _auth_timeout_check(self):
if deadline is not False:
path = http.root.session_store.get_session_filename(session.sid)
try:

expired = getmtime(path) < deadline
except OSError:
_logger.exception(
Expand Down
3 changes: 3 additions & 0 deletions auth_session_timeout/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
6 changes: 6 additions & 0 deletions auth_session_timeout/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Two system parameters are available:

- `inactive_session_time_out_delay`: validity of a session in seconds
(default = 2 Hours)
- `inactive_session_time_out_ignored_url`: technical urls where the
check does not occur
7 changes: 0 additions & 7 deletions auth_session_timeout/readme/CONFIGURE.rst

This file was deleted.

10 changes: 10 additions & 0 deletions auth_session_timeout/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- Cédric Pigeon \<<[email protected]>\>
- Dhinesh D \<<[email protected]>\>
- Jesse Morgan \<<[email protected]>\>
- Dave Lasley \<<[email protected]>\>
- Nadia Afakrouch \<<[email protected]>\>
- Chandresh Thakkar \<<[email protected]>\>
- [Greenice](https://www.greenice.com):
- Fernando La Chica \<<[email protected]>\>
- [APSL](https://apsl.tech):
- Antoni Marroig \<<[email protected]>\>
8 changes: 0 additions & 8 deletions auth_session_timeout/readme/CONTRIBUTORS.rst

This file was deleted.

4 changes: 4 additions & 0 deletions auth_session_timeout/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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.
3 changes: 0 additions & 3 deletions auth_session_timeout/readme/DESCRIPTION.rst

This file was deleted.

File renamed without changes.
27 changes: 17 additions & 10 deletions auth_session_timeout/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,11 @@ <h1 class="title">Inactive Sessions Timeout</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:809af48b1b6d53fa519fcbd3e75285f656e3e862e7c5c57ba2e7e3a800fab2ff
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/16.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-16-0/server-auth-16-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=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-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>
<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/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-auth/tree/17.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-17-0/server-auth-17-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=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-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>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -393,8 +394,8 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ul class="simple">
<li><tt class="docutils literal">inactive_session_time_out_delay</tt>: validity of a session in seconds
(default = 2 Hours)</li>
<li><tt class="docutils literal">inactive_session_time_out_ignored_url</tt>: technical urls where the check
does not occur</li>
<li><tt class="docutils literal">inactive_session_time_out_ignored_url</tt>: technical urls where the
check does not occur</li>
</ul>
</div>
<div class="section" id="usage">
Expand All @@ -406,7 +407,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">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 to smash 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:%2016.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:%2017.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 @@ -429,8 +430,14 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<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>
<li><a class="reference external" href="https://www.greenice.com">Greenice</a>:
* Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
<li><a class="reference external" href="https://www.greenice.com">Greenice</a>:<ul>
<li>Fernando La Chica &lt;<a class="reference external" href="mailto:fernandolachica&#64;gmail.com">fernandolachica&#64;gmail.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://apsl.tech">APSL</a>:<ul>
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:toni.marroig1&#64;gmail.com">toni.marroig1&#64;gmail.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -440,7 +447,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">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/16.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/17.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
35 changes: 21 additions & 14 deletions auth_session_timeout/tests/test_ir_config_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests import common
import logging

from odoo.tests.common import TransactionCase

class TestIrConfigParameter(common.TransactionCase):
logger = logging.getLogger()


class TestIrConfigParameter(TransactionCase):
def setUp(self):
super(TestIrConfigParameter, self).setUp()
super().setUp()
self.db = self.env.cr.dbname
self.param_obj = self.env["ir.config_parameter"]
self.data_obj = self.env["ir.model.data"]
Expand All @@ -25,24 +29,27 @@ def test_check_session_param_urls(self):
self.assertIsInstance(urls, list)


class TestIrConfigParameterCaching(common.TransactionCase):
def setUp(self):
super(TestIrConfigParameterCaching, self).setUp()
self.db = self.env.cr.dbname
self.param_obj = self.env["ir.config_parameter"]
self.get_param_called = False
test = self
class TestIrConfigParameterCaching(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.db = cls.env.cr.dbname
cls.param_obj = cls.env["ir.config_parameter"]
cls.get_param_called = False
test = cls

def get_param(*args, **kwargs):
logger.info("hola")
test.get_param_called = True
return orig_get_param(*args[1:], **kwargs)

orig_get_param = self.param_obj.get_param
self.param_obj._patch_method("get_param", get_param)
orig_get_param = cls.param_obj.get_param
cls.param_obj.get_param("get_param", get_param)
logger.info("func", dir(cls.param_obj))

def tearDown(self):
super(TestIrConfigParameterCaching, self).tearDown()
self.param_obj._revert_method("get_param")
super().tearDown()
self.param_obj.set_param("get_param", "")

def test_auth_timeout_get_parameter_delay_cache(self):
"""It should cache the parameter call."""
Expand Down
7 changes: 4 additions & 3 deletions auth_session_timeout/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class EndTestException(Exception):


class TestResUsers(TransactionCase):
def setUp(self):
super(TestResUsers, self).setUp()
self.ResUsers = self.env["res.users"]
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ResUsers = cls.env["res.users"]

@contextmanager
def _mock_assets(self, assets=None):
Expand Down

0 comments on commit 914676c

Please sign in to comment.