diff --git a/base_user_auth_log/__openerp__.py b/base_user_auth_log/__manifest__.py similarity index 80% rename from base_user_auth_log/__openerp__.py rename to base_user_auth_log/__manifest__.py index bc79bbd..eb7a921 100644 --- a/base_user_auth_log/__openerp__.py +++ b/base_user_auth_log/__manifest__.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) +# Copyright 2017-2018 Akretion France +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Users authentification logs', - 'version': '8.0.1.0.0', + 'version': '10.0.1.0.0', 'category': 'Tools', 'license': 'AGPL-3', 'summary': 'Adds users authentication logs', diff --git a/base_user_auth_log/data/ir_cron.xml b/base_user_auth_log/data/ir_cron.xml index 90db7eb..c306d2b 100644 --- a/base_user_auth_log/data/ir_cron.xml +++ b/base_user_auth_log/data/ir_cron.xml @@ -1,11 +1,12 @@ - - + + Purge old authentication logs @@ -20,5 +21,5 @@ - - + + diff --git a/base_user_auth_log/models/res_users.py b/base_user_auth_log/models/res_users.py index 3878d89..76ec249 100644 --- a/base_user_auth_log/models/res_users.py +++ b/base_user_auth_log/models/res_users.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -# © 2017 Akretion (Alexis de Lattre ) +# Copyright 2017-2018 Akretion France +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, fields, registry, SUPERUSER_ID +from odoo import models, fields, registry, SUPERUSER_ID import logging logger = logging.getLogger(__name__) @@ -13,19 +14,22 @@ class ResUsers(models.Model): auth_log_ids = fields.One2many( 'res.users.auth.log', 'user_id', string='Authentication Logs') - def _login(self, db, login, password): - user_id = super(ResUsers, self)._login(db, login, password) + @classmethod + def _login(cls, db, login, password): + user_id = super(ResUsers, cls)._login(db, login, password) with registry(db).cursor() as cr: if user_id: result = 'success' + user_log_id = user_id else: - user_id = None # To write a null value, psycopg2 wants None + # To write a null value, psycopg2 wants None + user_log_id = None result = 'failure' cr.execute( "SELECT id FROM res_users WHERE login=%s", (login, )) user_select = cr.fetchall() if user_select: - user_id = user_select[0][0] + user_log_id = user_select[0][0] cr.execute(""" INSERT INTO res_users_auth_log ( @@ -37,6 +41,6 @@ class ResUsers(models.Model): user_id ) VALUES ( %s, NOW() AT TIME ZONE 'UTC', NOW() AT TIME ZONE 'UTC', - %s, %s, %s)""", (SUPERUSER_ID, login, result, user_id)) + %s, %s, %s)""", (SUPERUSER_ID, login, result, user_log_id)) logger.info('Auth log created for login %s type %s', login, result) return user_id diff --git a/base_user_auth_log/models/res_users_auth_log.py b/base_user_auth_log/models/res_users_auth_log.py index 1bec710..11e946a 100644 --- a/base_user_auth_log/models/res_users_auth_log.py +++ b/base_user_auth_log/models/res_users_auth_log.py @@ -2,8 +2,8 @@ # © 2017 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, fields, api, _ -from openerp.exceptions import Warning as UserError +from odoo import models, fields, api, _ +from odoo.exceptions import UserError from datetime import datetime, timedelta import logging logger = logging.getLogger(__name__) diff --git a/base_user_auth_log/views/res_users.xml b/base_user_auth_log/views/res_users.xml index c100ad4..2aeeb9e 100644 --- a/base_user_auth_log/views/res_users.xml +++ b/base_user_auth_log/views/res_users.xml @@ -1,11 +1,11 @@ - - + @@ -22,5 +22,4 @@ - - + diff --git a/base_user_auth_log/views/res_users_auth_log.xml b/base_user_auth_log/views/res_users_auth_log.xml index 2f75f33..c63c631 100644 --- a/base_user_auth_log/views/res_users_auth_log.xml +++ b/base_user_auth_log/views/res_users_auth_log.xml @@ -1,11 +1,11 @@ - - + @@ -77,5 +77,4 @@ parent="base.menu_security" sequence="100"/> - - +