Files
odoo_source/addons/mail/models/ir_http.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

28 lines
992 B
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo
from odoo import models
from odoo.http import request
class IrHttp(models.AbstractModel):
_inherit = 'ir.http'
def session_info(self):
user = self.env.user
result = super(IrHttp, self).session_info()
if self.env.user._is_internal():
result['notification_type'] = user.notification_type
guest = self.env['mail.guest']._get_guest_from_context()
if not request.session.uid and guest:
user_context = {'lang': guest.lang}
mods = odoo.conf.server_wide_modules or []
lang = user_context.get("lang")
translation_hash = self.env['ir.http'].sudo().get_web_translations_hash(mods, lang)
result['cache_hashes']['translations'] = translation_hash
result.update({
'name': guest.name,
'user_context': user_context,
})
return result