Skip to content

Commit

Permalink
[IMP] website_mail: allow per-module override of token_field
Browse files Browse the repository at this point in the history
Instead of forcing a token field through an override, set it at the class level
to be changed in other model inheriting from the MailThread
  • Loading branch information
tde-banana-odoo committed Jul 8, 2018
1 parent 19ac9fb commit e00370e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addons/website_mail/controllers/main.py
Expand Up @@ -49,14 +49,15 @@ def _message_post_helper(res_model='', res_id=None, message='', token='', token_
""" """
record = request.env[res_model].browse(res_id) record = request.env[res_model].browse(res_id)
author_id = request.env.user.partner_id.id if request.env.user.partner_id else False author_id = request.env.user.partner_id.id if request.env.user.partner_id else False
if token and record and token == getattr(record.sudo(), token_field, None): if token and record and token == getattr(record.sudo(), record._mail_post_token_field, None):
record = record.sudo() record = record.sudo()
if request.env.user == request.env.ref('base.public_user'): if request.env.user == request.env.ref('base.public_user'):
author_id = record.partner_id.id if hasattr(record, 'partner_id') else author_id author_id = record.partner_id.id if hasattr(record, 'partner_id') else author_id
else: else:
if not author_id: if not author_id:
raise NotFound() raise NotFound()
kw.pop('csrf_token', None) kw.pop('csrf_token', None)
kw.pop('attachment_ids', None)
return record.with_context(mail_create_nosubscribe=nosubscribe).message_post(body=message, return record.with_context(mail_create_nosubscribe=nosubscribe).message_post(body=message,
message_type=kw.pop('message_type', "comment"), message_type=kw.pop('message_type', "comment"),
subtype=kw.pop('subtype', "mt_comment"), subtype=kw.pop('subtype', "mt_comment"),
Expand Down
6 changes: 6 additions & 0 deletions addons/website_mail/models/mail_message.py
Expand Up @@ -56,3 +56,9 @@ def check_access_rule(self, operation):
if self.env.cr.fetchall(): if self.env.cr.fetchall():
raise AccessError(_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation)) raise AccessError(_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation))
return super(MailMessage, self).check_access_rule(operation=operation) return super(MailMessage, self).check_access_rule(operation=operation)


class MailThread(models.AbstractModel):
_inherit = 'mail.thread'

_mail_post_token_field = 'access_token' # token field for external posts, to be overridden

0 comments on commit e00370e

Please sign in to comment.