Skip to content

Commit

Permalink
[MIG] mail_tracking: Completed migration to 16.0
Browse files Browse the repository at this point in the history
The following changes were implemented:

1 - Added Failed Message component and related components to reuse the
  Message component when rendering failed messages. This allows us to
dispose of the messagefailed JS model altogether, since failed messages
are now just regular messages that were marked as failed.

2 - Fixed 'Retry' and 'Set as reviewed' flows for failed messages.

3 - Fixed `Failed sent messages` filter on models by overriding `get_view`
    instead of `_fields_view_get`

4 - Refactored folder structure to more closely resemble the `mail`
  module's folder structure.

5 - Refactored module to utilize `Command` as a means to create, write,
  etc. instead of `[0, ...]`, `[4, ...]`.

6 - Fixed and added unit tests.

7 - Removed dead/unused code.
  • Loading branch information
payen000 committed Sep 25, 2023
1 parent b3f4068 commit c2faec5
Show file tree
Hide file tree
Showing 44 changed files with 716 additions and 1,155 deletions.
37 changes: 21 additions & 16 deletions mail_tracking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,28 @@
"views/res_partner_view.xml",
],
"assets": {
"mail.assets_messaging": [
"mail_tracking/static/src/js/models/*.js",
],
"web.assets_backend": [
"mail_tracking/static/src/xml/mail_tracking.xml",
"mail_tracking/static/src/css/mail_tracking.scss",
"mail_tracking/static/src/css/failed_message.scss",
"mail_tracking/static/src/js/message.esm.js",
"mail_tracking/static/src/js/failed_message/mail_failed_box.esm.js",
"mail_tracking/static/src/js/models/thread.esm.js",
"mail_tracking/static/src/xml/mail_tracking.xml",
"mail_tracking/static/src/xml/failed_message/common.xml",
"mail_tracking/static/src/xml/failed_message/thread.xml",
"mail_tracking/static/src/xml/failed_message/discuss.xml",
],
"web.assets_frontend": [
"mail_tracking/static/src/css/failed_message.scss",
"mail_tracking/static/src/models/chatter.esm.js",
"mail_tracking/static/src/models/discuss_sidebar_mailbox_view.esm.js",
"mail_tracking/static/src/models/discuss_view.esm.js",
"mail_tracking/static/src/models/mailbox.esm.js",
"mail_tracking/static/src/models/message_list_view_item.esm.js",
"mail_tracking/static/src/models/message_list_view.esm.js",
"mail_tracking/static/src/models/message_view.esm.js",
"mail_tracking/static/src/models/message.esm.js",
"mail_tracking/static/src/models/messaging_initializer.esm.js",
"mail_tracking/static/src/models/messaging.esm.js",
"mail_tracking/static/src/models/thread.esm.js",
"mail_tracking/static/src/components/discuss/discuss.xml",
"mail_tracking/static/src/components/message/message.esm.js",
"mail_tracking/static/src/components/message/message.scss",
"mail_tracking/static/src/components/failed_message/failed_message.xml",
"mail_tracking/static/src/components/failed_message/failed_message.esm.js",
"mail_tracking/static/src/components/failed_message/failed_message.scss",
"mail_tracking/static/src/components/failed_message_list/failed_message_list.xml",
"mail_tracking/static/src/components/failed_message_list/failed_message_list.esm.js", # noqa: B950
"mail_tracking/static/src/components/thread_view/thread_view.xml",
"mail_tracking/static/src/components/thread_view/thread_view.scss",
],
},
"demo": ["demo/demo.xml"],
Expand Down
14 changes: 9 additions & 5 deletions mail_tracking/controllers/discuss.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ def mail_init_messaging(self):

@http.route("/mail/failed/messages", methods=["POST"], type="json", auth="user")
def discuss_failed_messages(self, max_id=None, min_id=None, limit=30, **kwargs):
return http.request.env["mail.message"]._message_fetch(
domain=[("is_failed_message", "=", True)],
max_id=max_id,
min_id=min_id,
limit=limit,
return (
http.request.env["mail.message"]
._message_fetch(
domain=[("is_failed_message", "=", True)],
max_id=max_id,
min_id=min_id,
limit=limit,
)
.message_format()
)
25 changes: 0 additions & 25 deletions mail_tracking/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,6 @@ def _request_metadata(self):
"ua_family": request.user_agent.browser or False,
}

