From 66bd7707f5ba679ff3b878adafd72475250965a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 10 Mar 2017 11:54:37 +0100 Subject: [PATCH] [IMP] mail: protect by default alias of private or group based channels Otherwise by default their alias are public. This makes no sense for private groups to have by default public aliases. Field is set as invisible on the view because it makes sense to configure only the channel and not details of its alias. Anyway it is always possible to tweak the alias configuration under Technical menu. --- addons/mail/models/mail_channel.py | 14 ++++++++++++++ addons/mail/views/mail_channel_views.xml | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py index 29f0e927978..6012dc9c22b 100644 --- a/addons/mail/models/mail_channel.py +++ b/addons/mail/models/mail_channel.py @@ -43,6 +43,13 @@ class Channel(models.Model): image_path = modules.get_module_resource('mail', 'static/src/img', 'groupdefault.png') return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64')) + @api.model + def default_get(self, fields): + res = super(Channel, self).default_get(fields) + if not res.get('alias_contact') and (not fields or 'alias_contact' in fields): + res['alias_contact'] = 'everyone' if res.get('public', 'private') == 'public' else 'followers' + return res + name = fields.Char('Name', required=True, translate=True) channel_type = fields.Selection([ ('chat', 'Chat Discussion'), @@ -99,6 +106,13 @@ class Channel(models.Model): for record in self: record.is_member = record in membership_ids + @api.onchange('public') + def _onchange_public(self): + if self.public == 'public': + self.alias_contact = 'everyone' + else: + self.alias_contact = 'followers' + @api.model def create(self, vals): tools.image_resize_images(vals) diff --git a/addons/mail/views/mail_channel_views.xml b/addons/mail/views/mail_channel_views.xml index 0c1ed4a8ce9..58c6d724a4f 100644 --- a/addons/mail/views/mail_channel_views.xml +++ b/addons/mail/views/mail_channel_views.xml @@ -106,8 +106,7 @@ @ -