diff --git a/access_restriction_by_ip/models/allowed_ips.py b/access_restriction_by_ip/models/allowed_ips.py index 2d0f0ef18..aac0beb3a 100644 --- a/access_restriction_by_ip/models/allowed_ips.py +++ b/access_restriction_by_ip/models/allowed_ips.py @@ -18,13 +18,17 @@ # ############################################################################## from odoo import api, models, fields - +from odoo.http import request class ResUsersInherit(models.Model): _inherit = 'res.users' allowed_ips = fields.One2many('allowed.ips', 'users_ip', string='IP') + def action_logout(self): + session = self.env['ir.http'].session_info() + + class AllowedIPs(models.Model): _name = 'allowed.ips' diff --git a/access_restriction_by_ip/static/src/js/widget.js b/access_restriction_by_ip/static/src/js/widget.js index 8c076176c..b18d31b53 100644 --- a/access_restriction_by_ip/static/src/js/widget.js +++ b/access_restriction_by_ip/static/src/js/widget.js @@ -1,13 +1,13 @@ /** @odoo-module **/ import SystrayMenu from 'web.SystrayMenu'; import Widget from 'web.Widget'; -var ajax = require('web.ajax'); -var core = require('web.core'); +import ajax from 'web.ajax'; +import core from 'web.core'; var qweb = core.qweb; var GetUser = Widget.extend({ /** - function run before loading the page to call methode "get_idle_time" + function run before loading the page to call method "get_user" */ willStart: function() { var self = this; @@ -19,15 +19,30 @@ var GetUser = Widget.extend({ Getting minutes through python for the corresponding user in the backend */ get_user: function() { - var self = this - var now = new Date().getTime(); + var self = this; ajax.rpc('/get_ip').then(function(data) { - console.log(data) if (data == false){ location.replace("/web/session/logout") } - }) + }); + }, + /** + Binding mouseup event + */ + start: function() { + var self = this; + this._super.apply(this, arguments).then(function() { + $(document).on('mouseup', self.onMouseUp.bind(self)); + }); + }, + /** + Function to be called on mouseup event + */ + onMouseUp: function(event) { + this.get_user(); }, }); + +// Ensure the widget is added to the Systray menu SystrayMenu.Items.push(GetUser); -export default GetUser; \ No newline at end of file +export default GetUser; diff --git a/access_restriction_by_ip/views/allowed_ips_view.xml b/access_restriction_by_ip/views/allowed_ips_view.xml index a5a528fb1..1ae1db29f 100644 --- a/access_restriction_by_ip/views/allowed_ips_view.xml +++ b/access_restriction_by_ip/views/allowed_ips_view.xml @@ -8,6 +8,7 @@ +