[FIX] mail: thread search works for all channels

1. channel mention should work for channels, chats, and groups, even if
there is a group restriction for the channel.
2. channel mention in livechat is disabled because the visitor can't get
access to the channel.
3. remove the fetch and search for channel mentions in livechat so that
there is no extra rpc call for unuseful data.
4. add a test for the channel mention in thread.

closes odoo/odoo#155380

Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
zel-odoo
2024-02-27 17:40:52 +00:00
parent 865b6703a1
commit aa87b65dc8
4 changed files with 68 additions and 19 deletions
@@ -11,8 +11,15 @@ patch(SuggestionService.prototype, {
? [...super.getSupportedDelimiters(...arguments), [":"]]
: super.getSupportedDelimiters(...arguments);
},
async fetchSuggestions({ delimiter, term }, { thread } = {}) {
if (thread.type === "livechat" && delimiter === "#") {
return;
}
return super.fetchSuggestions(...arguments);
},
/**
* Returns suggestions that match the given search term from specified type.
* Searching on channels is disabled in livechat since the visitor don't have access to channels.
*
* @param {Object} [param0={}]
* @param {String} [param0.delimiter] can be one one of the following: ["@", ":", "#", "/"]
@@ -23,6 +30,13 @@ patch(SuggestionService.prototype, {
* @returns {[mainSuggestion[], extraSuggestion[]]}
*/
searchSuggestions({ delimiter, term }, { thread } = {}, sort = false) {
if (thread.type === "livechat" && delimiter === "#") {
return {
type: undefined,
mainSuggestions: [],
extraSuggestions: [],
};
}
if (delimiter === ":") {
return this.searchCannedResponseSuggestions(cleanTerm(term), sort);
}
@@ -32,3 +32,26 @@ QUnit.test("Suggestions are shown after delimiter was used in text (:)", async (
await insertText(".o-mail-Composer-input", " :");
await contains(".o-mail-Composer-suggestion strong", { text: "hello" });
});
QUnit.test("Cannot mention other channels in a livechat", async () => {
const pyEnv = await startServer();
const [channelId] = pyEnv["discuss.channel"].create([
{
anonymous_name: "Visitor",
channel_type: "livechat",
channel_member_ids: [
Command.create({ partner_id: pyEnv.currentPartnerId }),
Command.create({ partner_id: pyEnv.publicPartnerId }),
],
},
{
channel_type: "channel",
group_public_id: false,
name: "Link and Zelda",
},
]);
const { openDiscuss } = await start();
await openDiscuss(channelId);
await insertText(".o-mail-Composer-input", "#");
await contains(".o-mail-Composer-suggestion", { count: 0 });
});
@@ -85,7 +85,7 @@ export class SuggestionService {
return this.searchPartnerSuggestions(cleanedSearchTerm, thread, sort);
}
case "#":
return this.searchChannelSuggestions(cleanedSearchTerm, thread, sort);
return this.searchChannelSuggestions(cleanedSearchTerm, sort);
}
return {
type: undefined,
@@ -168,24 +168,8 @@ export class SuggestionService {
});
}
searchChannelSuggestions(cleanedSearchTerm, thread, sort) {
let threads;
if (
thread &&
(thread.type === "group" ||
thread.type === "chat" ||
(thread.type === "channel" && thread.authorizedGroupFullName))
) {
// Only return the current channel when in the context of a
// group restricted channel or group or chat. Indeed, the message with the mention
// would appear in the target channel, so this prevents from
// inadvertently leaking the private message into the mentioned
// channel.
threads = [thread];
} else {
threads = Object.values(this.store.Thread.records);
}
const suggestionList = threads.filter(
searchChannelSuggestions(cleanedSearchTerm, sort) {
const suggestionList = Object.values(this.store.Thread.records).filter(
(thread) =>
thread.type === "channel" &&
thread.displayName &&
@@ -213,6 +213,34 @@ QUnit.test("thread is still scrolling after scrolling up then to bottom", async
await contains(".o-mail-Thread", { scroll: "bottom" });
});
QUnit.test("Can mention other channels in a group-restricted channel", async () => {
const pyEnv = await startServer();
const groupId = pyEnv["res.groups"].create({
name: "Mario Group",
});
const [channelId1] = pyEnv["discuss.channel"].create([
{
channel_type: "channel",
group_public_id: groupId,
name: "Marios",
},
{
channel_type: "channel",
group_public_id: false,
name: "Link and Zelda",
},
]);
const { openDiscuss } = await start();
openDiscuss(channelId1);
await insertText(".o-mail-Composer-input", "#");
await contains(".o-mail-Composer-suggestion", { text: "#Marios" });
await contains(".o-mail-Composer-suggestion", { text: "#Link and Zelda" });
await click(".o-mail-Composer-suggestion", { text: "#Link and Zelda" });
await contains(".o-mail-Composer-input", { value: "#Link and Zelda " });
await click(".o-mail-Composer-send:enabled");
await contains(".o-mail-Message-body .o_channel_redirect", { text: "#Link and Zelda" });
});
QUnit.test("mention a channel with space in the name", async () => {
const pyEnv = await startServer();
const channelId = pyEnv["discuss.channel"].create({ name: "General good boy" });