Skip to content

Commit

Permalink
auth_admin_passkey: Migrate module for odoo 10
Browse files Browse the repository at this point in the history
Remove authenticate as check_credentials is dedicated for this
purpose.

Removed mail translations maybe possible in some way ?
Give some space to the code

Make the addon compliant to OCA guidelines
Adapt readme to new template and compress header in tests
Make the addon a python package

NOTE: authenticate() method cannot be used in tests because a new cr
is created in _login method that does not contains our user.

Signed-off-by: Eugen Don <eugen.don@don-systems.de>
  • Loading branch information
Fenkiou committed May 4, 2017
1 parent 5aea3ff commit 3ca787f
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 326 deletions.
98 changes: 80 additions & 18 deletions auth_admin_passkey/README.rst
@@ -1,18 +1,80 @@
Admin password become a passkey for all active logins
=====================================================

Functionality :
---------------
* Administrator has now the possibility to login in with any login;
* By default, Odoo will send a mail to user and admin to indicate them;
* If a user and the admin have the same password, admin will be informed;

Technical information :
-----------------------
* Create two ir_config_parameter to enable / disable mail sending;

Copyright, Author and Licence :
-------------------------------
* Copyright : 2014, Groupement Régional Alimentaire de Proximité;
* Author : Sylvain LE GAL (https://twitter.com/legalsylvain);
* Licence : AGPL-3 (http://www.gnu.org/licenses/)
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

====================
Auth Admin - Passkey
====================

This module extends the functionality of users module to support loging in with the administrator password
in other user accounts.

* Administrator has now the possibility to login in with any login;
* By default, Odoo will send a mail to user and admin to indicate them;
* If a user and the admin have the same password, admin will be informed;


Configuration
=============

To enable notifications for login attempts, you need to:

Go to Settings > General Settings.

Enable the "Send email to admin user" and / or "Send email to user" checkbox


Usage
=====

To login into a different user account type in the user name of the account and the password of the administrator at the login screen


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/10.0


Known issues / Roadmap
======================

None

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Eugen Don <eugen.don@don-systems.de>
* Alexandre Papin (https://twitter.com/Fenkiou)
* Sylvain LE GAL (https://twitter.com/legalsylvain)


Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
6 changes: 3 additions & 3 deletions auth_admin_passkey/__manifest__.py
Expand Up @@ -5,14 +5,14 @@

{
'name': 'Authentification - Admin Passkey',
'version': '8.0.2.1.1',
'version': '10.0.1.0.0',
'category': 'base',
'author': "GRAP,Odoo Community Association (OCA)",
'website': 'http://www.grap.coop',
'license': 'AGPL-3',
'depends': [
'mail',
],
],
'data': [
'data/ir_config_parameter.xml',
'views/res_config_view.xml',
Expand All @@ -24,6 +24,6 @@
'images': [],
'post_load': '',
'application': False,
'installable': False,
'installable': True,
'auto_install': False,
}
22 changes: 2 additions & 20 deletions auth_admin_passkey/data/ir_config_parameter.xml
@@ -1,23 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ********************************************************************** -->
<!--Admin Passkey module for Odoo -->
<!--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 <http://www.gnu.org/licenses/>. -->
<!-- ********************************************************************** -->
<openerp>
<odoo>
<data noupdate="1">

<record id="send_to_admin" model="ir.config_parameter">
Expand All @@ -31,4 +13,4 @@
</record>

</data>
</openerp>
</odoo>
48 changes: 13 additions & 35 deletions auth_admin_passkey/i18n/auth_admin_passkey.pot
@@ -1,33 +1,13 @@
##############################################################################
#
# Admin Passkey module for Odoo
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# Translation of OpenERP Server.
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * auth_admin_passkey
#
msgid ""
msgstr ""
"Project-Id-Version: OpenERP Server 7.0\n"
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-03-23 20:41+0000\n"
"PO-Revision-Date: 2014-03-23 20:41+0000\n"
"POT-Creation-Date: 2017-03-15 19:43+0000\n"
"PO-Revision-Date: 2017-03-15 19:43+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -36,13 +16,13 @@ msgstr ""
"Plural-Forms: \n"

#. module: auth_admin_passkey
#: code:addons/auth_admin_passkey/model/res_users.py:66
#: code:addons/auth_admin_passkey/models/res_users.py:64
#, python-format
msgid "<pre>User with login '%s' has the same password as you.</pre>"
msgstr ""

#. module: auth_admin_passkey
#: code:addons/auth_admin_passkey/model/res_users.py:44
#: code:addons/auth_admin_passkey/models/res_users.py:39
#, python-format
msgid "Admin user used his passkey to login with '%s'.\n"
"\n"
Expand All @@ -56,45 +36,43 @@ msgid "Admin user used his passkey to login with '%s'.\n"
msgstr ""

#. module: auth_admin_passkey
#: view:base.config.settings:0
#: model:ir.ui.view,arch_db:auth_admin_passkey.view_res_config_settings
msgid "Passkey"
msgstr ""

#. module: auth_admin_passkey
#: code:addons/auth_admin_passkey/model/res_users.py:42
#: code:addons/auth_admin_passkey/models/res_users.py:38
#, python-format
msgid "Passkey used"
msgstr ""

#. module: auth_admin_passkey
#: field:base.config.settings,auth_admin_passkey_send_to_admin:0
#: model:ir.model.fields,field_description:auth_admin_passkey.field_base_config_settings_auth_admin_passkey_send_to_admin
msgid "Send email to admin user."
msgstr ""

#. module: auth_admin_passkey
#: field:base.config.settings,auth_admin_passkey_send_to_user:0
#: model:ir.model.fields,field_description:auth_admin_passkey.field_base_config_settings_auth_admin_passkey_send_to_user
msgid "Send email to user."
msgstr ""

#. module: auth_admin_passkey
#: code:_description:0
#: model:ir.model,name:auth_admin_passkey.model_res_users
#, python-format
msgid "Users"
msgstr ""

#. module: auth_admin_passkey
#: help:base.config.settings,auth_admin_passkey_send_to_user:0
#: model:ir.model.fields,help:auth_admin_passkey.field_base_config_settings_auth_admin_passkey_send_to_user
msgid "When the administrator use his password to login in with a different account, Odoo will send an email to the account user."
msgstr ""

#. module: auth_admin_passkey
#: help:base.config.settings,auth_admin_passkey_send_to_admin:0
#: model:ir.model.fields,help:auth_admin_passkey.field_base_config_settings_auth_admin_passkey_send_to_admin
msgid "When the administrator use his password to login in with a different account, Odoo will send an email to the admin user."
msgstr ""

#. module: auth_admin_passkey
#: code:addons/auth_admin_passkey/model/res_users.py:64
#: code:addons/auth_admin_passkey/models/res_users.py:62
#, python-format
msgid "[WARNING] Odoo Security Risk"
msgstr ""
Expand Down
31 changes: 8 additions & 23 deletions auth_admin_passkey/models/__init__.py
@@ -1,24 +1,9 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Admin Passkey module for Odoo
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# Copyright (C) 2013-2014 GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import res_config
from . import res_users
from . import (
res_config,
res_users,
)
65 changes: 35 additions & 30 deletions auth_admin_passkey/models/res_config.py
Expand Up @@ -3,51 +3,56 @@
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
from odoo import api, fields, models
from odoo.tools import safe_eval


class BaseConfigSettings(models.TransientModel):
_inherit = 'base.config.settings'

# Getter / Setter Section
@api.model
def get_default_auth_admin_passkey_send_to_admin(self, fields):
icp = self.env['ir.config_parameter']
return {
'auth_admin_passkey_send_to_admin':
self.env["ir.config_parameter"].get_param(
"auth_admin_passkey.send_to_admin")
'auth_admin_passkey_send_to_admin': safe_eval(icp.get_param(
'auth_admin_passkey.send_to_admin', 'True')),
}

@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 '')

@api.model
def get_default_auth_admin_passkey_send_to_user(self, fields):
icp = self.env['ir.config_parameter']
return {
'auth_admin_passkey_send_to_user':
self.env["ir.config_parameter"].get_param(
"auth_admin_passkey.send_to_user")
'auth_admin_passkey_send_to_user': safe_eval(icp.get_param(
'auth_admin_passkey.send_to_user', 'True')),
}

@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 '')

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, Odoo will send an email """
"""to the admin user.""")

'Send email to admin user.',
help=('When the administrator use his password to login in '
'with a different account, Odoo 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, Odoo will send an email """
"""to the account user.""")
help=('When the administrator use his password to login in '
'with a different account, Odoo will send an email '
'to the account user.'),
)

@api.multi
def set_auth_admin_passkey_send_to_admin(self):
self.ensure_one()

icp = self.env['ir.config_parameter']
icp.set_param(
'auth_admin_passkey.send_to_admin',
repr(self.auth_admin_passkey_send_to_admin))

@api.multi
def set_auth_admin_passkey_send_to_user(self):
self.ensure_one()

icp = self.env['ir.config_parameter']
icp.set_param(
'auth_admin_passkey.send_to_user',
repr(self.auth_admin_passkey_send_to_user))

0 comments on commit 3ca787f

Please sign in to comment.