[FIX] im_livechat, mail: visitor to portal_user should keep livechat channel

Before this commit, when starting a livechat session as a public user and continuing as a portal user, the conversation was lost
(the poral user couldn't see previous messages posted as a public user)

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

OPW 775568

closes #20279
This commit is contained in:
Lucas Perais (lpe)
2017-11-09 10:42:36 +01:00
parent 35aa2a977f
commit bb38c7047e
2 changed files with 4 additions and 4 deletions
+2 -1
View File
@@ -70,9 +70,10 @@ class LivechatController(http.Controller):
anonymous_name = request.env.user.name
return request.env["im_livechat.channel"].get_mail_channel(channel_id, anonymous_name)
# Do not forward port in 10.0
@http.route('/im_livechat/history', type="json", auth="public")
def history(self, channel_id, limit):
return request.env["mail.channel"].browse(channel_id).channel_fetch_message(limit=limit)
return request.env["mail.channel"].browse(channel_id).sudo().channel_fetch_message(limit=limit)
@http.route('/im_livechat/feedback', type='json', auth='public')
def feedback(self, uuid, rate, reason=None, **kwargs):
+2 -3
View File
@@ -36,14 +36,13 @@ class MailChatController(openerp.addons.bus.controllers.main.BusController):
# --------------------------
@openerp.http.route('/mail/chat_post', type="json", auth="none")
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
author_id = False # message_post accept 'False' author_id, but not 'None'
if request.session.uid:
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
mail_channel = request.env["mail.channel"].sudo(request_uid).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)
mail_channel = request.env["mail.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
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
@openerp.http.route(['/mail/chat_history'], type="json", auth="none")