Port base_user_auth_log to v10

This commit is contained in:
Alexis de Lattre
2018-09-02 22:39:49 +02:00
parent 0d27c0a830
commit 6370dc0ec8
6 changed files with 30 additions and 26 deletions

View File

@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) # Copyright 2017-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Users authentification logs', 'name': 'Users authentification logs',
'version': '8.0.1.0.0', 'version': '10.0.1.0.0',
'category': 'Tools', 'category': 'Tools',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Adds users authentication logs', 'summary': 'Adds users authentication logs',

View File

@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) Copyright 2017-2018 Akretion France
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<openerp> <odoo noupdate="1">
<data noupdate="1"> <!-- noupdate = 1 for the 'active' field -->
<record id="purge_auth_log_cron" model="ir.cron"> <record id="purge_auth_log_cron" model="ir.cron">
<field name="name">Purge old authentication logs</field> <field name="name">Purge old authentication logs</field>
@@ -20,5 +21,5 @@
<field name="args" eval="'()'"/> <field name="args" eval="'()'"/>
</record> </record>
</data>
</openerp> </odoo>

View File

@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) # Copyright 2017-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # 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 import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -13,19 +14,22 @@ class ResUsers(models.Model):
auth_log_ids = fields.One2many( auth_log_ids = fields.One2many(
'res.users.auth.log', 'user_id', string='Authentication Logs') 'res.users.auth.log', 'user_id', string='Authentication Logs')
def _login(self, db, login, password): @classmethod
user_id = super(ResUsers, self)._login(db, login, password) def _login(cls, db, login, password):
user_id = super(ResUsers, cls)._login(db, login, password)
with registry(db).cursor() as cr: with registry(db).cursor() as cr:
if user_id: if user_id:
result = 'success' result = 'success'
user_log_id = user_id
else: 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' result = 'failure'
cr.execute( cr.execute(
"SELECT id FROM res_users WHERE login=%s", (login, )) "SELECT id FROM res_users WHERE login=%s", (login, ))
user_select = cr.fetchall() user_select = cr.fetchall()
if user_select: if user_select:
user_id = user_select[0][0] user_log_id = user_select[0][0]
cr.execute(""" cr.execute("""
INSERT INTO res_users_auth_log ( INSERT INTO res_users_auth_log (
@@ -37,6 +41,6 @@ class ResUsers(models.Model):
user_id user_id
) VALUES ( ) VALUES (
%s, NOW() AT TIME ZONE 'UTC', NOW() AT TIME ZONE 'UTC', %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) logger.info('Auth log created for login %s type %s', login, result)
return user_id return user_id

View File

@@ -2,8 +2,8 @@
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) # © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api, _ from odoo import models, fields, api, _
from openerp.exceptions import Warning as UserError from odoo.exceptions import UserError
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) Copyright 2017-2018 Akretion France
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<openerp> <odoo>
<data>
<record id="view_users_form" model="ir.ui.view"> <record id="view_users_form" model="ir.ui.view">
@@ -22,5 +22,4 @@
</record> </record>
</data> </odoo>
</openerp>

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) Copyright 2017-2018 Akretion France
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<openerp> <odoo>
<data>
<record id="res_users_auth_log_form" model="ir.ui.view"> <record id="res_users_auth_log_form" model="ir.ui.view">
@@ -77,5 +77,4 @@
parent="base.menu_security" sequence="100"/> parent="base.menu_security" sequence="100"/>
</data> </odoo>
</openerp>