summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authordip-odoo <dip@odoo.com>2018-02-08 17:38:03 +0530
committerRomainLibert <rli@odoo.com>2018-05-04 18:07:31 +0200
commit362613a2fa5dd99ae9b0521b6695badb512f5600 (patch)
tree4bef20f9b354d4deded79b75af3580a168faf065 /addons
parent2f15a5fa647d55df36c9019df467802a3aa9b4e3 (diff)
[IMP] auth_signup: change email invitation condition
Currently if a user has already been invited you cannot invite him again via the web_settings_dashboard as it automatically tries to create a new user. This commit changes that behaviour in case you have the mail app installed odoo will now send an invitation email to the invited user as long as this user has never connected. 1) Mail app not installed: - if user is active > display error (this email is already in use) - if user not active > activate the user - if user doesn't exist > create new user 2) Mail app installed: - if user is active && state confirmed > display popup (this email is already in use) - if user is active && never connected > resend invitation mail - if user is inactive > activate the user - if user doesn't exist > create new user and send invitation mail This commit is related to task #54023 Closes #23081
Diffstat (limited to 'addons')
-rw-r--r--addons/auth_signup/controllers/main.py8
-rw-r--r--addons/auth_signup/models/res_users.py37
-rw-r--r--addons/web_settings_dashboard/static/src/js/dashboard.js18
3 files changed, 54 insertions, 9 deletions
diff --git a/addons/auth_signup/controllers/main.py b/addons/auth_signup/controllers/main.py
index b8bdb9787b3..189c3cc8337 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.addons.web_settings_dashboard.controllers.main import WebSettingsDashboard as Dashboard
from odoo.exceptions import UserError
from odoo.http import request
@@ -133,3 +134,10 @@ class AuthSignupHome(Home):
uid = request.session.authenticate(db, login, password)
if not uid:
raise SignupError(_('Authentication Failed.'))
+
+class WebSettingsDashboard(Dashboard):
+ @http.route('/web_settings_dashboard/data', type='json', auth='user')
+ def web_settings_dashboard_data(self, **kw):
+ res = super(WebSettingsDashboard, self).web_settings_dashboard_data(**kw)
+ res['users_info'].update({'resend_invitation': True})
+ return res
diff --git a/addons/auth_signup/models/res_users.py b/addons/auth_signup/models/res_users.py
index a2280ac14ce..7bf33663b5e 100644
--- a/addons/auth_signup/models/res_users.py
+++ b/addons/auth_signup/models/res_users.py
@@ -7,6 +7,7 @@ from ast import literal_eval
from odoo import api, fields, models, _
from odoo.exceptions import UserError
+from odoo.osv import expression
from odoo.tools.misc import ustr
from odoo.addons.base.models.ir_mail_server import MailDeliveryException
@@ -17,9 +18,34 @@ _logger = logging.getLogger(__name__)
class ResUsers(models.Model):
_inherit = 'res.users'
- state = fields.Selection(compute='_compute_state', string='Status',
+ state = fields.Selection(compute='_compute_state', search='_search_state', string='Status',
selection=[('new', 'Never Connected'), ('active', 'Confirmed')])
+ def _search_state(self, operator, value):
+ negative = operator in expression.NEGATIVE_TERM_OPERATORS
+
+ # In case we have no value
+ if not value:
+ return TRUE_DOMAIN if negative else FALSE_DOMAIN
+
+ if operator in ['in', 'not in']:
+ if len(value) > 1:
+ return FALSE_DOMAIN if negative else TRUE_DOMAIN
+ if value[0] == 'new':
+ comp = '!=' if negative else '='
+ if value[0] == 'active':
+ comp = '=' if negative else '!='
+ return [('log_ids', comp, False)]
+
+ if operator in ['=', '!=']:
+ # In case we search against anything else than new, we have to invert the operator
+ if value != 'new':
+ operator = expression.TERM_OPERATORS_NEGATION[operator]
+
+ return [('log_ids', operator, False)]
+
+ return expression.TRUE_DOMAIN
+
@api.multi
def _compute_state(self):
for user in self:
@@ -144,6 +170,15 @@ class ResUsers(models.Model):
_logger.info("Password reset email sent for user <%s> to <%s>", user.login, user.email)
@api.model
+ def web_dashboard_create_users(self, emails):
+ inactive_users = self.search([('state', '=', 'new'), '|', ('login', 'in', emails), ('email', 'in', emails)])
+ new_emails = set(emails) - set(inactive_users.mapped('email'))
+ res = super(ResUsers, self).web_dashboard_create_users(list(new_emails))
+ if inactive_users:
+ inactive_users.with_context(create_user=True).action_reset_password()
+ return res
+
+ @api.model
def create(self, values):
# overridden to automatically invite user to sign up
user = super(ResUsers, self).create(values)
diff --git a/addons/web_settings_dashboard/static/src/js/dashboard.js b/addons/web_settings_dashboard/static/src/js/dashboard.js
index d5705c80e42..49768cee06b 100644
--- a/addons/web_settings_dashboard/static/src/js/dashboard.js
+++ b/addons/web_settings_dashboard/static/src/js/dashboard.js
@@ -104,15 +104,17 @@ var DashboardInvitations = Widget.extend({
}
emails = _.difference(emails, invalidEmails);
- // filter out already processed or pending addresses
- var pendingEmails = _.map(this.data.pending_users, function (info) {
- return info[1];
- });
- var existingEmails = _.intersection(emails, this.emails.concat(pendingEmails));
- if (existingEmails.length) {
- this.do_warn(_.str.sprintf(_t('The following email addresses already exist: %s.'), existingEmails.join(', ')));
+ if (!this.data.resend_invitation) {
+ // filter out already processed or pending addresses
+ var pendingEmails = _.map(this.data.pending_users, function (info) {
+ return info[1];
+ });
+ var existingEmails = _.intersection(emails, this.emails.concat(pendingEmails));
+ if (existingEmails.length) {
+ this.do_warn(_.str.sprintf(_t('The following email addresses already exist: %s.'), existingEmails.join(', ')));
+ }
+ emails = _.difference(emails, existingEmails);
}
- emails = _.difference(emails, existingEmails);
// add valid email addresses, if any
if (emails.length) {