From af21d99a36db0452f6fcdf6d70b82f3bd5f0d432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 14 Jun 2023 15:05:15 +0000 Subject: [PATCH] [FIX] mail: pass props to thread actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since [1] thread actions are stored in a specific registry. Some of those actions require props to be passed to their component. Those props are not correctly passed as the `componentProps` key is in fact a function that returns the props but is treated as the props themselves. This commit fixes this issue by transforming `componentProps` into a getter, so that `action` is internally passed to `componentProps` definition. The templates using thread actions can still use `t-props="componentProps"` as getter, as the active action is deduced by transform automatically. [1]: odoo#123454 closes odoo/odoo#125120 Signed-off-by: Sébastien Theys (seb) --- .../static/src/core/common/thread_actions.js | 4 ++- .../discuss/core/channel_invitation_tests.js | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/core/common/thread_actions.js b/addons/mail/static/src/core/common/thread_actions.js index 10fc80bbbb9..811d3588be5 100644 --- a/addons/mail/static/src/core/common/thread_actions.js +++ b/addons/mail/static/src/core/common/thread_actions.js @@ -35,7 +35,9 @@ function transformAction(component, id, action) { return this.isActive && this.component && this.condition && !this.popover; }, /** Props to pass to the component of this action. */ - componentProps: action.componentProps, + get componentProps() { + return action.componentProps?.(this); + }, /** Condition to display this action. */ get condition() { return action.condition(component); diff --git a/addons/mail/static/tests/discuss/core/channel_invitation_tests.js b/addons/mail/static/tests/discuss/core/channel_invitation_tests.js index 880a1aa55ac..d38b03ea13d 100644 --- a/addons/mail/static/tests/discuss/core/channel_invitation_tests.js +++ b/addons/mail/static/tests/discuss/core/channel_invitation_tests.js @@ -29,6 +29,33 @@ QUnit.test( } ); +QUnit.test("can invite users in channel from chat window", async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ + email: "testpartner@odoo.com", + name: "TestPartner", + }); + pyEnv["res.users"].create({ partner_id: partnerId }); + pyEnv["discuss.channel"].create({ + name: "TestChanel", + channel_member_ids: [ + Command.create({ partner_id: pyEnv.currentPartnerId, is_minimized: true }), + ], + channel_type: "channel", + }); + await start(); + await click("[title='More actions']"); + await click("[title='Add Users']"); + assert.containsOnce($, ".o-discuss-ChannelInvitation"); + await click("div:contains(TestPartner) input[type='checkbox']"); + await click("[title='Invite to Channel']"); + assert.containsNone($, ".o-discuss-ChannelInvitation"); + assert.containsOnce( + $, + ".o-mail-Thread .o-mail-NotificationMessage:contains(Mitchell Admin invited TestPartner to the channel)" + ); +}); + QUnit.test( "should be able to search for a new user to invite from an existing chat", async (assert) => {