diff --git a/setup/web_session_auto_close/odoo/addons/web_session_auto_close b/setup/web_session_auto_close/odoo/addons/web_session_auto_close new file mode 120000 index 000000000..ea6cbf57e --- /dev/null +++ b/setup/web_session_auto_close/odoo/addons/web_session_auto_close @@ -0,0 +1 @@ +../../../../web_session_auto_close \ No newline at end of file diff --git a/setup/web_session_auto_close/setup.py b/setup/web_session_auto_close/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_session_auto_close/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_session_auto_close/README.rst b/web_session_auto_close/README.rst new file mode 100644 index 000000000..dbdc5c954 --- /dev/null +++ b/web_session_auto_close/README.rst @@ -0,0 +1,93 @@ +====================== +Web Session Auto Close +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:8e943d4902f551f397f203c4f0b8189984d04003a647b0fd8065bf154b2bcb92 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/13.0/web_session_auto_close + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_session_auto_close + :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/web&target_branch=13.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module automatically closes the session when the last odoo tab is closed or when the computer +gets in idle mode. The `timeout` occurs 15 seconds after the tab has been closed or the computer got idle. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Once installed, the module will ensure that the user session gets closed once the last odoo tab is +closed or when the computer gets idle. The `timeout` occurs 15 seconds after the tab has been closed or the computer got idle. + +No user specific usage is needed. + +Changelog +========= + +13.0.1.0.0 (2023-08-17) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [ADD] web_session_auto_close. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Laurent Stukkens (https://www.acsone.eu) + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_session_auto_close/__init__.py b/web_session_auto_close/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_session_auto_close/__manifest__.py b/web_session_auto_close/__manifest__.py new file mode 100644 index 000000000..fb93c606e --- /dev/null +++ b/web_session_auto_close/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Web Session Auto Close", + "summary": """ + This module purpose is to automatically close the session when the last odoo + tab is closed or when the computer gets in idle mode. + The `timeout` occurs 15 seconds after the tab has been closed or the computer + got idle.""", + "version": "13.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/web", + "depends": ["bus", "web"], + "data": ["views/assets_common.xml", "views/assets_backend.xml"], +} diff --git a/web_session_auto_close/readme/CONTRIBUTORS.rst b/web_session_auto_close/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..0180f2ada --- /dev/null +++ b/web_session_auto_close/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Laurent Stukkens (https://www.acsone.eu) diff --git a/web_session_auto_close/readme/DESCRIPTION.rst b/web_session_auto_close/readme/DESCRIPTION.rst new file mode 100644 index 000000000..d97de223f --- /dev/null +++ b/web_session_auto_close/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module automatically closes the session when the last odoo tab is closed or when the computer +gets in idle mode. The `timeout` occurs 15 seconds after the tab has been closed or the computer got idle. diff --git a/web_session_auto_close/readme/HISTORY.rst b/web_session_auto_close/readme/HISTORY.rst new file mode 100644 index 000000000..e0f5cd578 --- /dev/null +++ b/web_session_auto_close/readme/HISTORY.rst @@ -0,0 +1,4 @@ +13.0.1.0.0 (2023-08-17) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [ADD] web_session_auto_close. diff --git a/web_session_auto_close/readme/USAGE.rst b/web_session_auto_close/readme/USAGE.rst new file mode 100644 index 000000000..524b34f95 --- /dev/null +++ b/web_session_auto_close/readme/USAGE.rst @@ -0,0 +1,4 @@ +Once installed, the module will ensure that the user session gets closed once the last odoo tab is +closed or when the computer gets idle. The `timeout` occurs 15 seconds after the tab has been closed or the computer got idle. + +No user specific usage is needed. diff --git a/web_session_auto_close/static/description/icon.png b/web_session_auto_close/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_session_auto_close/static/description/icon.png differ diff --git a/web_session_auto_close/static/description/index.html b/web_session_auto_close/static/description/index.html new file mode 100644 index 000000000..a3814e927 --- /dev/null +++ b/web_session_auto_close/static/description/index.html @@ -0,0 +1,442 @@ + + + + + + +Web Session Auto Close + + + +
+

Web Session Auto Close

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This module automatically closes the session when the last odoo tab is closed or when the computer +gets in idle mode. The timeout occurs 15 seconds after the tab has been closed or the computer got idle.

+

Table of contents

+ +
+

Usage

+

Once installed, the module will ensure that the user session gets closed once the last odoo tab is +closed or when the computer gets idle. The timeout occurs 15 seconds after the tab has been closed or the computer got idle.

+

No user specific usage is needed.

+
+
+

Changelog

+
+

13.0.1.0.0 (2023-08-17)

+
    +
  • [ADD] web_session_auto_close.
  • +
+
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/web project on GitHub.

+

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

+
+
+
+ + diff --git a/web_session_auto_close/static/src/js/bus_service.js b/web_session_auto_close/static/src/js/bus_service.js new file mode 100644 index 000000000..37304475a --- /dev/null +++ b/web_session_auto_close/static/src/js/bus_service.js @@ -0,0 +1,39 @@ +odoo.define("web_session_auto_close.BusService", function(require) { + "use strict"; + + const BusService = require("bus.BusService"); + const LocalStorageServiceMixin = require("web_session_auto_close.LocalStorageServiceMixin"); + + return BusService.include( + Object.assign(LocalStorageServiceMixin, { + /** + * @override + * @private + */ + _heartbeat() { + this._updateLocalStorageLastPresence(); + this._super.apply(this, arguments); + }, + + /** + * Return whether the current session is valid and does not require a logout. + * @returns {Boolean} + */ + isSessionStillValid() { + let sessionLastPresenceTime = this._getLocalStorageLastPresence() || 0; + try { + sessionLastPresenceTime = parseInt(sessionLastPresenceTime); + } catch (e) { + this._clearLocalStorageLastPresence(); + sessionLastPresenceTime = 0; + } + const timeSinceLastPageRefresh = + new Date().getTime() - sessionLastPresenceTime; + return ( + sessionLastPresenceTime === 0 || + timeSinceLastPageRefresh < this.HEARTBEAT_KILL_OLD_PERIOD + ); + }, + }) + ); +}); diff --git a/web_session_auto_close/static/src/js/local_storage_mixin.js b/web_session_auto_close/static/src/js/local_storage_mixin.js new file mode 100644 index 000000000..d23ebc4a8 --- /dev/null +++ b/web_session_auto_close/static/src/js/local_storage_mixin.js @@ -0,0 +1,46 @@ +odoo.define("web_session_auto_close.LocalStorageServiceMixin", function() { + "use strict"; + + return { + /** + * Get the local storage key to use to manage the last presence time. + * @returns {String} the key of the local storage. + * @private + */ + _getLocalStorageLastPresenceKey() { + const window_origin = location.protocol + "//" + location.host; + // Replace ':', '/' & '//' by '_' + const sanitized_origin = window_origin.replace(/:\/{0,2}/g, "_"); + return `web_session_auto_close.${sanitized_origin}.lastPresenceTime`; + }, + + /** + * Update the last presence time in the local storage. + * @private + */ + _updateLocalStorageLastPresence() { + const now = new Date().getTime(); + localStorage.setItem( + this._getLocalStorageLastPresenceKey(), + now.toString() + ); + }, + + /** + * Get the last presence time from the local storage. + * @returns {String} the last presence time stored in the local storage. + * @private + */ + _getLocalStorageLastPresence() { + return localStorage.getItem(this._getLocalStorageLastPresenceKey()); + }, + + /** + * Clear the last presence key in the local storage. + * @private + */ + _clearLocalStorageLastPresence() { + localStorage.removeItem(this._getLocalStorageLastPresenceKey()); + }, + }; +}); diff --git a/web_session_auto_close/static/src/js/session.js b/web_session_auto_close/static/src/js/session.js new file mode 100644 index 000000000..6db522472 --- /dev/null +++ b/web_session_auto_close/static/src/js/session.js @@ -0,0 +1,21 @@ +odoo.define("web_session_auto_close.Session", function(require) { + "use strict"; + + const LocalStorageServiceMixin = require("web_session_auto_close.LocalStorageServiceMixin"); + const WebSession = require("web.Session"); + + return WebSession.include( + Object.assign(LocalStorageServiceMixin, { + /** + * @override + */ + session_init() { + const result = this._super.apply(this, arguments); + if (!this.session_is_valid()) { + this._clearLocalStorageLastPresence(); + } + return result; + }, + }) + ); +}); diff --git a/web_session_auto_close/static/src/js/web_client.js b/web_session_auto_close/static/src/js/web_client.js new file mode 100644 index 000000000..db4127b0b --- /dev/null +++ b/web_session_auto_close/static/src/js/web_client.js @@ -0,0 +1,24 @@ +odoo.define("web_session_auto_close.WebClient", function(require) { + "use strict"; + + const WebClient = require("web.WebClient"); + + return WebClient.include({ + dependencies: ["bus_service", WebClient.prototype.dependencies], + + /** + * @override + */ + start: function() { + const isSessionStillValid = this.call("bus_service", "isSessionStillValid"); + if (!isSessionStillValid) { + window.location = "/web/session/logout"; + return; + } + const result = this._super.apply(this, arguments); + // We need to ensure that the polling has started as this module relies on that process. + this.call("bus_service", "startPolling"); + return result; + }, + }); +}); diff --git a/web_session_auto_close/views/assets_backend.xml b/web_session_auto_close/views/assets_backend.xml new file mode 100644 index 000000000..d106b2c76 --- /dev/null +++ b/web_session_auto_close/views/assets_backend.xml @@ -0,0 +1,19 @@ + + +