summaryrefslogtreecommitdiff
path: root/addons/mail/controllers
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2019-07-09 10:43:28 +0000
committerDavid Beguin <dbe@odoo.com>2019-07-16 15:23:36 +0000
commita0fc2210e60a47ac17690c53323995f9753c5ff8 (patch)
tree42994a59741f04d1f0af421a333acc06e46513b8 /addons/mail/controllers
parentee50b4a20c08cee4651597b7ad93d6e3bc26ccb7 (diff)
[FIX] mail : enable to start livechat conversation
The public user doesn't have an email address. To start a livechat conversation, the email of the user that start the conversation is used. As the conversation was started in sudo, the system user's email address was used. But, since changes with sudo() and with_users(), the public user is not able to start a livechat conversation as the system email is not used anymore in this case as sudo is not changing the user but only skip the user's access right. To start a livechat conversation, and to post a message, at least email_from must be filled in. Anonymous name is used to fill in email_from to bypass the checks and to build the author given back the thread window. If anonymous name is empty, we fallback on the company's catchall email from the mail.channel create user. Pre-required for task ID: 2028059 Fix Task : 2037048 PR #34918 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/mail/controllers')
-rw-r--r--addons/mail/controllers/bus.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/addons/mail/controllers/bus.py b/addons/mail/controllers/bus.py
index 6ad8cc88870..cecf83eb1b7 100644
--- a/addons/mail/controllers/bus.py
+++ b/addons/mail/controllers/bus.py
@@ -36,14 +36,24 @@ class MailChatController(BusController):
# --------------------------
@route('/mail/chat_post', type="json", auth="public", cors="*")
def mail_chat_post(self, uuid, message_content, **kwargs):
- # find the author from the user session, which can be None
- author_id = False # message_post accept 'False' author_id, but not 'None'
+ mail_channel = request.env["mail.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
+ if not mail_channel:
+ return False
+
+ # find the author from the user session
if request.session.uid:
- author_id = request.env['res.users'].sudo().browse(request.session.uid).partner_id.id
+ author = request.env['res.users'].sudo().browse(request.session.uid).partner_id
+ author_id = author.id
+ email_from = author.email_formatted
+ else: # If Public User, use catchall email from company
+ author_id = False
+ email_from = mail_channel.anonymous_name or mail_channel.create_uid.company_id.catchall
# 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().search([('uuid', '=', uuid)], limit=1)
body = tools.plaintext2html(message_content)
- message = mail_channel.sudo().with_context(mail_create_nosubscribe=True).message_post(author_id=author_id, email_from=False, body=body, message_type='comment', subtype='mail.mt_comment')
+ message = mail_channel.with_context(mail_create_nosubscribe=True).message_post(author_id=author_id,
+ email_from=email_from, body=body,
+ message_type='comment',
+ subtype='mail.mt_comment')
return message and message.id or False
@route(['/mail/chat_history'], type="json", auth="public", cors="*")