This PR prepares the ground for the one introducing guests for livechat visitors. Since our SameSite cookie policy is Lax, the cookie won't be send on unsafe cross site requests thus another mechanism will be introduced to retrieve the guest. This PR abstracts the way the guest is retrieved in order to ease this transition as much as possible by overriding the `ir_http._pre_dispatch` method in order to inject the guest in the context if any. part of task-3332628 closes odoo/odoo#129039 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
19 lines
733 B
Python
19 lines
733 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
|
|
|
|
|
|
class GuestController(http.Controller):
|
|
@http.route("/mail/guest/update_name", methods=["POST"], type="json", auth="public")
|
|
def mail_guest_update_name(self, guest_id, name):
|
|
guest = request.env["mail.guest"]._get_guest_from_context()
|
|
guest_to_rename_sudo = guest.env["mail.guest"].browse(guest_id).sudo().exists()
|
|
if not guest_to_rename_sudo:
|
|
raise NotFound()
|
|
if guest_to_rename_sudo != guest and not request.env.user._is_admin():
|
|
raise NotFound()
|
|
guest_to_rename_sudo._update_name(name)
|