[FIX] mail: standardize way to get guest from context

Backport of `_get_guest_from_context`.

Prevent crash when unexpected (not recordset) values are in the context.

Ensure the mere existence of a value (example integer) does not lead to
executing flows where an actual guest is expected.

task-2819597

closes odoo/odoo#127831

X-original-commit: 3d1890e88b99f059377d8b227b56d77798157397
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2023-07-10 15:33:06 +02:00
parent f90253d3a3
commit 6dacefd50a
4 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ class IrHttp(models.AbstractModel):
result = super(IrHttp, self).session_info()
if self.env.user._is_internal():
result['notification_type'] = user.notification_type
guest = self.env.context.get('guest')
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 []
+2 -1
View File
@@ -197,10 +197,11 @@ class Message(models.Model):
@api.depends_context('guest', 'uid')
def _compute_is_current_user_or_guest_author(self):
user = self.env.user
guest = self.env['mail.guest']._get_guest_from_context()
for message in self:
if not user._is_public() and (message.author_id and message.author_id == user.partner_id):
message.is_current_user_or_guest_author = True
elif user._is_public() and (message.author_guest_id and message.author_guest_id == self.env.context.get('guest')):
elif message.author_guest_id and message.author_guest_id == guest:
message.is_current_user_or_guest_author = True
else:
message.is_current_user_or_guest_author = False
+3 -2
View File
@@ -2023,8 +2023,9 @@ class MailThread(models.AbstractModel):
self = self._fallback_lang()
# Find the message's author
if self.env.user._is_public() and 'guest' in self.env.context:
author_guest_id = self.env.context['guest'].id
guest = self.env['mail.guest']._get_guest_from_context()
if self.env.user._is_public() and guest:
author_guest_id = guest.id
author_id, email_from = False, False
else:
author_guest_id = False
+1 -1
View File
@@ -245,7 +245,7 @@ class Partner(models.Model):
"id": main_user.id,
"isInternalUser": not main_user.share,
} if main_user else [('clear',)]
if 'guest' in self.env.context or not self.env.user._is_internal():
if not self.env.user._is_internal():
data.pop('email', None)
partners_format[partner] = data
return partners_format