[FIX] mail: guest search error

Before this PR, I guest searching in discuss would get an access error.
This is because the search is searching in the attachments that the guest can't
access.

task-3637314

closes odoo/odoo#146110

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Didier (did)
2024-01-08 20:38:00 +00:00
parent 40c183f6d9
commit d507be4bf1
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -954,7 +954,8 @@ class Message(models.Model):
# we replace every space by a % to avoid hard spacing matching
search_term = search_term.replace(" ", "%")
domain = expression.AND([domain, expression.OR([
[("attachment_ids.name", "ilike", search_term)],
# sudo: access to attachment is allowed if you have access to the parent model
[("attachment_ids", "in", self.env["ir.attachment"].sudo()._search([("name", "ilike", search_term)]))],
[("body", "ilike", search_term)],
[("subject", "ilike", search_term)],
[("subtype_id.description", "ilike", search_term)],
@@ -130,5 +130,24 @@ registry.category("web_tour.tours").add("discuss_channel_public_tour.js", {
await contains(".o-mail-AttachmentCard", { text: "extra.txt", count: 0 });
},
},
{
content: "Open search panel",
trigger: "button[title='Search Messages']",
},
{
content: "Search for the attachment name",
trigger: ".o_searchview_input",
run: "text text.txt",
},
{
content: "Trigger the search",
trigger: "button[aria-label='Search button']",
},
{
content: "Check that searched message contains the attachment",
trigger:
'.o-mail-SearchMessagesPanel .o-mail-Message .o-mail-AttachmentCard:contains("text.txt")',
run() {},
},
],
});