From 676022e3afdd774c3e0c78cb26c0062133043308 Mon Sep 17 00:00:00 2001 From: Denis Vermylen Date: Mon, 15 May 2017 15:14:49 +0200 Subject: [PATCH] [IMP] auth_signup: display meaningfull and translated error messages Since 5425316eff19e7ae716aafdb730c92d1b3ea2abb errors when signing up will only display two messages: * "Another user is already registered using this email address." or * "Could not create a new account." While Odoo creates a multitude of other comprehensible error messages such as * "Passwords do not match; please retype them." * "Signup token '%s' is no longer valid" This commit now separate UserError and AssertionError from SignupErrors. Those are still hidden in a general message (see 5425316eff19e7ae716aafdb730c92d1b3ea2abb for reasons) while the other ones are fully displayed. This commit also improves translations of messages. --- addons/auth_oauth/models/res_users.py | 4 ++-- addons/auth_signup/controllers/main.py | 11 ++++++++--- addons/auth_signup/models/res_partner.py | 6 +++--- addons/auth_signup/models/res_users.py | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/addons/auth_oauth/models/res_users.py b/addons/auth_oauth/models/res_users.py index dd2496bdea7..dd61505b485 100644 --- a/addons/auth_oauth/models/res_users.py +++ b/addons/auth_oauth/models/res_users.py @@ -6,7 +6,7 @@ import json import requests from odoo import api, fields, models -from odoo.exceptions import AccessDenied +from odoo.exceptions import AccessDenied, UserError from odoo.addons.auth_signup.models.res_users import SignupError from odoo.addons import base @@ -82,7 +82,7 @@ class ResUsers(models.Model): try: _, login, _ = self.signup(values, token) return login - except SignupError: + except (SignupError, UserError): raise access_denied_exception @api.model diff --git a/addons/auth_signup/controllers/main.py b/addons/auth_signup/controllers/main.py index 533f84a8d82..0b546011b27 100644 --- a/addons/auth_signup/controllers/main.py +++ b/addons/auth_signup/controllers/main.py @@ -6,6 +6,7 @@ import werkzeug from odoo import http, _ from odoo.addons.auth_signup.models.res_users import SignupError from odoo.addons.web.controllers.main import ensure_db, Home +from odoo.exceptions import UserError from odoo.http import request from odoo.tools import pycompat @@ -34,6 +35,8 @@ class AuthSignupHome(Home): try: self.do_signup(qcontext) return super(AuthSignupHome, self).web_login(*args, **kw) + except UserError as e: + qcontext['error'] = str(e) except (SignupError, AssertionError) as e: if request.env["res.users"].sudo().search([("login", "=", qcontext.get("login"))]): qcontext["error"] = _("Another user is already registered using this email address.") @@ -57,7 +60,7 @@ class AuthSignupHome(Home): return super(AuthSignupHome, self).web_login(*args, **kw) else: login = qcontext.get('login') - assert login, "No login provided." + assert login, _("No login provided.") _logger.info( "Password reset attempt for <%s> by user <%s> from %s", login, request.env.user.login, request.httprequest.remote_addr) @@ -100,8 +103,10 @@ class AuthSignupHome(Home): def do_signup(self, qcontext): """ Shared helper that creates a res.partner out of a token """ values = { key: qcontext.get(key) for key in ('login', 'name', 'password') } - assert values, "The form was not properly filled in." - assert values.get('password') == qcontext.get('confirm_password'), "Passwords do not match; please retype them." + if not values: + raise UserError(_("The form was not properly filled in.")) + if values.get('password') != qcontext.get('confirm_password'): + raise UserError(_("Passwords do not match; please retype them.")) supported_langs = [lang['code'] for lang in request.env['res.lang'].sudo().search_read([], ['code'])] if request.lang in supported_langs: values['lang'] = request.lang diff --git a/addons/auth_signup/models/res_partner.py b/addons/auth_signup/models/res_partner.py index d8111420a3c..f0da06f7cbd 100644 --- a/addons/auth_signup/models/res_partner.py +++ b/addons/auth_signup/models/res_partner.py @@ -6,7 +6,7 @@ import werkzeug.urls from datetime import datetime, timedelta -from odoo import api, fields, models, _ +from odoo import api, exceptions, fields, models, _ from odoo.tools import pycompat @@ -125,11 +125,11 @@ class ResPartner(models.Model): partner = self.search([('signup_token', '=', token)], limit=1) if not partner: if raise_exception: - raise SignupError("Signup token '%s' is not valid" % token) + raise exceptions.UserError(_("Signup token '%s' is not valid") % token) return False if check_validity and not partner.signup_valid: if raise_exception: - raise SignupError("Signup token '%s' is no longer valid" % token) + raise exceptions.UserError(_("Signup token '%s' is no longer valid") % token) return False return partner diff --git a/addons/auth_signup/models/res_users.py b/addons/auth_signup/models/res_users.py index 05d52596c85..b58606b73ab 100644 --- a/addons/auth_signup/models/res_users.py +++ b/addons/auth_signup/models/res_users.py @@ -85,7 +85,7 @@ class ResUsers(models.Model): # check that uninvited users may sign up if 'partner_id' not in values: if not literal_eval(get_param('auth_signup.allow_uninvited', 'False')): - raise SignupError('Signup is not allowed for uninvited users') + raise SignupError(_('Signup is not allowed for uninvited users')) assert values.get('login'), "Signup: no login given for new user" assert values.get('partner_id') or values.get('name'), "Signup: no name or partner given for new user"