Skip to content

Commit

Permalink
[MIG] mail_forward: Migration to version 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-lopez-tecnativa committed Jan 21, 2025
1 parent 807ef4a commit edfbe03
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 127 deletions.
8 changes: 3 additions & 5 deletions mail_forward/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/**/*",
Expand Down
2 changes: 1 addition & 1 deletion mail_forward/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions mail_forward/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
});
}
Expand All @@ -40,5 +36,3 @@ ForwardMessage.template = "mail_forward.ForwardMessage";
ForwardMessage.props = {
message: Object,
};

registerMessagingComponent(ForwardMessage);
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates xml:space="preserve">
<t t-name="mail_forward.ForwardMessage" owl="1">
<span
class="o_MessageActionList_action o_MessageActionList_actionForward fa-stack"
<t t-name="mail_forward.ForwardMessage">
<div
class="mail_forward_message w-100"
title="Forward Message"
role="button"
tabindex="0"
aria-label="Forward Message"
t-on-click="onClickForwardMessage"
>
<i
class="fa fa-lg fa-share fa-stack-1x"
style="margin-left:1px"
role="img"
aria-label="Forward Message Left"
/>
<i
class="fa fa-lg fa-share fa-inverse fa-stack-1x"
style="margin-left:-2px;"
role="img"
aria-label="Forward Message Center"
/>
<i
class="fa fa-lg fa-share fa-stack-1x"
style="margin-left:-3px"
role="img"
aria-label="Forward Message Right"
/>
</span>
<span class="fa-stack" style="width: 1.5em">
<i
class="fa fa-lg fa-share fa-stack-1x"
style="margin-left:1px"
role="img"
aria-label="Forward Message Left"
/>
<i
class="fa fa-lg fa-share fa-inverse fa-stack-1x"
style="margin-left:-2px;"
role="img"
aria-label="Forward Message Center"
/>
<i
class="fa fa-lg fa-share fa-stack-1x"
style="margin-left:-3px"
role="img"
aria-label="Forward Message Right"
/>
</span>
Forward
</div>
</t>
</templates>

This file was deleted.

27 changes: 27 additions & 0 deletions mail_forward/static/src/core/common/message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates xml:space="preserve">
<t t-inherit="mail.Message.actions" t-inherit-mode="extension">
<!--
In the DropdownItem, render the callComponent if it is defined,
similar to how it is rendered for quick actions.
Currently, Odoo only renders the callComponent for quick actions (2 or 3 actions).
However, the remaining actions, rendered as DropdownItem, do not invoke the callComponent.
See the related code here:
https://github.com/odoo/odoo/blob/a32626be4cfbaeb21ed64a0abaad298e8e223ea3/addons/mail/static/src/core/common/message.xml#L146-L160 -->
<xpath expr="//DropdownItem//i" position="before">
<t
t-if="action.callComponent"
t-component="action.callComponent"
t-props="action.props"
/>
<t t-else="">
<!-- used to move the elements into the t-else -->
<span class="mail_action_item d-none" />
</t>
</xpath>
<xpath expr="//span[hasclass('mail_action_item')]" position="before">
<xpath expr="//DropdownItem/i" position="move" />
<xpath expr="//DropdownItem/t[@t-esc='action.title']" position="move" />
</xpath>
</t>
</templates>
17 changes: 17 additions & 0 deletions mail_forward/static/src/core/common/message_actions.esm.js
Original file line number Diff line number Diff line change
@@ -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"),
});
76 changes: 21 additions & 55 deletions mail_forward/static/tests/tours/mail_forward.esm.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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",
},
{
Expand All @@ -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)",
},
]
);
],
});
9 changes: 8 additions & 1 deletion mail_forward/tests/test_mail_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TestMailForward(TestMailComposer, HttpCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.test_record.write({"name": "Test Forward", "email": "[email protected]"})
cls.partner_follower1 = cls.env["res.partner"].create(
{"name": "Follower1", "email": "[email protected]"}
)
Expand All @@ -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 = "<p>Hello</p>"
Expand Down Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion mail_forward/wizards/mail_compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_record_data(self, values):
# remove 'Re: ' prefixes and add 'Fwd:' prefix to the subject
subject = result.get("subject")

Check warning on line 16 in mail_forward/wizards/mail_compose_message.py

View check run for this annotation

Codecov / codecov/patch

mail_forward/wizards/mail_compose_message.py#L16

Added line #L16 was not covered by tests
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

Check warning on line 20 in mail_forward/wizards/mail_compose_message.py

View check run for this annotation

Codecov / codecov/patch

mail_forward/wizards/mail_compose_message.py#L18-L20

Added lines #L18 - L20 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion mail_forward/wizards/mail_compose_message_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<attribute name="invisible">1</attribute>
</xpath>
<xpath
expr="//button[@name='action_save_as_template']"
expr="//button[@name='open_template_creation_wizard']"
position="attributes"
>
<attribute name="invisible">1</attribute>
Expand Down

0 comments on commit edfbe03

Please sign in to comment.