Files
odoo_source/addons/mail/controllers/webclient.py
T
tsm-odoo cdc35aed74 [IMP] mail: add decorator to extract guest
This PR adds the `add_guest_to_context` decorator in order to provide a generic
way to extract the guest from a request. It will be used to unified guest
extraction from cookie/param based on its provenance (external livechat/public
page).

This is better than the `pre_dispatch` method since it can be applied to
specific routes instead of adding this logic to every request.

part of task-3332628

closes odoo/odoo#130052

Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
2023-08-09 13:20:53 +02:00

24 lines
962 B
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from werkzeug.exceptions import NotFound
from odoo import http
from odoo.http import request
from odoo.addons.mail.models.discuss.mail_guest import add_guest_to_context
class WebclientController(http.Controller):
@http.route("/mail/init_messaging", methods=["POST"], type="json", auth="public")
@add_guest_to_context
def mail_init_messaging(self):
if not request.env.user.sudo()._is_public():
return request.env.user.sudo(request.env.user.has_group("base.group_portal"))._init_messaging()
guest = request.env["mail.guest"]._get_guest_from_context()
if guest:
return guest.sudo()._init_messaging()
raise NotFound()
@http.route("/mail/load_message_failures", methods=["POST"], type="json", auth="user")
def mail_load_message_failures(self):
return request.env.user.partner_id._message_fetch_failed()