From d437d3af728bfc48d0162aff503542dc63007fa0 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Sun, 23 Mar 2014 21:45:12 +0100 Subject: [PATCH] [IMP] Emails are now translated. --- auth_admin_passkey/__openerp__.py | 5 +- .../i18n/auth_admin_passkey.pot | 35 +++++++++-- auth_admin_passkey/i18n/fr.po | 58 +++++++++++++++++-- auth_admin_passkey/model/res_users.py | 45 ++++++++------ 4 files changed, 111 insertions(+), 32 deletions(-) diff --git a/auth_admin_passkey/__openerp__.py b/auth_admin_passkey/__openerp__.py index 3b62dca74..10de4cdb6 100644 --- a/auth_admin_passkey/__openerp__.py +++ b/auth_admin_passkey/__openerp__.py @@ -15,15 +15,12 @@ Functionnalities : ------------------ * Administrator has now the possibility to login in with any login; * By default, OpenERP will send a mail to user and admin to indicate them; + * If a user has the same password as the admin, OpenERP will inform the admin; Technical informations : ------------------------ * Create two ir_config_parameter to enable / disable mail sending; -Limits : --------- - * For the moment, this module doesn't manage translations for the mails; - Copyright and Licence : ----------------------- * 2014, Groupement Régional Alimentaire de Proximité diff --git a/auth_admin_passkey/i18n/auth_admin_passkey.pot b/auth_admin_passkey/i18n/auth_admin_passkey.pot index 1e20c237b..358c3a006 100644 --- a/auth_admin_passkey/i18n/auth_admin_passkey.pot +++ b/auth_admin_passkey/i18n/auth_admin_passkey.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-03-23 17:43+0000\n" -"PO-Revision-Date: 2014-03-23 17:43+0000\n" +"POT-Creation-Date: 2014-03-23 20:41+0000\n" +"PO-Revision-Date: 2014-03-23 20:41+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,11 +15,37 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: auth_admin_passkey +#: code:addons/auth_admin_passkey/model/res_users.py:66 +#, python-format +msgid "
User with login '%s' has the same password as you.
" +msgstr "" + +#. module: auth_admin_passkey +#: code:addons/auth_admin_passkey/model/res_users.py:44 +#, python-format +msgid "Admin user used his passkey to login with '%s'.\n" +"\n" +"\n" +"\n" +"Technicals informations belows : \n" +"\n" +"- Login date : %s\n" +"\n" +"" +msgstr "" + #. module: auth_admin_passkey #: view:base.config.settings:0 msgid "Passkey" msgstr "" +#. module: auth_admin_passkey +#: code:addons/auth_admin_passkey/model/res_users.py:42 +#, python-format +msgid "Passkey used" +msgstr "" + #. module: auth_admin_passkey #: field:base.config.settings,auth_admin_passkey_send_to_admin:0 msgid "Send email to admin user." @@ -48,9 +74,8 @@ msgid "When the administrator use his password to login in with a different acco msgstr "" #. module: auth_admin_passkey -#: code:_description:0 -#: model:ir.model,name:auth_admin_passkey.model_base_config_settings +#: code:addons/auth_admin_passkey/model/res_users.py:64 #, python-format -msgid "base.config.settings" +msgid "[WARNING] OpenERP Security Risk" msgstr "" diff --git a/auth_admin_passkey/i18n/fr.po b/auth_admin_passkey/i18n/fr.po index c352d40a5..2aa851e02 100644 --- a/auth_admin_passkey/i18n/fr.po +++ b/auth_admin_passkey/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: OpenERP Server 7.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-03-17 12:04+0000\n" -"PO-Revision-Date: 2014-03-17 12:04+0000\n" +"POT-Creation-Date: 2014-03-23 20:38+0000\n" +"PO-Revision-Date: 2014-03-23 20:38+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -15,16 +15,62 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: auth_admin_passkey +#: code:addons/auth_admin_passkey/model/res_users.py:66 +#, python-format +msgid "
User with login '%s' has the same password as you.
" +msgstr "
L'utilisateur dont l'identifiant est '%s' a le même mot de passe que vous.
" + +#. module: auth_admin_passkey +#: code:addons/auth_admin_passkey/model/res_users.py:44 +#, python-format +msgid "Admin user used his passkey to login with '%s'.\n" +"\n" +"\n" +"\n" +"Technicals informations belows : \n" +"\n" +"- Login date : %s\n" +"\n" +"" +msgstr "L'administrateur a utilisé son mot de passe bris de glace pour s'identifier avec l'identifiant '%s'.\n" +"\n" +"\n" +"\n" +"Informations techniques ci-dessous : \n" +"\n" +"- Date d'authentification : %s\n" +"\n" +"" + #. module: auth_admin_passkey #: view:base.config.settings:0 msgid "Passkey" msgstr "Mot de passe bris de glace" +#. module: auth_admin_passkey +#: code:addons/auth_admin_passkey/model/res_users.py:42 +#, python-format +msgid "Passkey used" +msgstr "Mot de passe bris de glace utilisé" + #. module: auth_admin_passkey #: field:base.config.settings,auth_admin_passkey_send_to_admin:0 msgid "Send email to admin user." msgstr "Envoyer un email à l'administrateur." +#. module: auth_admin_passkey +#: field:base.config.settings,auth_admin_passkey_send_to_user:0 +msgid "Send email to user." +msgstr "Envoyer un email à l'utilisateur." + +#. module: auth_admin_passkey +#: code:_description:0 +#: model:ir.model,name:auth_admin_passkey.model_res_users +#, python-format +msgid "Users" +msgstr "Utilisateurs" + #. module: auth_admin_passkey #: help:base.config.settings,auth_admin_passkey_send_to_user:0 msgid "When the administrator use his password to login in with a different account, OpenERP will send an email to the account user." @@ -36,7 +82,7 @@ msgid "When the administrator use his password to login in with a different acco msgstr "Quand l'administrateur utilise son mot de passe pour s'authentifier avec un compte différent, OpenERP enverra un mail à l'utilisateur." #. module: auth_admin_passkey -#: field:base.config.settings,auth_admin_passkey_send_to_user:0 -msgid "Send email to user." -msgstr "Envoyer un email à l'utilisateur." - +#: code:addons/auth_admin_passkey/model/res_users.py:64 +#, python-format +msgid "[WARNING] OpenERP Security Risk" +msgstr "[WARNING] Faille de sécurité sur OpenERP" diff --git a/auth_admin_passkey/model/res_users.py b/auth_admin_passkey/model/res_users.py index eab27e9cd..5bfe8ac93 100644 --- a/auth_admin_passkey/model/res_users.py +++ b/auth_admin_passkey/model/res_users.py @@ -10,14 +10,20 @@ from openerp import SUPERUSER_ID from openerp import pooler from openerp import exceptions from openerp.osv.orm import Model +from openerp.tools.translate import _ class res_users(Model): _inherit = "res.users" ### Private Function section + def _get_translation(self, cr, lang, text): + context = {'lang': lang} + return _(text) + def _send_email_passkey(self, cr, user_id, user_agent_env): """ Send a email to the admin of the system and / or the user to inform passkey use """ + mails = [] mail_obj = self.pool.get('mail.mail') icp_obj = self.pool.get('ir.config_parameter') admin_user = self.browse(cr, SUPERUSER_ID, SUPERUSER_ID) @@ -26,21 +32,24 @@ class res_users(Model): 'auth_admin_passkey.send_to_admin', 'True')) send_to_user = literal_eval(icp_obj.get_param(cr, SUPERUSER_ID, 'auth_admin_passkey.send_to_user', 'True')) - emails_to = [] - if send_to_admin and admin_user.email: - emails_to.append(admin_user.email) + + if send_to_admin and admin_user.email: + mails.append({'email': admin_user.email, 'lang': admin_user.lang,}) if send_to_user and login_user.email: - emails_to.append(login_user.email) - if emails_to: - body = "Admin user used his passkey to login with '%s'.\n\n" %(login_user.login) - body += "\n\nTechnicals informations belows : \n\n" - body += "- Login date : %s\n\n" %(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) - for key, value in user_agent_env.iteritems(): - body +=("- %s : %s\n\n") % (key, value) - for email_to in emails_to: - mail_obj.create(cr, SUPERUSER_ID, { - 'email_to': email_to, - 'subject': "Passkey used", + mails.append({'email': login_user.email, 'lang': login_user.lang,}) + + for mail in mails: + subject = self._get_translation(cr, mail['lang'], _('Passkey used')) + body = self._get_translation(cr, mail['lang'], + _("""Admin user used his passkey to login with '%s'.\n\n"""\ + """\n\nTechnicals informations belows : \n\n"""\ + """- Login date : %s\n\n""")) %(login_user.login, + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + for k, v in user_agent_env.iteritems(): + body +=("- %s : %s\n\n") % (k, v) + mail_obj.create(cr, SUPERUSER_ID, { + 'email_to': mail['email'], + 'subject': subject, 'body_html': '
%s
' % body}) def _send_email_same_password(self, cr, login_user): @@ -51,9 +60,11 @@ class res_users(Model): if admin_user.email: mail_obj.create(cr, SUPERUSER_ID, { 'email_to': admin_user.email, - 'subject': "[WARNING] OpenERP Security Risk", - 'body_html': """
User with login '%s' has the same """\
-                    """password as you.
""" %(login_user) + 'subject': self._get_translation(cr, admin_user.lang, + _('[WARNING] OpenERP Security Risk')), + 'body_html': self._get_translation(cr, admin_user.lang, + _("""
User with login '%s' has the same """\
+                        """password as you.
""")) %(login_user), }) ### Overload Section