# TODO Remove useless controller
@http.route(
[
"/mail/tracking/all/<string:db>",
"/mail/tracking/event/<string:db>/<string:event_type>",
],
type="http",
auth="none",
csrf=False,
)
def mail_tracking_event(self, db, event_type=None, **kw):
"""Route used by external mail service"""
metadata = self._request_metadata()
res = None
with db_env(db) as env:
try:
res = env["mail.tracking.email"].event_process(
http.request, kw, metadata, event_type=event_type
)
except Exception as e:
_logger.warning(e)
if not res or res == "NOT FOUND":
return werkzeug.exceptions.NotAcceptable()
return res

@http.route(
[
"/mail/tracking/open/<string:db>" "/<int:tracking_email_id>/blank.gif",
Expand Down
28 changes: 20 additions & 8 deletions mail_tracking/demo/demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
<field name="body"><![CDATA[<p>This is a message with CC</p>]]></field>
<field name="email_from">[email protected]</field>
<field name="author_id" ref="base.res_partner_1" />
<field name="partner_ids" eval="[(6, 0, [ref('base.partner_demo')])]" />
<field
name="partner_ids"
eval="[Command.set([ref('base.partner_demo')])]"
/>
<field
name="notification_ids"
eval="[(0, 0, {'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
/>
<field name="subject">Message with CC</field>
</record>
Expand All @@ -41,10 +44,13 @@
<field name="body"><![CDATA[<p>This is a failed message</p>]]></field>
<field name="email_from">[email protected]</field>
<field name="author_id" ref="base.res_partner_1" />
<field name="partner_ids" eval="[(6, 0, [ref('base.partner_demo')])]" />
<field
name="partner_ids"
eval="[Command.set([ref('base.partner_demo')])]"
/>
<field
name="notification_ids"
eval="[(0, 0, {'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
/>
<field name="subject">Failed Message</field>
</record>
Expand All @@ -69,10 +75,13 @@
<field name="body"><![CDATA[<p>This is another failed message</p>]]></field>
<field name="email_from">[email protected]</field>
<field name="author_id" ref="base.res_partner_10" />
<field name="partner_ids" eval="[(6, 0, [ref('base.partner_demo')])]" />
<field
name="partner_ids"
eval="[Command.set([ref('base.partner_demo')])]"
/>
<field
name="notification_ids"
eval="[(0, 0, {'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
/>
<field name="subject">Failed Message</field>
</record>
Expand All @@ -97,10 +106,13 @@
<field name="body"><![CDATA[<p>This is another failed message</p>]]></field>
<field name="email_from">[email protected]</field>
<field name="author_id" ref="base.partner_admin" />
<field name="partner_ids" eval="[(6, 0, [ref('base.partner_demo')])]" />
<field
name="partner_ids"
eval="[Command.set([ref('base.partner_demo')])]"
/>
<field
name="notification_ids"
eval="[(0, 0, {'res_partner_id': ref('base.partner_demo')})]"
eval="[Command.create({'res_partner_id': ref('base.partner_demo')})]"
/>
<field name="subject">Failed Message</field>
</record>
Expand Down
5 changes: 0 additions & 5 deletions mail_tracking/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,9 @@ def _prepare_dict_failed_message(self):
return
failed_partners = failed_trackings.mapped("partner_id")
failed_recipients = failed_partners.name_get()
if self.author_id:
author = self.author_id.name_get()[0]
else:
author = (-1, _("-Unknown Author-"))
return {
"id": self.id,
"date": self.date,
"author": author,
"body": self.body,
"failed_recipients": failed_recipients,
}
Expand Down
10 changes: 3 additions & 7 deletions mail_tracking/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,13 @@ def _add_extra_recipients_suggestions(self, suggestions, field_mail, reason):
)

@api.model
def _fields_view_get(
self, view_id=None, view_type="form", toolbar=False, submenu=False
):
def get_view(self, view_id=None, view_type="form", **options):
"""Add filters for failed messages.
These filters will show up on any form or search views of any
These filters will show up on any search views of any
model inheriting from ``mail.thread``.
"""
res = super()._fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
)
res = super().get_view(view_id, view_type, **options)
if view_type != "search":
return res
doc = etree.XML(res["arch"])
Expand Down
2 changes: 1 addition & 1 deletion mail_tracking/models/mail_tracking_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MailTrackingEmail(models.Model):
time = fields.Datetime(readonly=True, index=True)
date = fields.Date(readonly=True, compute="_compute_date", store=True)
mail_message_id = fields.Many2one(
string="Message", comodel_name="mail.message", readonly=True, index=True
comodel_name="mail.message", readonly=True, index=True
)
message_id = fields.Char(compute="_compute_message_id")
mail_id = fields.Many2one(string="Email", comodel_name="mail.mail", readonly=True)
Expand Down
Loading

0 comments on commit c2faec5

Please sign in to comment.