diff --git a/mail_forward/__manifest__.py b/mail_forward/__manifest__.py index 6134ef4a64..7eb972af2c 100644 --- a/mail_forward/__manifest__.py +++ b/mail_forward/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Mail Forward Message", - "version": "15.0.1.0.1", + "version": "17.0.1.0.0", "summary": "Forward messages from the chatter of any document to other users.", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/social", @@ -12,10 +12,8 @@ ], "assets": { "web.assets_backend": [ - "mail_forward/static/src/components/**/*.esm.js", - ], - "web.assets_qweb": [ - "mail_forward/static/src/components/*/*.xml", + "mail_forward/static/src/**/*.esm.js", + "mail_forward/static/src/**/*.xml", ], "web.assets_tests": [ "mail_forward/static/tests/tours/**/*", diff --git a/mail_forward/models/mail_message.py b/mail_forward/models/mail_message.py index b5bacd6214..57a68cfbeb 100644 --- a/mail_forward/models/mail_message.py +++ b/mail_forward/models/mail_message.py @@ -17,7 +17,7 @@ def action_wizard_forward(self): action["views"] = [(view.id, view.type)] action["context"] = { "default_model": self.model, - "default_res_id": self.res_id, + "default_res_ids": [self.res_id], "default_composition_mode": "comment", "default_body": self._build_message_body_for_forward(), "default_attachment_ids": self.attachment_ids.ids, diff --git a/mail_forward/models/mail_thread.py b/mail_forward/models/mail_thread.py index ea0bfac3e1..babb29db52 100644 --- a/mail_forward/models/mail_thread.py +++ b/mail_forward/models/mail_thread.py @@ -6,8 +6,8 @@ class MailThread(models.AbstractModel): _inherit = "mail.thread" - def _notify_compute_recipients(self, message, msg_vals): - recipients_data = super()._notify_compute_recipients(message, msg_vals) + def _notify_get_recipients(self, message, msg_vals, **kwargs): + recipients_data = super()._notify_get_recipients(message, msg_vals, **kwargs) # only notify to explicit partners, remove others(followers). if self.env.context.get("message_forwarded_id"): current_partners_ids = message.partner_ids.ids diff --git a/mail_forward/static/src/components/forward_message/forward_message.esm.js b/mail_forward/static/src/components/forward_message/forward_message.esm.js index 654b74a077..0fc7c0ca21 100644 --- a/mail_forward/static/src/components/forward_message/forward_message.esm.js +++ b/mail_forward/static/src/components/forward_message/forward_message.esm.js @@ -2,35 +2,31 @@ /* Copyright 2024 Tecnativa - Carlos Lopez License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). */ -import {registerMessagingComponent} from "@mail/utils/messaging_component"; const {Component} = owl; +import {useService} from "@web/core/utils/hooks"; export class ForwardMessage extends Component { + setup() { + super.setup(); + this.threadService = useService("mail.thread"); + } async onClickForwardMessage() { const composer = this.props.message.originThread.composer; - const action = await this.env.services.rpc({ - model: "mail.message", - method: "action_wizard_forward", - args: [[this.props.message.id]], - }); - this.env.bus.trigger("do-action", { - action: action, - options: { - additional_context: { - active_id: this.props.message.id, - active_ids: [this.props.message.id], - active_model: "mail.message", - }, - on_close: () => { - if (composer.exists()) { - composer._reset(); - if (composer.activeThread) { - composer.activeThread.loadNewMessages(); - composer.activeThread.refreshFollowers(); - composer.activeThread.fetchAndUpdateSuggestedRecipients(); - } - } - }, + const action = await this.env.services.orm.call( + "mail.message", + "action_wizard_forward", + [[this.props.message.id]] + ); + this.env.services.action.doAction(action, { + additionalContext: { + active_id: this.props.message.id, + active_ids: [this.props.message.id], + active_model: "mail.message", + }, + onClose: () => { + if (composer.thread) { + this.threadService.fetchNewMessages(composer.thread); + } }, }); } @@ -40,5 +36,3 @@ ForwardMessage.template = "mail_forward.ForwardMessage"; ForwardMessage.props = { message: Object, }; - -registerMessagingComponent(ForwardMessage); diff --git a/mail_forward/static/src/components/forward_message/forward_message.xml b/mail_forward/static/src/components/forward_message/forward_message.xml index 0da6d778cb..070664668a 100644 --- a/mail_forward/static/src/components/forward_message/forward_message.xml +++ b/mail_forward/static/src/components/forward_message/forward_message.xml @@ -1,32 +1,34 @@ - - +
- - - - + + + + + + Forward +
diff --git a/mail_forward/static/src/components/message_action_list/message_action_list.xml b/mail_forward/static/src/components/message_action_list/message_action_list.xml deleted file mode 100644 index 4f13fa8fb2..0000000000 --- a/mail_forward/static/src/components/message_action_list/message_action_list.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - diff --git a/mail_forward/static/src/core/common/message.xml b/mail_forward/static/src/core/common/message.xml new file mode 100644 index 0000000000..2fd6f57fb6 --- /dev/null +++ b/mail_forward/static/src/core/common/message.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + diff --git a/mail_forward/static/src/core/common/message_actions.esm.js b/mail_forward/static/src/core/common/message_actions.esm.js new file mode 100644 index 0000000000..37b7fb0198 --- /dev/null +++ b/mail_forward/static/src/core/common/message_actions.esm.js @@ -0,0 +1,17 @@ +/* @odoo-module */ +/* Copyright 2024 Tecnativa - Carlos Lopez + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +*/ + +import {_t} from "@web/core/l10n/translation"; +import {ForwardMessage} from "../../components/forward_message/forward_message.esm"; +import {messageActionsRegistry} from "@mail/core/common/message_actions"; + +messageActionsRegistry.add("forward", { + callComponent: ForwardMessage, + props: (component) => ({message: component.props.message}), + condition: (component) => + component.props.message.is_discussion && !component.props.message.is_note, + sequence: 15, + title: _t("Forward"), +}); diff --git a/mail_forward/static/tests/tours/mail_forward.esm.js b/mail_forward/static/tests/tours/mail_forward.esm.js index 4845900a34..3f4b720fce 100644 --- a/mail_forward/static/tests/tours/mail_forward.esm.js +++ b/mail_forward/static/tests/tours/mail_forward.esm.js @@ -1,6 +1,7 @@ /** @odoo-module */ -import tour from "web_tour.tour"; +import {registry} from "@web/core/registry"; + const contact_steps = [ { trigger: ".o_navbar_apps_menu button", @@ -11,7 +12,7 @@ const contact_steps = [ { content: "Search Contact", trigger: ".o_searchview_input", - run: "text Test", + run: "text Test Forward", }, { trigger: ".o_menu_item", @@ -25,39 +26,22 @@ const contact_steps = [ }, { content: "Open contact", - trigger: ".o_list_table td[name='display_name']:contains('Test')", + trigger: ".o_list_table td[name='complete_name']:contains('Test Forward')", }, ]; -tour.register( - "mail_forward.mail_forward_tour", - { - test: true, - url: "/web", - }, - [ +registry.category("web_tour.tours").add("mail_forward.mail_forward_tour", { + test: true, + url: "/web", + steps: () => [ ...contact_steps, - { - content: "Open Chat", - trigger: ".o_ChatterTopbar_buttonSendMessage", - run: "click", - }, - { - content: "Write a message", - trigger: ".o_ComposerTextInput_textarea", - run: "text Hello World", - }, - { - content: "Post a message", - trigger: ".o_Composer_buttonSend", - }, { content: "Hover a message", - trigger: "div.o_Message.o-discussion", + trigger: "div.o-mail-Message[aria-label='Message'] button.dropdown-toggle", run: "click", }, { content: "Forward a message", - trigger: ".o_MessageActionList_actionForward", + trigger: ".mail_forward_message", run: "click", }, { @@ -80,42 +64,24 @@ tour.register( { content: "Check Mail Forward", trigger: - ".o_Message_prettyBody:contains(---------- Forwarded message ---------)", + "div.o-mail-Message[aria-label='Message']:contains(---------- Forwarded message ---------)", }, - ] -); + ], +}); -tour.register( - "mail_forward.mail_note_not_forward_tour", - { - test: true, - url: "/web", - }, - [ +registry.category("web_tour.tours").add("mail_forward.mail_note_not_forward_tour", { + test: true, + url: "/web", + steps: () => [ ...contact_steps, - { - content: "Open Chat", - trigger: ".o_ChatterTopbar_buttonLogNote", - run: "click", - }, - { - content: "Write a note", - trigger: ".o_ComposerTextInput_textarea", - run: "text This is a note", - }, - { - content: "Post a note", - trigger: ".o_Composer_buttonSend", - }, { content: "Hover a note", - trigger: "div.o_Message.o-not-discussion", + trigger: "div.o-mail-Message[aria-label='Note']", run: "click", }, { content: "Verify that the Forward button does not exist.", - trigger: - "div.o_Message.o-not-discussion:not(.o_MessageActionList_actionForward)", + trigger: "div.o-mail-Message[aria-label='Note']:not(.mail_forward_message)", }, - ] -); + ], +}); diff --git a/mail_forward/tests/test_mail_forward.py b/mail_forward/tests/test_mail_forward.py index b6e632b353..88f311bf49 100644 --- a/mail_forward/tests/test_mail_forward.py +++ b/mail_forward/tests/test_mail_forward.py @@ -12,6 +12,7 @@ class TestMailForward(TestMailComposer, HttpCase): @classmethod def setUpClass(cls): super().setUpClass() + cls.test_record.write({"name": "Test Forward", "email": "test@example.com"}) cls.partner_follower1 = cls.env["res.partner"].create( {"name": "Follower1", "email": "follower1@example.com"} ) @@ -29,7 +30,7 @@ def test_01_mail_forward(self): """ ctx = { "default_model": self.test_record._name, - "default_res_id": self.test_record.id, + "default_res_ids": [self.test_record.id], } composer_form = Form(self.env["mail.compose.message"].with_context(**ctx)) composer_form.body = "

Hello

" @@ -69,9 +70,15 @@ def test_01_mail_forward(self): self.assertIn("---------- Forwarded message ---------", forward_message.body) def test_02_mail_forward_tour(self): + self.test_record.message_post( + body="Hello World", message_type="comment", subtype_xmlid="mail.mt_comment" + ) self.start_tour("/web", "mail_forward.mail_forward_tour", login="admin") def test_03_mail_note_not_forward_tour(self): + self.test_record.message_post( + body="This is a note", message_type="comment", subtype_xmlid="mail.mt_note" + ) self.start_tour( "/web", "mail_forward.mail_note_not_forward_tour", login="admin" ) diff --git a/mail_forward/wizards/mail_compose_message.py b/mail_forward/wizards/mail_compose_message.py index 19ccfcb890..cb36069e2c 100644 --- a/mail_forward/wizards/mail_compose_message.py +++ b/mail_forward/wizards/mail_compose_message.py @@ -15,7 +15,7 @@ def get_record_data(self, values): # remove 'Re: ' prefixes and add 'Fwd:' prefix to the subject subject = result.get("subject") if subject and subject.startswith(re_prefix): - subject = "%s %s" % (fwd_prefix, subject[4:]) + subject = f"{fwd_prefix} {subject[4:]}" result["subject"] = subject return result diff --git a/mail_forward/wizards/mail_compose_message_view.xml b/mail_forward/wizards/mail_compose_message_view.xml index bda46bed9c..1327be8d2e 100644 --- a/mail_forward/wizards/mail_compose_message_view.xml +++ b/mail_forward/wizards/mail_compose_message_view.xml @@ -17,7 +17,7 @@ 1 1