Browse Source

[ADD] 'auth_generate_password' module to generate randomly user's password

pull/92/head
Sylvain LE GAL 10 years ago
parent
commit
580cbe6e1a
  1. 23
      auth_generate_password/__init__.py
  2. 70
      auth_generate_password/__openerp__.py
  3. 45
      auth_generate_password/data/email_template.xml
  4. 29
      auth_generate_password/data/ir_config_parameter.yml
  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. 61
      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. 53
      auth_generate_password/tests/tests.py
  13. 48
      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

70
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'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',
],
}

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 : ${object.password}</li>
</ul>
Please,
<ul>
<li>remember this password and delete this email;</li>
<li>Communicate the password to your team, if you are many people to use the same credentials;</li>
</ul>]]>
</field>
</record>
</data>
</openerp>

29
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
- !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

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 you are many people to use 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

61
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 <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
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 {}

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

After

Width: 128  |  Height: 128  |  Size: 6.7 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,
]

53
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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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)))

48
auth_generate_password/view/view.xml

@ -0,0 +1,48 @@
<?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