Browse Source

Merge pull request #92 from grap/7.0-auth_generate_password

[ADD] 'auth_generate_password' module to generate randomly user's password
pull/49/merge
Holger Brunn 9 years ago
parent
commit
1587c39bee
  1. 23
      auth_generate_password/__init__.py
  2. 76
      auth_generate_password/__openerp__.py
  3. 45
      auth_generate_password/data/email_template.xml
  4. 32
      auth_generate_password/data/ir_config_parameter.xml
  5. 25
      auth_generate_password/demo/res_groups.yml
  6. 26
      auth_generate_password/demo/res_users.yml
  7. 72
      auth_generate_password/i18n/fr.po
  8. 23
      auth_generate_password/model/__init__.py
  9. 69
      auth_generate_password/model/res_users.py
  10. BIN
      auth_generate_password/static/src/img/icon.png
  11. 27
      auth_generate_password/tests/__init__.py
  12. 58
      auth_generate_password/tests/tests.py
  13. 46
      auth_generate_password/view/view.xml

23
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import model

76
auth_generate_password/__openerp__.py

@ -0,0 +1,76 @@
# -*- 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Authentification - Generate Password',
'version': '1.0',
'category': 'Tools',
'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;
Roadmap
-------
* When porting this module, please remove the feature that forbid users to
change them password, as another module 'password_change_restrict' exists in
V8 serie : https://github.com/OCA/server-tools/pull/249
Copyright, Author and Licence :
-------------------------------
* Copyright : 2014, Groupement Regional Alimentaire de Proximite;
* 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.xml',
'data/email_template.xml',
'view/view.xml',
],
'demo': [
'demo/res_groups.yml',
'demo/res_users.yml',
],
}

45
auth_generate_password/data/email_template.xml

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ********************************************************************** -->
<!--Authentification - Generate Password Module for OpenERP -->
<!--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 <http://www.gnu.org/licenses/>. -->
<!-- ********************************************************************** -->
<openerp>
<data>
<!-- Model: email.template -->
<record model="email.template" id="generate_password_template" >
<field name="name">Generate Password</field>
<field name="model_id" ref="base.model_res_users"/>
<field name="email_from"><![CDATA[${object.company_id.name} <${(object.company_id.email or user.email)|safe}>]]></field>
<field name="email_to">${object.email|safe}</field>
<field name="subject">OpenERP - Password Changed</field>
<field name="body_html"><![CDATA[
Your OpenERP credentials has been changed:
<ul>
<li>Login : ${object.login}</li>
<li>New Password : ${ctx.get('generated_password')}</li>
</ul>
Please,
<ul>
<li>remember this password and delete this email;</li>
<li>Communicate the password to your team, if there are many people that are using the same credentials;</li>
</ul>]]>
</field>
</record>
</data>
</openerp>

32
auth_generate_password/data/ir_config_parameter.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ********************************************************************** -->
<!--Authentification - Generate Password Module for OpenERP -->
<!--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 <http://www.gnu.org/licenses/>. -->
<!-- ********************************************************************** -->
<openerp>
<data noupdate="1">
<record model="ir.config_parameter" id="password_size">
<field name="key">auth_generate_password.password_size</field>
<field name="value">12</field>
</record>
<record model="ir.config_parameter" id="password_chars">
<field name="key">auth_generate_password.password_chars</field>
<field name="value">string.ascii_letters + string.digits</field>
</record>
</data>
</openerp>

25
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
- !record {model: res.groups, id: base.group_no_one}:
users:
- base.user_root

26
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
- !record {model: res.users, id: extra_user}:
name: Extra User
login: extra
email: extra@example.com

72
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"
"<ul>\n"
"<li>Login : ${object.login}</li>\n"
"<li>New Password : ${object.password}</li>\n"
"</ul>\n"
"Please,\n"
"<ul>\n"
"<li>remember this password and delete this email;</li>\n"
"<li>Communicate the password to your team, if there are many people that are using the same credentials;</li>\n"
"</ul>\n"
" "
msgstr "\n"
"Vos identifiants OpenERP ont changés :\n"
"<ul>\n"
"<li>Login : ${object.login}</li>\n"
"<li>Nouveau Mot de passe : ${object.password}</li>\n"
"</ul>\n"
"Merci de,\n"
"<ul>\n"
"<li>vous souvenir de ce mot de passe et de supprimer cet email ;</li>\n"
"<li>de communiquer ce mot de passe à votre équipe, si plusieurs personnes utilisent les même identifiants;</li>\n"
"</ul>\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"

23
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import res_users

69
auth_generate_password/model/res_users.py

@ -0,0 +1,69 @@
# -*- 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# 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, except_orm
from openerp.tools.translate import _
class res_users(Model):
_inherit = 'res.users'
def generate_password(self, cr, uid, ids, context=None):
if not context:
context = {}
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']
try:
int(icp_obj.get_param(
cr, uid, 'auth_generate_password.password_size'))
except:
raise except_orm(_("error"), _("Only digit chars authorized"))
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'))
et = imd_obj.get_object(
cr, uid, 'auth_generate_password', 'generate_password_template')
for ru in self.browse(cr, uid, ids, context=context):
if not ru.email:
raise except_orm(
_("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
context['generated_password'] = password
mail_id = et_obj.send_mail(
cr, uid, et.id, ru.id, True, context=context)
del context['generated_password']
return {}

BIN
auth_generate_password/static/src/img/icon.png

After

Width: 128  |  Height: 128  |  Size: 5.0 KiB

27
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import tests
fast_suite = [
tests,
]

58
auth_generate_password/tests/tests.py

@ -0,0 +1,58 @@
# -*- 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
# import threading
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, []))
# threading.currentThread().testing = True
self.ims_obj = self.registry('ir.mail_server')
ims_ids = self.ims_obj.search(cr, uid, [])
self.ims_obj.unlink(cr, uid, ims_ids)
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)))

46
auth_generate_password/view/view.xml

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ********************************************************************** -->
<!--Authentification - Generate Password Module for OpenERP -->
<!--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 <http://www.gnu.org/licenses/>. -->
<!-- ********************************************************************** -->
<openerp>
<data>
<!-- Model: res.users -->
<record id="view_res_users_form" model="ir.ui.view">
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
<field name="arch" type="xml">
<button name="preference_change_password" position="attributes">
<attribute name="groups">base.group_system</attribute>
</button>
</field>
</record>
<record id="view_res_users_tree" model="ir.ui.view">
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_tree" />
<field name="arch" type="xml">
<field name="login_date" position="after">
<button name="generate_password"
icon="terp-mail-message-new" type="object" string="Generate Password and Send Mail"/>
</field>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save