Port base_user_auth_log to v10
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
# -*- 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).
|
||||
|
||||
{
|
||||
'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',
|
||||
@@ -1,11 +1,12 @@
|
||||
<?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).
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data noupdate="1"> <!-- noupdate = 1 for the 'active' field -->
|
||||
<odoo noupdate="1">
|
||||
|
||||
|
||||
<record id="purge_auth_log_cron" model="ir.cron">
|
||||
<field name="name">Purge old authentication logs</field>
|
||||
@@ -20,5 +21,5 @@
|
||||
<field name="args" eval="'()'"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# -*- 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).
|
||||
|
||||
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
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
||||
# 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__)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?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).
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="view_users_form" model="ir.ui.view">
|
||||
@@ -22,5 +22,4 @@
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?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).
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="res_users_auth_log_form" model="ir.ui.view">
|
||||
@@ -77,5 +77,4 @@
|
||||
parent="base.menu_security" sequence="100"/>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user