Skip to content

Commit

Permalink
[FIX] mail: visitor to portal_user should keep livechat channel
Browse files Browse the repository at this point in the history
adapting #20279 to v10

Before this commit, when starting a livechat session as a public user and continuing as a portal user, the livechat crashed
(the poral user couldn't see the channel created before as Admin)

After this commit, the conversation is kept and security insured by the uuid in the cookie

OPW 775568
  • Loading branch information
kebeclibre committed Oct 18, 2017
1 parent c7f5ad8 commit 5de2234
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions addons/mail/controllers/bus.py
Expand Up @@ -36,18 +36,16 @@ def _poll(self, dbname, channels, last, options):
# -------------------------- # --------------------------
@route('/mail/chat_post', type="json", auth="none") @route('/mail/chat_post', type="json", auth="none")
def mail_chat_post(self, uuid, message_content, **kwargs): def mail_chat_post(self, uuid, message_content, **kwargs):
request_uid = self._default_request_uid()
# find the author from the user session, which can be None # find the author from the user session, which can be None
author_id = False # message_post accept 'False' author_id, but not 'None' author_id = False # message_post accept 'False' author_id, but not 'None'
if request.session.uid: if request.session.uid:
author_id = request.env['res.users'].sudo().browse(request.session.uid).partner_id.id author_id = request.env['res.users'].sudo().browse(request.session.uid).partner_id.id
# post a message without adding followers to the channel. email_from=False avoid to get author from email data # post a message without adding followers to the channel. email_from=False avoid to get author from email data
mail_channel = request.env["mail.channel"].sudo(request_uid).search([('uuid', '=', uuid)], limit=1) mail_channel = request.env["mail.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
message = mail_channel.sudo(request_uid).with_context(mail_create_nosubscribe=True).message_post(author_id=author_id, email_from=False, body=message_content, message_type='comment', subtype='mail.mt_comment', content_subtype='plaintext', **kwargs) message = mail_channel.sudo().with_context(mail_create_nosubscribe=True).message_post(author_id=author_id, email_from=False, body=message_content, message_type='comment', subtype='mail.mt_comment', content_subtype='plaintext')
return message and message.id or False return message and message.id or False


@route(['/mail/chat_history'], type="json", auth="none") @route(['/mail/chat_history'], type="json", auth="none")
def mail_chat_history(self, uuid, last_id=False, limit=20): def mail_chat_history(self, uuid, last_id=False, limit=20):
request_uid = self._default_request_uid() channel = request.env["mail.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
channel = request.env["mail.channel"].sudo(request_uid).search([('uuid', '=', uuid)], limit=1) return channel.sudo().channel_fetch_message(last_id, limit)
return channel.sudo(request_uid).channel_fetch_message(last_id, limit)

0 comments on commit 5de2234

Please sign in to comment.