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>
31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class LinkPreviewController(http.Controller):
|
|
@http.route("/mail/link_preview", methods=["POST"], type="json", auth="public")
|
|
def mail_link_preview(self, message_id, clear=None):
|
|
if not request.env["mail.link.preview"]._is_link_preview_enabled():
|
|
return
|
|
guest = request.env["mail.guest"]._get_guest_from_context()
|
|
message = guest.env["mail.message"].search([("id", "=", int(message_id))])
|
|
if not message:
|
|
return
|
|
if not message.is_current_user_or_guest_author and not guest.env.user._is_admin():
|
|
return
|
|
if clear:
|
|
guest.env["mail.link.preview"]._clear_link_previews(message.sudo())
|
|
guest.env["mail.link.preview"].sudo()._create_link_previews(message)
|
|
|
|
@http.route("/mail/link_preview/delete", methods=["POST"], type="json", auth="public")
|
|
def mail_link_preview_delete(self, link_preview_id):
|
|
guest = request.env["mail.guest"]._get_guest_from_context()
|
|
link_preview_sudo = guest.env["mail.link.preview"].sudo().search([("id", "=", int(link_preview_id))])
|
|
if not link_preview_sudo:
|
|
return
|
|
if not link_preview_sudo.message_id.is_current_user_or_guest_author and not guest.env.user._is_admin():
|
|
return
|
|
link_preview_sudo._delete_and_notify()
|