summaryrefslogtreecommitdiff
path: root/addons/mail/models/mail_alias.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2017-03-20 16:11:47 +0100
committerThibault Delavallée <tde@odoo.com>2017-03-23 13:11:34 +0100
commit78ac6de52d690d278fd0cde5476bbeaec86cb124 (patch)
tree25ff65ce09aa9c2b1623c9715f6f3b4e18330054 /addons/mail/models/mail_alias.py
parent634821c68868678127f4aff9a85b1aa525cc1d1f (diff)
[IMP] mail: factorize code that handles alias security in mail gateway
Currently check of alias security is directly embedded in mail.thread routing method. In this commit we move this check in the mail.alias.mixin class itself. Doing this allows models to extend or improve the behavior depending on how inheriting models use aliases.
Diffstat (limited to 'addons/mail/models/mail_alias.py')
-rw-r--r--addons/mail/models/mail_alias.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/addons/mail/models/mail_alias.py b/addons/mail/models/mail_alias.py
index 67233efcd77..df0d84062e7 100644
--- a/addons/mail/models/mail_alias.py
+++ b/addons/mail/models/mail_alias.py
@@ -262,3 +262,21 @@ class AliasMixin(models.AbstractModel):
record.with_context({'mail_notrack': True}).alias_id = alias
_logger.info('Mail alias created for %s %s (id %s)',
record._name, record.display_name, record.id)
+
+ def _alias_check_contact(self, message, message_dict, alias):
+ author = self.env['res.partner'].browse(message_dict.get('author_id', False))
+ if alias.alias_contact == 'followers' and self.ids:
+ if not hasattr(self, "message_partner_ids") or not hasattr(self, "message_channel_ids"):
+ return {
+ 'error_mesage': _('incorrectly configured alias'),
+ }
+ accepted_partner_ids = self.message_partner_ids | self.message_channel_ids.mapped('channel_partner_ids')
+ if not author or author not in accepted_partner_ids:
+ return {
+ 'error_mesage': _('restricted to followers'),
+ }
+ elif alias.alias_contact == 'partners' and not author:
+ return {
+ 'error_message': _('restricted to known authors')
+ }
+ return True