From ce6b6e64588f8ba22bd7eb29651d862f43850b17 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Tue, 20 Feb 2018 12:40:58 +0000 Subject: [PATCH] [FIX] event: do not suggest public user email in registration chatter Chatter suggests to include recipients on several objects, notably on registrations. When a registration is done through a public interface like website in website_event associated partner is the public user. In that case proposing to mail the public user does not make sense. It should propose the real email stored on the registration record. To fix that we filter the partner if it is linked to the pubic groups. The fix includes a sudo + context switch in a loop. As this method is called only on a recordset of one element this has no impact on real use case. Purpose is to keep the diff minimal. Closes #23187 . --- addons/event/models/event.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/event/models/event.py b/addons/event/models/event.py index 81e9e2ff398..c1cb4df14a0 100644 --- a/addons/event/models/event.py +++ b/addons/event/models/event.py @@ -390,9 +390,14 @@ class EventRegistration(models.Model): @api.multi def message_get_suggested_recipients(self): recipients = super(EventRegistration, self).message_get_suggested_recipients() + public_users = self.env['res.users'].sudo() + public_groups = self.env.ref("base.group_public", raise_if_not_found=False) + if public_groups: + public_users = public_groups.sudo().with_context(active_test=False).mapped("users") try: for attendee in self: - if attendee.partner_id: + is_public = attendee.sudo().with_context(active_test=False).partner_id.user_ids in public_users if public_users else False + if attendee.partner_id and not is_public: attendee._message_add_suggested_recipient(recipients, partner=attendee.partner_id, reason=_('Customer')) elif attendee.email: attendee._message_add_suggested_recipient(recipients, email=attendee.email, reason=_('Customer Email'))