Skip to content
Permalink
Browse files

[IMP] website_mail: allow per-module override of token_field

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 e5984fb commit 6033439c67d696f5accb7e17ac42de6f9c0bd0b3
Showing with 5 additions and 2 deletions.
  1. +3 −2 addons/website_mail/controllers/main.py
  2. +2 −0 addons/website_mail/models/mail_thread.py
@@ -36,7 +36,7 @@ def _message_post_helper(res_model='', res_id=None, message='', token='', token_
optional keywords arguments:
:param string token: access token if the object's model uses some kind of public access
using tokens (usually a uuid4) to bypass access rules
:param string token_field: name of the field that contains the token on the object (defaults to 'token')
:param string token_field: name of the field that contains the token on the object (deprecated, use _mail_post_token_field)
:param string sha_in: sha1 hash of the string composed of res_model, res_id and the dabase secret in ir.config_parameter
if you wish to allow public users to write on the object with some security but you don't want
to add a token field on the object, the sha-sign prevents public users from writing to any other
@@ -49,7 +49,7 @@ def _message_post_helper(res_model='', res_id=None, message='', token='', token_
"""
res = request.env[res_model].browse(res_id)
author_id = request.env.user.partner_id.id
if token and res and token == getattr(res.sudo(), token_field, None):
if token and res and token == getattr(res.sudo(), res._mail_post_token_field, None):
res = res.sudo()
if request.env.user == request.env['ir.model.data'].xmlid_to_object('base.public_user'):
author_id = (res.partner_id and res.partner_id.id) if hasattr(res, 'partner_id') else author_id
@@ -66,6 +66,7 @@ def _message_post_helper(res_model='', res_id=None, message='', token='', token_
else:
raise NotFound()
kw.pop('csrf_token', None)
kw.pop('attachment_ids', None)
return res.with_context({'mail_create_nosubscribe': nosubscribe}).message_post(body=message,
message_type=kw.pop('message_type', False) or "comment",
subtype=kw.pop('subtype', False) or "mt_comment",
@@ -7,6 +7,8 @@
class MailThread(osv.AbstractModel):
_inherit = 'mail.thread'

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

_columns = {
'website_message_ids': fields.one2many(
'mail.message', 'res_id',

0 comments on commit 6033439

Please sign in to comment.
You can’t perform that action at this time.