diff --git a/auth_generate_password/__init__.py b/auth_generate_password/__init__.py new file mode 100644 index 000000000..782a258d8 --- /dev/null +++ b/auth_generate_password/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password 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 . +# +############################################################################## + +from . import model diff --git a/auth_generate_password/__openerp__.py b/auth_generate_password/__openerp__.py new file mode 100644 index 000000000..03241dca0 --- /dev/null +++ b/auth_generate_password/__openerp__.py @@ -0,0 +1,70 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password module for Odoo +# Copyright (C) 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 . +# +############################################################################## + +{ + 'name': 'Password Secure', + 'version': '2.0', + 'category': 'GRAP - Custom', + 'description': """ +Password Secure +=============== + +Functionnality: +--------------- + * Forbid users to change them password; + * Only members of base.group_system can change password; OK. + * Add a button to the res_users form: + * to change the password (randomly generated); + * send an email to each users; + +Settings: +--------- + * Once the module installed, you have to set two settings: + * password size: the size of the password generated (6 by default); + * password chars: the list of allowed chars (by default ASCII letters + and digits); You can: + * set a list of chars like 'abcdef'; + * use string function like string.ascii_letters; + * Be sure that an Outgoing Email Server is correctly configured; + +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/) + """, + 'author': 'GRAP', + 'website': 'http://www.grap.coop', + 'license': 'AGPL-3', + 'depends': [ + 'email_template', + ], + 'data': [ + 'data/ir_config_parameter.yml', + 'data/email_template.xml', + 'view/view.xml', + ], + 'demo': [ + 'demo/res_groups.yml', + 'demo/res_users.yml', + ], +} diff --git a/auth_generate_password/data/email_template.xml b/auth_generate_password/data/email_template.xml new file mode 100644 index 000000000..b22920aa9 --- /dev/null +++ b/auth_generate_password/data/email_template.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Generate Password + + ]]> + ${object.email|safe} + OpenERP - Password Changed + +
  • Login : ${object.login}
  • +
  • New Password : ${object.password}
  • + +Please, +
      +
    • remember this password and delete this email;
    • +
    • Communicate the password to your team, if you are many people to use the same credentials;
    • +
    ]]> +
    +
    + +
    +
    diff --git a/auth_generate_password/data/ir_config_parameter.yml b/auth_generate_password/data/ir_config_parameter.yml new file mode 100644 index 000000000..6282a0ff7 --- /dev/null +++ b/auth_generate_password/data/ir_config_parameter.yml @@ -0,0 +1,29 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password module for Odoo +# Copyright (C) 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 . +# +############################################################################## + +- !record {model: ir.config_parameter, id: password_size}: + key: auth_generate_password.password_size + value: 6 + +- !record {model: ir.config_parameter, id: password_chars}: + key: auth_generate_password.password_chars + value: string.ascii_letters + string.digits diff --git a/auth_generate_password/demo/res_groups.yml b/auth_generate_password/demo/res_groups.yml new file mode 100644 index 000000000..e52835925 --- /dev/null +++ b/auth_generate_password/demo/res_groups.yml @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password module for Odoo +# Copyright (C) 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 . +# +############################################################################## + +- !record {model: res.groups, id: base.group_no_one}: + users: + - base.user_root diff --git a/auth_generate_password/demo/res_users.yml b/auth_generate_password/demo/res_users.yml new file mode 100644 index 000000000..00b401abe --- /dev/null +++ b/auth_generate_password/demo/res_users.yml @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password module for Odoo +# Copyright (C) 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 . +# +############################################################################## + +- !record {model: res.users, id: extra_user}: + name: Extra User + login: extra + email: extra@example.com diff --git a/auth_generate_password/i18n/fr.po b/auth_generate_password/i18n/fr.po new file mode 100644 index 000000000..2ffaae6cf --- /dev/null +++ b/auth_generate_password/i18n/fr.po @@ -0,0 +1,72 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * auth_generate_password +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-12-09 12:53+0000\n" +"PO-Revision-Date: 2014-12-09 12:53+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: auth_generate_password +#: model:email.template,body_html:auth_generate_password.generate_password_template +msgid "\n" +"Your OpenERP credentials has been changed:\n" +"
      \n" +"
    • Login : ${object.login}
    • \n" +"
    • New Password : ${object.password}
    • \n" +"
    \n" +"Please,\n" +"
      \n" +"
    • remember this password and delete this email;
    • \n" +"
    • Communicate the password to your team, if you are many people to use the same credentials;
    • \n" +"
    \n" +" " +msgstr "\n" +"Vos identifiants OpenERP ont changés :\n" +"
      \n" +"
    • Login : ${object.login}
    • \n" +"
    • Nouveau Mot de passe : ${object.password}
    • \n" +"
    \n" +"Merci de,\n" +"
      \n" +"
    • vous souvenir de ce mot de passe et de supprimer cet email ;
    • \n" +"
    • de communiquer ce mot de passe Ă  votre Ă©quipe, si plusieurs personnes utilisent les mĂȘme identifiants;
    • \n" +"
    \n" +" " + +#. module: auth_generate_password +#: code:addons/auth_generate_password/model/res_users.py:48 +#, python-format +msgid "Cannot send email: user has no email address." +msgstr "Impossible d'envoyer un email : l'utilisateur n'a pas d'adresse." + +#. module: auth_generate_password +#: view:res.users:0 +msgid "Generate Password and Send Mail" +msgstr "Générer un mot de passe et envoyer un email" + +#. module: auth_generate_password +#: model:email.template,subject:auth_generate_password.generate_password_template +msgid "OpenERP - Password Changed" +msgstr "OpenERP - Mot de passe changé" + +#. module: auth_generate_password +#: code:_description:0 +#: model:ir.model,name:auth_generate_password.model_res_users +#, python-format +msgid "Users" +msgstr "Utilisateurs" + +#. module: auth_generate_password +#: view:res.users:0 +msgid "base.group_system" +msgstr "base.group_system" + diff --git a/auth_generate_password/model/__init__.py b/auth_generate_password/model/__init__.py new file mode 100644 index 000000000..e5a505c75 --- /dev/null +++ b/auth_generate_password/model/__init__.py @@ -0,0 +1,23 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password 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 . +# +############################################################################## + +from . import res_users diff --git a/auth_generate_password/model/res_users.py b/auth_generate_password/model/res_users.py new file mode 100644 index 000000000..47d78d4d0 --- /dev/null +++ b/auth_generate_password/model/res_users.py @@ -0,0 +1,61 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password 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 . +# +############################################################################## + +# This line is noqa flaged, to allow users to use string functions written +# in ir_config_parameter +import string # flake8: noqa +import random + +from openerp.osv.orm import Model +from openerp.osv.osv import except_osv +from openerp.tools.translate import _ + + +class res_users(Model): + _inherit = 'res.users' + + def generate_password(self, cr, uid, ids, context=None): + mm_obj = self.pool['mail.mail'] + icp_obj = self.pool['ir.config_parameter'] + imd_obj = self.pool['ir.model.data'] + et_obj = self.pool['email.template'] + password_size = eval(icp_obj.get_param( + cr, uid, 'auth_generate_password.password_size')) + password_chars = eval(icp_obj.get_param( + cr, uid, 'auth_generate_password.password_chars')) + for ru in self.browse(cr, uid, ids, context=context): + if not ru.email: + raise osv.except_osv( + _("Cannot send email: user has no email address."), + user.name) + # Generate Password + password = "".join([random.choice( + password_chars) for n in xrange(password_size)]) + self._set_new_password( + cr, uid, ru.id, None, password, None, context=None) + # Send Mail + et = imd_obj.get_object( + cr, uid, 'auth_generate_password', + 'generate_password_template') + mail_id = et_obj.send_mail( + cr, uid, et.id, ru.id, True, context=context) + return {} diff --git a/auth_generate_password/static/src/img/icon.png b/auth_generate_password/static/src/img/icon.png new file mode 100644 index 000000000..2cb11b276 Binary files /dev/null and b/auth_generate_password/static/src/img/icon.png differ diff --git a/auth_generate_password/tests/__init__.py b/auth_generate_password/tests/__init__.py new file mode 100644 index 000000000..a7320fdc7 --- /dev/null +++ b/auth_generate_password/tests/__init__.py @@ -0,0 +1,27 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password 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 . +# +############################################################################## + +from . import tests + +fast_suite = [ + tests, +] diff --git a/auth_generate_password/tests/tests.py b/auth_generate_password/tests/tests.py new file mode 100644 index 000000000..6a3b67934 --- /dev/null +++ b/auth_generate_password/tests/tests.py @@ -0,0 +1,53 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Authentification - Generate Password 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 . +# +############################################################################## + +from openerp.tests.common import TransactionCase + + +class TestAuthGeneratePassword(TransactionCase): + + def setUp(self): + super(TestAuthGeneratePassword, self).setUp() + cr, uid = self.cr, self.uid + self.imd_obj = self.registry('ir.model.data') + self.ru_obj = self.registry('res.users') + self.mm_obj = self.registry('mail.mail') + self.demo_ru_id = self.imd_obj.get_object_reference( + cr, uid, 'base', + 'user_demo')[1] + self.extra_ru_id = self.imd_obj.get_object_reference( + cr, uid, 'auth_generate_password', + 'extra_user')[1] + + # Test Section + def test_01_generate_password(self): + """[Functional Test] Test if generate password generate mails""" + cr, uid = self.cr, self.uid + ru_ids = [self.demo_ru_id, self.extra_ru_id] + mm_qty_before = len(self.mm_obj.search(cr, uid, [])) + self.ru_obj.generate_password(cr, uid, ru_ids) + mm_qty_after = len(self.mm_obj.search(cr, uid, [])) + + self.assertEquals( + mm_qty_before + len(ru_ids), mm_qty_after, + "Generate password for %d user(s) must send %d email(s) !" % ( + len(ru_ids), len(ru_ids))) diff --git a/auth_generate_password/view/view.xml b/auth_generate_password/view/view.xml new file mode 100644 index 000000000..e1dfe3b24 --- /dev/null +++ b/auth_generate_password/view/view.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + res.users + + + + + + + + res.users + + + +