From b711020e8d2d7e36932e3b458aa8adaf33609e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Thu, 13 Jul 2023 12:50:41 +0000 Subject: [PATCH] [FIX] mail: no suggested recipients in full composer of log note MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, opening full composer from chatter were always copying the selected suggested recipients, regardless of the mode of the composer. Suggested recipients only makes sense in "Send message" mode, therefore it should not copy them in "Log note" mode, which this commit fixes. Also fix a bug where copying of suggested recipients in full composer was taking all suggested recipients into account, regardless of checkbox state. This commit fixes issue by copying only checked suggested recipients closes odoo/odoo#128466 X-original-commit: 89afc58a69a53824a9100ceaf4f3574bb82dfc1d Signed-off-by: Sébastien Theys (seb) Signed-off-by: Alexandre Kühn (aku) --- .../mail/static/src/core/common/composer.js | 9 ++- .../composer/suggested_recipients_test.js | 76 +++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/addons/mail/static/src/core/common/composer.js b/addons/mail/static/src/core/common/composer.js index d4942674983..67b77ced0dd 100644 --- a/addons/mail/static/src/core/common/composer.js +++ b/addons/mail/static/src/core/common/composer.js @@ -434,9 +434,12 @@ export class Composer extends Component { default_attachment_ids: attachmentIds, default_body: escapeAndCompactTextContent(this.props.composer.textInputContent), default_model: this.props.composer.thread.model, - default_partner_ids: this.props.composer.thread.suggestedRecipients.map( - (recipient) => recipient.persona.id - ), + default_partner_ids: + this.props.type === "note" + ? [] + : this.props.composer.thread.suggestedRecipients + .filter((recipient) => recipient.checked) + .map((recipient) => recipient.persona.id), default_res_ids: [this.props.composer.thread.id], default_subtype_xmlid: this.props.type === "note" ? "mail.mt_note" : "mail.mt_comment", mail_post_autofollow: this.props.composer.thread.hasWriteAccess, diff --git a/addons/mail/static/tests/composer/suggested_recipients_test.js b/addons/mail/static/tests/composer/suggested_recipients_test.js index 86dc787bb2c..3faeb4cffea 100644 --- a/addons/mail/static/tests/composer/suggested_recipients_test.js +++ b/addons/mail/static/tests/composer/suggested_recipients_test.js @@ -7,6 +7,7 @@ import { startServer, waitUntil, } from "@mail/../tests/helpers/test_utils"; +import { patchWithCleanup } from "@web/../tests/helpers/utils"; const views = { "res.fake,false,form": ` @@ -37,6 +38,81 @@ QUnit.test("with 3 or less suggested recipients: no 'show more' button", async ( assert.containsNone($, "button:contains(Show more)"); }); +QUnit.test( + "Opening full composer in 'send message' mode should copy selected suggested recipients", + async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ + display_name: "John Jane", + email: "john@jane.be", + }); + const fakeId = pyEnv["res.fake"].create({ + email_cc: "john@test.be", + partner_ids: [partnerId], + }); + const { env, openFormView } = await start(); + await openFormView("res.fake", fakeId); + patchWithCleanup(env.services.action, { + doAction(action) { + assert.step("do-action"); + assert.strictEqual(action.name, "Compose Email"); + assert.strictEqual(action.context.default_subtype_xmlid, "mail.mt_comment"); + assert.deepEqual(action.context.default_partner_ids, [partnerId]); + return Promise.resolve(); + }, + }); + await click("button:contains(Send message)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(john@test.be)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(John Jane)"); + assert.notOk( + $(".o-mail-SuggestedRecipient:contains(john@test.be) input[type=checkbox]")[0].checked + ); + assert.ok( + $(".o-mail-SuggestedRecipient:contains(John Jane) input[type=checkbox]")[0].checked + ); + await click("button[title='Full composer']"); + assert.verifySteps(["do-action"]); + } +); + +QUnit.test( + "Opening full composer in 'log note' mode should not copy selected suggested recipients", + async (assert) => { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ + display_name: "John Jane", + email: "john@jane.be", + }); + const fakeId = pyEnv["res.fake"].create({ + email_cc: "john@test.be", + partner_ids: [partnerId], + }); + const { env, openFormView } = await start(); + await openFormView("res.fake", fakeId); + patchWithCleanup(env.services.action, { + doAction(action) { + assert.step("do-action"); + assert.strictEqual(action.name, "Log note"); + assert.strictEqual(action.context.default_subtype_xmlid, "mail.mt_note"); + assert.deepEqual(action.context.default_partner_ids, []); + return Promise.resolve(); + }, + }); + await click("button:contains(Send message)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(john@test.be)"); + assert.containsOnce($, ".o-mail-SuggestedRecipient:contains(John Jane)"); + assert.notOk( + $(".o-mail-SuggestedRecipient:contains(john@test.be) input[type=checkbox]")[0].checked + ); + assert.ok( + $(".o-mail-SuggestedRecipient:contains(John Jane) input[type=checkbox]")[0].checked + ); + await click("button:contains(Log note)"); + await click("button[title='Full composer']"); + assert.verifySteps(["do-action"]); + } +); + QUnit.test( "more than 3 suggested recipients: display only 3 and 'show more' button", async (assert) => {