diff --git a/addons/auth_signup/models/res_users.py b/addons/auth_signup/models/res_users.py index 598d390dbd5..27fd43a0403 100644 --- a/addons/auth_signup/models/res_users.py +++ b/addons/auth_signup/models/res_users.py @@ -81,6 +81,8 @@ class ResUsers(models.Model): values.pop('login', None) values.pop('name', None) partner_user.write(values) + if not partner_user.login_date: + partner_user._notify_inviter() return (self.env.cr.dbname, partner_user.login, values.get('password')) else: # user does not exist: sign up invited user @@ -92,7 +94,8 @@ class ResUsers(models.Model): if partner.company_id: values['company_id'] = partner.company_id.id values['company_ids'] = [(6, 0, [partner.company_id.id])] - self._signup_create_user(values) + partner_user = self._signup_create_user(values) + partner_user._notify_inviter() else: # no token, sign up an external user values['email'] = values.get('email') or values.get('login') @@ -110,6 +113,20 @@ class ResUsers(models.Model): raise SignupError(_('Signup is not allowed for uninvited users')) return self._create_user_from_template(values) + @api.multi + def _notify_inviter(self): + for user in self: + invite_partner = user.create_uid.partner_id + if invite_partner: + # notify invite user that new user is connected + title = _("%s connected") % user.name + message = _("This is his first connection. Wish him welcome") + self.env['bus.bus'].sendone( + (self._cr.dbname, 'res.partner', invite_partner.id), + {'type': 'user_connection', 'title': title, + 'message': message, 'partner_id': user.partner_id.id} + ) + def _create_user_from_template(self, values): template_user_id = literal_eval(self.env['ir.config_parameter'].sudo().get_param('base.template_portal_user_id', 'False')) template_user = self.browse(template_user_id) diff --git a/addons/bus/static/src/js/services/bus_service.js b/addons/bus/static/src/js/services/bus_service.js index 8e367b7f93a..af505dfc6e4 100644 --- a/addons/bus/static/src/js/services/bus_service.js +++ b/addons/bus/static/src/js/services/bus_service.js @@ -27,11 +27,12 @@ var BusService = CrossTab.extend(ServicesMixin, { * * @param {string} title * @param {string} content + * @param {function} [callback] if given callback will be called when user clicks on notification */ - sendNotification: function (title, content) { + sendNotification: function (title, content, callback) { if (window.Notification && Notification.permission === "granted") { if (this.isMasterTab()) { - this._sendNativeNotification(title, content); + this._sendNativeNotification(title, content, callback); } } else { this.do_notify(title, content); @@ -76,8 +77,9 @@ var BusService = CrossTab.extend(ServicesMixin, { * @private * @param {string} title * @param {string} content + * @param {function} [callback] if given callback will be called when user clicks on notification */ - _sendNativeNotification: function (title, content) { + _sendNativeNotification: function (title, content, callback) { var notification = new Notification(title, {body: content, icon: "/mail/static/src/img/odoo_o.png"}); notification.onclick = function () { window.focus(); @@ -86,6 +88,9 @@ var BusService = CrossTab.extend(ServicesMixin, { } else if (this.close) { this.close(); } + if (callback) { + callback(); + } }; }, diff --git a/addons/mail/static/src/js/services/mail_notification_manager.js b/addons/mail/static/src/js/services/mail_notification_manager.js index b3e5239f9ee..475cbd44f90 100644 --- a/addons/mail/static/src/js/services/mail_notification_manager.js +++ b/addons/mail/static/src/js/services/mail_notification_manager.js @@ -165,13 +165,13 @@ MailManager.include({ * Add or remove failure when receiving a failure update message * * @private - * @param {Object} data - * @param {Object[]} data.elements list of mail failure data - * @param {string} data.elements[].message_id ID of related message that + * @param {Object} datas + * @param {Object[]} datas.elements list of mail failure data + * @param {string} datas.elements[].message_id ID of related message that * has a mail failure. - * @param {Array} data.elements[].notifications list of notifications + * @param {Array} datas.elements[].notifications list of notifications * that is related to a mail failure. - * @param {string} data.elements[].notifications[0] sending state of a mail + * @param {string} datas.elements[].notifications[0] sending state of a mail * failure (e.g. 'exception'). */ _handlePartnerMailFailureNotification: function (datas) { @@ -313,6 +313,8 @@ MailManager.include({ this._handlePartnerActivityUpdateNotification(data); } else if (data.type === 'mail_failure') { this._handlePartnerMailFailureNotification(data); + } else if (data.type === 'user_connection') { + this._handlePartnerUserConnectionNotification(data); } else { this._handlePartnerChannelNotification(data); } @@ -402,8 +404,25 @@ MailManager.include({ this._mailBus.trigger('unsubscribe_from_channel', data.id); this.do_notify(_("Unsubscribed"), message); } + }, + /** + * Shows a popup to notify a user connection + * + * @private + * @param {Object} data + * @param {Object[]} data.partner_id id of the connected partner + * @param {string} data.title title to display on notification + * @param {Array} data.messages message to display on notification + */ + _handlePartnerUserConnectionNotification: function (data) { + var self=this; + var partner_id = data.partner_id; + this.call('bus_service', 'sendNotification', data.title, data.message, function(){ + self.call('mail_service', 'openDmWindow', partner_id); + }); }, /** + * * On receiving an update on user status (e.g. becoming 'online', 'offline', * 'idle', etc.). *