[FIX] mail: no crash on opening non-existing channel
closes odoo/odoo#140562 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -28,7 +28,10 @@ class ChannelController(http.Controller):
|
||||
@http.route("/discuss/channel/info", methods=["POST"], type="json", auth="public")
|
||||
@add_guest_to_context
|
||||
def discuss_channel_info(self, channel_id):
|
||||
return request.env["discuss.channel"].search([("id", "=", channel_id)])._channel_info()
|
||||
channel = request.env["discuss.channel"].search([("id", "=", channel_id)])
|
||||
if not channel:
|
||||
return
|
||||
return channel._channel_info()[0]
|
||||
|
||||
@http.route("/discuss/channel/messages", methods=["POST"], type="json", auth="public")
|
||||
@add_guest_to_context
|
||||
|
||||
@@ -44,10 +44,13 @@ export class ThreadService {
|
||||
/**
|
||||
* @param {import("models).Thread} thread
|
||||
* @param {number} id
|
||||
* @returns {Promise<import("models").Thread>}
|
||||
* @returns {Promise<import("models").Thread|undefined>}
|
||||
*/
|
||||
async fetchChannel(id) {
|
||||
const [channelData] = await this.rpc("/discuss/channel/info", { channel_id: id });
|
||||
const channelData = await this.rpc("/discuss/channel/info", { channel_id: id });
|
||||
if (!channelData) {
|
||||
return;
|
||||
}
|
||||
return this.store.Thread.insert({
|
||||
...channelData,
|
||||
model: "discuss.channel",
|
||||
|
||||
@@ -58,6 +58,9 @@ export class DiscussClientAction extends Component {
|
||||
const thread =
|
||||
this.store.Thread.get({ model, id }) ??
|
||||
(await this.threadService.fetchChannel(parseInt(id)));
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
if (!thread.is_pinned) {
|
||||
await this.threadService.pin(thread);
|
||||
}
|
||||
|
||||
@@ -233,12 +233,10 @@ export class DiscussCoreCommon {
|
||||
const { id, message: messageData } = notif.payload;
|
||||
let channel = this.store.Thread.get({ model: "discuss.channel", id });
|
||||
if (!channel || !channel.type) {
|
||||
const [channelData] = await this.rpc("/discuss/channel/info", { channel_id: id });
|
||||
channel = this.store.Thread.insert({
|
||||
model: "discuss.channel",
|
||||
type: channelData.channel_type,
|
||||
...channelData,
|
||||
});
|
||||
channel = await this.threadService.fetchChannel(id);
|
||||
if (!channel) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!channel.is_pinned) {
|
||||
this.threadService.pin(channel);
|
||||
|
||||
@@ -193,3 +193,10 @@ QUnit.test("Chat is added to discuss on other tab that the one that joined", asy
|
||||
await contains(".o-mail-DiscussSidebarChannel", { target: tab1.target, text: "Jerry Golay" });
|
||||
await contains(".o-mail-DiscussSidebarChannel", { target: tab2.target, text: "Jerry Golay" });
|
||||
});
|
||||
|
||||
QUnit.test("no conversation selected when opening non-existing channel in discuss", async () => {
|
||||
await startServer();
|
||||
const { openDiscuss } = await start();
|
||||
await openDiscuss(200); // non-existing id
|
||||
await contains("h4", { text: "No conversation selected." });
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ patch(MockServer.prototype, {
|
||||
}
|
||||
if (route === "/discuss/channel/info") {
|
||||
const id = args.channel_id;
|
||||
return this._mockDiscussChannelChannelInfo([id]);
|
||||
return this._mockDiscussChannelChannelInfo([id])[0];
|
||||
}
|
||||
if (args.model === "discuss.channel" && args.method === "add_members") {
|
||||
const ids = args.args[0];
|
||||
|
||||
@@ -34,27 +34,13 @@ registryNamesToCloneWithCleanup.push("mock_server_callbacks", "discuss.model");
|
||||
function getOpenDiscuss(webClient, { context = {}, params = {}, ...props } = {}) {
|
||||
return async function openDiscuss(pActiveId) {
|
||||
const actionOpenDiscuss = {
|
||||
context: { ...context, active_id: pActiveId },
|
||||
// hardcoded actionId, required for discuss_container props validation.
|
||||
id: 104,
|
||||
context,
|
||||
params,
|
||||
tag: "mail.action_discuss",
|
||||
type: "ir.actions.client",
|
||||
};
|
||||
const activeId =
|
||||
pActiveId ?? context.active_id ?? params.default_active_id ?? "mail.box_inbox";
|
||||
let [threadModel, threadId] =
|
||||
typeof activeId === "number" ? ["discuss.channel", activeId] : activeId.split("_");
|
||||
if (threadModel === "discuss.channel") {
|
||||
threadId = parseInt(threadId, 10);
|
||||
}
|
||||
// TODO-DISCUSS-REFACTORING: remove when activeId will be handled.
|
||||
webClient.env.services["mail.thread"].setDiscussThread(
|
||||
webClient.env.services["mail.store"].Thread.insert({
|
||||
model: threadModel,
|
||||
id: threadId,
|
||||
})
|
||||
);
|
||||
await doAction(webClient, actionOpenDiscuss, { props });
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user