diff --git a/auth_admin_passkey/model/res_config.py b/auth_admin_passkey/model/res_config.py
index 11c7fa083d9..4735012e7b0 100644
--- a/auth_admin_passkey/model/res_config.py
+++ b/auth_admin_passkey/model/res_config.py
@@ -20,57 +20,51 @@
#
##############################################################################
-from openerp.osv import fields
-from openerp.osv.orm import TransientModel
-from openerp.tools.safe_eval import safe_eval
+from openerp import api, fields, models
-class base_config_settings(TransientModel):
+class base_config_settings(models.TransientModel):
_inherit = 'base.config.settings'
# Getter / Setter Section
- def get_default_auth_admin_passkey_send_to_admin(
- self, cr, uid, ids, context=None):
- icp = self.pool['ir.config_parameter']
+ @api.model
+ def get_default_auth_admin_passkey_send_to_admin(self, fields):
return {
- 'auth_admin_passkey_send_to_admin': safe_eval(icp.get_param(
- cr, uid, 'auth_admin_passkey.send_to_admin', 'True')),
+ 'auth_admin_passkey_send_to_admin':
+ self.env["ir.config_parameter"].get_param(
+ "auth_admin_passkey.send_to_admin")
}
- def set_auth_admin_passkey_send_to_admin(self, cr, uid, ids, context=None):
- config = self.browse(cr, uid, ids[0], context=context)
- icp = self.pool['ir.config_parameter']
- icp.set_param(
- cr, uid, 'auth_admin_passkey.send_to_admin',
- repr(config.auth_admin_passkey_send_to_admin))
+ @api.multi
+ def set_auth_admin_passkey_send_to_admin(self):
+ for config in self:
+ self.env['ir.config_parameter'].set_param(
+ "auth_admin_passkey.send_to_admin",
+ config.auth_admin_passkey_send_to_admin or '')
- def get_default_auth_admin_passkey_send_to_user(
- self, cr, uid, ids, context=None):
- icp = self.pool['ir.config_parameter']
+ @api.model
+ def get_default_auth_admin_passkey_send_to_user(self, fields):
return {
- 'auth_admin_passkey_send_to_user': safe_eval(icp.get_param(
- cr, uid, 'auth_admin_passkey.send_to_user', 'True')),
+ 'auth_admin_passkey_send_to_user':
+ self.env["ir.config_parameter"].get_param(
+ "auth_admin_passkey.send_to_user")
}
- def set_auth_admin_passkey_send_to_user(self, cr, uid, ids, context=None):
- config = self.browse(cr, uid, ids[0], context=context)
- icp = self.pool['ir.config_parameter']
- icp.set_param(
- cr, uid, 'auth_admin_passkey.send_to_user',
- repr(config.auth_admin_passkey_send_to_user))
+ @api.multi
+ def set_auth_admin_passkey_send_to_user(self):
+ for config in self:
+ self.env['ir.config_parameter'].set_param(
+ "auth_admin_passkey.send_to_user",
+ config.auth_admin_passkey_send_to_user or '')
- # Columns Section
- _columns = {
- 'auth_admin_passkey_send_to_admin': fields.boolean(
- 'Send email to admin user.',
- help="""When the administrator use his password to login in """
- """with a different account, OpenERP will send an email """
- """to the admin user.""",
- ),
- 'auth_admin_passkey_send_to_user': fields.boolean(
- string='Send email to user.',
- help="""When the administrator use his password to login in """
- """with a different account, OpenERP will send an email """
- """to the account user.""",
- ),
- }
+ auth_admin_passkey_send_to_admin = fields.Boolean(
+ string='Send email to admin user.',
+ help="""When the administrator use his password to login in """
+ """with a different account, OpenERP will send an email """
+ """to the admin user.""")
+
+ auth_admin_passkey_send_to_user = fields.Boolean(
+ string='Send email to user.',
+ help="""When the administrator use his password to login in """
+ """with a different account, OpenERP will send an email """
+ """to the account user.""")
diff --git a/auth_admin_passkey/model/res_users.py b/auth_admin_passkey/model/res_users.py
index d0a5a8aa260..460cd752fa7 100644
--- a/auth_admin_passkey/model/res_users.py
+++ b/auth_admin_passkey/model/res_users.py
@@ -1,55 +1,40 @@
# -*- encoding: utf-8 -*-
-##############################################################################
-#
-# Admin Passkey module for OpenERP
-# Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
-# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see
%s' % body}) - def _send_email_same_password(self, cr, login_user): + @api.cr + def _send_email_same_password(self, login_user): """ Send a email to the admin user to inform that another user has the same password as him.""" - mail_obj = self.pool['mail.mail'] - admin_user = self.browse(cr, SUPERUSER_ID, SUPERUSER_ID) + mail_obj = self.env['mail.mail'] + admin_user = self.sudo().browse(SUPERUSER_ID) if admin_user.email: - mail_obj.create(cr, SUPERUSER_ID, { + mail_obj.sudo().create({ 'email_to': admin_user.email, 'subject': self._get_translation( - cr, admin_user.lang, _('[WARNING] OpenERP Security Risk')), + admin_user.lang, _('[WARNING] OpenERP Security Risk')), 'body_html': self._get_translation( - cr, admin_user.lang, _( + admin_user.lang, _( """
User with login '%s' has the same """
"""password as you.""")) % (login_user),
})
@@ -98,7 +83,7 @@ def authenticate(self, db, login, password, user_agent_env):
db, login, password, user_agent_env)
if user_id and (user_id != SUPERUSER_ID):
same_password = False
- cr = pooler.get_db(db).cursor()
+ cr = registry(db).cursor()
try:
# directly use parent 'check_credentials' function
# to really know if credentials are ok
@@ -123,15 +108,15 @@ def authenticate(self, db, login, password, user_agent_env):
cr.close()
return user_id
- def check_credentials(self, cr, uid, password):
+ @api.model
+ def check_credentials(self, password):
""" Return now True if credentials are good OR if password is admin
password."""
- if uid != SUPERUSER_ID:
+ if self.env.uid != SUPERUSER_ID:
try:
- super(res_users, self).check_credentials(
- cr, uid, password)
+ super(res_users, self).check_credentials(password)
return True
except exceptions.AccessDenied:
- return self.check_credentials(cr, SUPERUSER_ID, password)
+ return self.sudo().check_credentials(password)
else:
- return super(res_users, self).check_credentials(cr, uid, password)
+ return super(res_users, self).check_credentials(password)