diff --git a/mail_edit/README.rst b/mail_edit/README.rst new file mode 100644 index 0000000000..dfba6a1a4f --- /dev/null +++ b/mail_edit/README.rst @@ -0,0 +1,125 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============ +Message Edit +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5c752155d8002154d92f54efdbeb6a90644b35a4a94cdf383c1fef7931763e6f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/16.0/mail_edit + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_edit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of mail. You can edit message/mail +and move them to any model. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure this module: + +* Activate the 'Move mail message' or 'Edit mail message' permissions for a + user (the admin user has these rights by default) + +Usage +===== + +To use this module, you need to: + +* Go to *Message* *Chatter* in any model, click the Edit (pen) Icon to open up + the 'Edit or Move' wizard. +* To edit, edit the Mail as necessary and click Save. +* To move, select the destination object and click Save. +* To delete a message, click the trash icon, and do the confirmation. + +Known issues / Roadmap +====================== + +* Better live-updating of an edited message in the thread, right now only + 'body' parameter is updated. +* For the body parameter, call processBody to correctly handle emoji. +* Live-update edited message through all threads, using the message bus. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Sunflower IT + +Contributors +~~~~~~~~~~~~ + +* `Sunflower IT `_: + + * Dan Kiplangat + * Tom Blauwendraat + + +* `Therp BV `_: + + * George Daramouskas + * Holger Brunn + +Other credits +~~~~~~~~~~~~~ + +Images +------ + +* PICOL Icon Generator `here `__. + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_edit/__init__.py b/mail_edit/__init__.py new file mode 100644 index 0000000000..4582ed24d5 --- /dev/null +++ b/mail_edit/__init__.py @@ -0,0 +1,4 @@ +# © 2016 Sunflower IT (http://sunflowerweb.nl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mail_edit/__manifest__.py b/mail_edit/__manifest__.py new file mode 100644 index 0000000000..e5e68e0f6c --- /dev/null +++ b/mail_edit/__manifest__.py @@ -0,0 +1,36 @@ +# © 2016-24 Sunflower IT (http://sunflowerweb.nl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Message Edit", + "summary": "Edit, Delete or Move messages to any model", + "version": "16.0.1.0.0", + "category": "Social Network", + "website": "https://github.com/OCA/social", + "author": "Sunflower IT, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mail", + "web", + "web_tour", + "contacts", + ], + "data": [ + "security/mail_edit_security.xml", + "views/compose_message.xml", + ], + "demo": ["demo/data.xml"], + "assets": { + "mail.assets_messaging": [ + "mail_edit/static/src/components/message/mail_edit.esm.js", + ], + "web.assets_tests": [ + "mail_edit/static/src/tests/tours/*.esm.js", + ], + "web.qunit_suite_tests": [ + "mail_edit/static/src/tests/qunit_suite_tests/*.esm.js", + ], + }, +} diff --git a/mail_edit/demo/data.xml b/mail_edit/demo/data.xml new file mode 100644 index 0000000000..e6de613ed0 --- /dev/null +++ b/mail_edit/demo/data.xml @@ -0,0 +1,9 @@ + + + + + + diff --git a/mail_edit/i18n/mail_edit.pot b/mail_edit/i18n/mail_edit.pot new file mode 100644 index 0000000000..1545b5f83b --- /dev/null +++ b/mail_edit/i18n/mail_edit.pot @@ -0,0 +1,123 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_edit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-23 11:52+0000\n" +"PO-Revision-Date: 2026-04-23 11:52+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Change 'Destination Object' in the wizard, then save." +msgstr "" + +#. module: mail_edit +#: model:ir.model.fields,field_description:mail_edit.field_mail_mail__destination_object_id +#: model:ir.model.fields,field_description:mail_edit.field_mail_message__destination_object_id +msgid "Destination object" +msgstr "" + +#. module: mail_edit +#: model_terms:ir.ui.view,arch_db:mail_edit.mail_edit_form +msgid "Discard" +msgstr "" + +#. module: mail_edit +#: model:ir.actions.act_window,name:mail_edit.mail_edit_action +msgid "Edit or Move Message" +msgstr "" + +#. module: mail_edit +#: model:res.groups,name:mail_edit.group_mail_edit_superuser +msgid "Edit or Move anyone's mail messages" +msgstr "" + +#. module: mail_edit +#: model:res.groups,name:mail_edit.group_mail_edit_editor +msgid "Edit own mail messages" +msgstr "" + +#. module: mail_edit +#: model:res.groups,comment:mail_edit.group_mail_edit_editor +msgid "Members of this group are able to edit mail messages." +msgstr "" + +#. module: mail_edit +#: model:res.groups,comment:mail_edit.group_mail_edit_mover +msgid "Members of this group are able to move mails." +msgstr "" + +#. module: mail_edit +#: model:res.groups,comment:mail_edit.group_mail_edit_superuser +msgid "Members of this group are able to move or edit mails" +msgstr "" + +#. module: mail_edit +#: model:ir.model,name:mail_edit.model_mail_message +#: model_terms:ir.ui.view,arch_db:mail_edit.mail_edit_form +msgid "Message" +msgstr "" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message edited" +msgstr "" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message edited successfully." +msgstr "" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message moved" +msgstr "" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message moved successfully, refresh to see changes." +msgstr "" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#: code:addons/mail_edit/static/src/tests/qunit_suite_tests/mail_edit_tests.esm.js:0 +#, python-format +msgid "Move message" +msgstr "" + +#. module: mail_edit +#: model:res.groups,name:mail_edit.group_mail_edit_mover +msgid "Move own mail messages" +msgstr "" + +#. module: mail_edit +#: model:ir.model.fields,help:mail_edit.field_mail_mail__destination_object_id +#: model:ir.model.fields,help:mail_edit.field_mail_message__destination_object_id +msgid "Object where the message will be moved to" +msgstr "" + +#. module: mail_edit +#: model_terms:ir.ui.view,arch_db:mail_edit.mail_edit_form +msgid "Save" +msgstr "" diff --git a/mail_edit/i18n/nl.po b/mail_edit/i18n/nl.po new file mode 100644 index 0000000000..01e565270a --- /dev/null +++ b/mail_edit/i18n/nl.po @@ -0,0 +1,126 @@ +# Translation of Mail edit module. +# This file contains the translation of the following modules: +# * mail_edit +# +# Translators: +# Tom Blauwendraat , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-04-23 11:52+0000\n" +"PO-Revision-Date: 2017-08-18 16:51+0000\n" +"Last-Translator: Erwin van der Ploeg \n" +"Language-Team: Dutch (http://www.transifex.com/odoo/odoo-8/language/nl/)\n" +"Language: nl\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Change 'Destination Object' in the wizard, then save." +msgstr "Verander 'Doel Object' in de assistent, sla daarna op." + +#. module: mail_edit +#: model:ir.model.fields,field_description:mail_edit.field_mail_mail__destination_object_id +#: model:ir.model.fields,field_description:mail_edit.field_mail_message__destination_object_id +msgid "Destination object" +msgstr "Doelobject" + +#. module: mail_edit +#: model_terms:ir.ui.view,arch_db:mail_edit.mail_edit_form +msgid "Discard" +msgstr "Negeer wijzigingen" + +#. module: mail_edit +#: model:ir.actions.act_window,name:mail_edit.mail_edit_action +msgid "Edit or Move Message" +msgstr "Wijzigen of verplaatsen van bericht" + +#. module: mail_edit +#: model:res.groups,name:mail_edit.group_mail_edit_superuser +msgid "Edit or Move anyone's mail messages" +msgstr "Wijzig of verplaats bericht van anderen" + +#. module: mail_edit +#: model:res.groups,name:mail_edit.group_mail_edit_editor +#, python-format +msgid "Edit own mail messages" +msgstr "Eigen berichten wijzigen" + +#. module: mail_edit +#: model:res.groups,comment:mail_edit.group_mail_edit_editor +#, python-format +msgid "Members of this group are able to edit mail messages." +msgstr "Leden van deze groep mogen de inhoud van berichten wijzigen." + +#. module: mail_edit +#: model:res.groups,comment:mail_edit.group_mail_edit_mover +msgid "Members of this group are able to move mails." +msgstr "Leden van deze groep mogen berichten verplaatsen." + +#. module: mail_edit +#: model:res.groups,comment:mail_edit.group_mail_edit_superuser +msgid "Members of this group are able to move or edit mails" +msgstr "Leden van deze groep mogen berichten verplaatsen of bewerken." + +#. module: mail_edit +#: model:ir.model,name:mail_edit.model_mail_message +#: model_terms:ir.ui.view,arch_db:mail_edit.mail_edit_form +msgid "Message" +msgstr "Bericht" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message edited" +msgstr "Bericht gewijzigd" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message edited successfully." +msgstr "Bericht met succes gewijzigd." + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +msgid "Message moved" +msgstr "Bericht verplaatst" + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#, python-format +msgid "Message moved successfully, refresh to see changes." +msgstr "Bericht met succes verplaatst, ververs om veranderingen te zien." + +#. module: mail_edit +#. odoo-javascript +#: code:addons/mail_edit/static/src/components/message/mail_edit.esm.js:0 +#: code:addons/mail_edit/static/src/tests/qunit_suite_tests/mail_edit_tests.esm.js:0 +#, python-format +msgid "Move message" +msgstr "Verplaats bericht" + +#. module: mail_edit +#: model:res.groups,name:mail_edit.group_mail_edit_mover +msgid "Move own mail messages" +msgstr "Eigen berichten verplaatsen" + +#. module: mail_edit +#: model:ir.model.fields,help:mail_edit.field_mail_mail__destination_object_id +#: model:ir.model.fields,help:mail_edit.field_mail_message__destination_object_id +msgid "Object where the message will be moved to" +msgstr "Object waar het bericht naartoe verplaatst zal worden" + +#. module: mail_edit +#: model_terms:ir.ui.view,arch_db:mail_edit.mail_edit_form +msgid "Save" +msgstr "Opslaan" diff --git a/mail_edit/models/__init__.py b/mail_edit/models/__init__.py new file mode 100644 index 0000000000..6f66d745f2 --- /dev/null +++ b/mail_edit/models/__init__.py @@ -0,0 +1,4 @@ +# © 2016 Sunflower IT (http://sunflowerweb.nl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import compose_message diff --git a/mail_edit/models/compose_message.py b/mail_edit/models/compose_message.py new file mode 100644 index 0000000000..0a144af04c --- /dev/null +++ b/mail_edit/models/compose_message.py @@ -0,0 +1,61 @@ +# © 2016 Sunflower IT (http://sunflowerweb.nl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class MailMessage(models.Model): + _inherit = "mail.message" + + @api.model + def _get_model_selection(self): + # Get models that supports messages, exclude transient models + models = self.env["ir.model"].search( + [("is_mail_thread", "=", True), ("transient", "=", False)] + ) + return [(m.model, m.name) for m in models] + + @api.onchange("destination_object_id") + def change_destination_object(self): + """Update some fields for the new message.""" + # pylint: disable=api-one-deprecated + if self.destination_object_id: + self.model = self.destination_object_id._name + self.res_id = self.destination_object_id.id + + model_name = self.env["ir.model"].search([("model", "=", self.model)]).name + display_name = self.destination_object_id.display_name + if model_name: + display_name = "%s %s" % (model_name, display_name) + + self.record_name = display_name + else: + self.model = self.res_id = self.record_name = False + + destination_object_id = fields.Reference( + _get_model_selection, + "Destination object", + help="Object where the message will be moved to", + ) + + @api.model + def _message_read_dict_postprocess(self, messages, message_tree): + parent = super() + if hasattr(parent, "_message_read_dict_postprocess"): + res = parent._message_read_dict_postprocess(messages, message_tree) + else: + res = messages + + is_superuser = self.env.user.has_group("mail_edit.group_mail_edit_superuser") + user_partner = self.env.user.partner_id + + for message_dict in messages: + if is_superuser: + message_dict["is_superuser"] = True + + author_id = message_dict.get("author_id") + message_dict["is_author"] = ( + bool(author_id) and user_partner.id == author_id[0] + ) + + return res diff --git a/mail_edit/readme/CONFIGURE.rst b/mail_edit/readme/CONFIGURE.rst new file mode 100644 index 0000000000..a664e0516f --- /dev/null +++ b/mail_edit/readme/CONFIGURE.rst @@ -0,0 +1,4 @@ +To configure this module: + +* Activate the 'Move mail message' or 'Edit mail message' permissions for a + user (the admin user has these rights by default) diff --git a/mail_edit/readme/CONTRIBUTORS.rst b/mail_edit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..ea8186a993 --- /dev/null +++ b/mail_edit/readme/CONTRIBUTORS.rst @@ -0,0 +1,10 @@ +* `Sunflower IT `_: + + * Dan Kiplangat + * Tom Blauwendraat + + +* `Therp BV `_: + + * George Daramouskas + * Holger Brunn diff --git a/mail_edit/readme/CREDITS.rst b/mail_edit/readme/CREDITS.rst new file mode 100644 index 0000000000..c8674a675b --- /dev/null +++ b/mail_edit/readme/CREDITS.rst @@ -0,0 +1,4 @@ +Images +------ + +* PICOL Icon Generator `here `__. diff --git a/mail_edit/readme/DESCRIPTION.rst b/mail_edit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..e2e89d74cf --- /dev/null +++ b/mail_edit/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of mail. You can edit message/mail +and move them to any model. diff --git a/mail_edit/readme/ROADMAP.rst b/mail_edit/readme/ROADMAP.rst new file mode 100644 index 0000000000..e6728ef41e --- /dev/null +++ b/mail_edit/readme/ROADMAP.rst @@ -0,0 +1,4 @@ +* Better live-updating of an edited message in the thread, right now only + 'body' parameter is updated. +* For the body parameter, call processBody to correctly handle emoji. +* Live-update edited message through all threads, using the message bus. diff --git a/mail_edit/readme/USAGE.rst b/mail_edit/readme/USAGE.rst new file mode 100644 index 0000000000..51f140d0ac --- /dev/null +++ b/mail_edit/readme/USAGE.rst @@ -0,0 +1,7 @@ +To use this module, you need to: + +* Go to *Message* *Chatter* in any model, click the Edit (pen) Icon to open up + the 'Edit or Move' wizard. +* To edit, edit the Mail as necessary and click Save. +* To move, select the destination object and click Save. +* To delete a message, click the trash icon, and do the confirmation. diff --git a/mail_edit/security/mail_edit_security.xml b/mail_edit/security/mail_edit_security.xml new file mode 100644 index 0000000000..7d2fb43aad --- /dev/null +++ b/mail_edit/security/mail_edit_security.xml @@ -0,0 +1,27 @@ + + + + Edit own mail messages + Members of this group are able to edit mail messages. + + + + + + Move own mail messages + Members of this group are able to move mails. + + + + + + Edit or Move anyone's mail messages + Members of this group are able to move or edit mails + + + + diff --git a/mail_edit/static/description/icon.png b/mail_edit/static/description/icon.png new file mode 100644 index 0000000000..b0ff417aad Binary files /dev/null and b/mail_edit/static/description/icon.png differ diff --git a/mail_edit/static/description/index.html b/mail_edit/static/description/index.html new file mode 100644 index 0000000000..d848dc44e8 --- /dev/null +++ b/mail_edit/static/description/index.html @@ -0,0 +1,489 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Message Edit

+ +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

This module extends the functionality of mail. You can edit message/mail +and move them to any model.

+

Table of contents

+ +
+

Configuration

+

To configure this module:

+
    +
  • Activate the ‘Move mail message’ or ‘Edit mail message’ permissions for a +user (the admin user has these rights by default)
  • +
+
+
+

Usage

+

To use this module, you need to:

+
    +
  • Go to Message Chatter in any model, click the Edit (pen) Icon to open up +the ‘Edit or Move’ wizard.
  • +
  • To edit, edit the Mail as necessary and click Save.
  • +
  • To move, select the destination object and click Save.
  • +
  • To delete a message, click the trash icon, and do the confirmation.
  • +
+
+
+

Known issues / Roadmap

+
    +
  • Better live-updating of an edited message in the thread, right now only +‘body’ parameter is updated.
  • +
  • For the body parameter, call processBody to correctly handle emoji.
  • +
  • Live-update edited message through all threads, using the message bus.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Sunflower IT
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+
+

Images

+
    +
  • PICOL Icon Generator here.
  • +
+
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/mail_edit/static/src/components/message/mail_edit.esm.js b/mail_edit/static/src/components/message/mail_edit.esm.js new file mode 100644 index 0000000000..a085e8a4bd --- /dev/null +++ b/mail_edit/static/src/components/message/mail_edit.esm.js @@ -0,0 +1,188 @@ +/** @odoo-module **/ + +/* Copyright 2023 Therp BV + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ + +import {registerPatch} from "@mail/model/model_core"; +import {one} from "@mail/model/model_field"; +import {clear} from "@mail/model/model_field_command"; + +registerPatch({ + name: "MessageAction", + fields: { + messageActionListOwnerAsMove: one("MessageActionList", { + identifying: true, + inverse: "actionMove", + }), + + sequence: { + compute() { + if (this.messageActionListOwnerAsMove) { + return 9; + } + return this._super(); + }, + }, + + messageActionListOwner: { + compute() { + if (this.messageActionListOwnerAsMove) { + return this.messageActionListOwnerAsMove; + } + return this._super(); + }, + }, + }, +}); + +registerPatch({ + name: "MessageActionList", + fields: { + actionMove: one("MessageAction", { + compute() { + const message = this.message; + const canMoveMessage = + message && + message.id && + ["comment", "email"].includes(message.message_type); + + if (this.actionEdit || canMoveMessage) { + return {}; + } + return clear(); + }, + inverse: "messageActionListOwnerAsMove", + }), + }, +}); + +registerPatch({ + name: "MessageActionView", + recordMethods: { + async _openMailEditWizard(message, isMove) { + const action = await this.env.services.rpc("/web/action/load", { + action_id: "mail_edit.mail_edit_action", + }); + + action.res_id = message.id; + + await this.env.services.action.doAction(action, { + onClose: async () => { + await this._onMailEditWizardClose(message, isMove); + }, + }); + }, + + async _onMailEditWizardClose(message, isMove) { + const data = await this.env.services.orm.call( + "mail.message", + "message_format", + [[message.id]], + {}, + {shadow: true} + ); + + if (!data || !data.length) { + message.delete(); + return; + } + + const MessageModel = + this.messaging.models["mail.message"] || this.messaging.models.Message; + + message.update(MessageModel.convertData(data[0])); + + this.env.services.notification.add(this._getSuccessMessage(isMove), { + title: this._getSuccessTitle(isMove), + type: "success", + sticky: true, + }); + }, + + _getSuccessMessage(isMove) { + if (isMove) { + return this.env._t( + "Message moved successfully, refresh to see changes." + ); + } + return this.env._t("Message edited successfully."); + }, + + _getSuccessTitle(isMove) { + if (isMove) { + return this.env._t("Message moved"); + } + return this.env._t("Message edited"); + }, + + async _reloadCurrentAction() { + await this.env.services.action.doAction({ + type: "ir.actions.client", + tag: "reload", + }); + }, + + async onClick(ev) { + if (this.messageAction.messageActionListOwnerAsEdit) { + ev.stopPropagation(); + + await this._openMailEditWizard( + this.messageAction.messageActionListOwner.message, + false + ); + return; + } + + if (this.messageAction.messageActionListOwnerAsMove) { + ev.stopPropagation(); + this._notifyMoveHelp(); + + await this._openMailEditWizard( + this.messageAction.messageActionListOwner.message, + true + ); + return; + } + + return this._super(...arguments); + }, + + _notifyMoveHelp() { + this.env.services.notification.add( + this.env._t("Change 'Destination Object' in the wizard, then save."), + { + title: this.env._t("Move message"), + type: "info", + sticky: true, + } + ); + }, + }, + + fields: { + title: { + compute() { + if (this.messageAction.messageActionListOwnerAsMove) { + return this.env._t("Move message"); + } + return this._super(); + }, + }, + + classNames: { + compute() { + if (this.messageAction.messageActionListOwnerAsMove) { + return [ + this.paddingClassNames, + "fa", + "fa-lg", + "fa-hand-o-right", + "o_MessageActionView_actionMove", + ].join(" "); + } + return this._super(); + }, + }, + }, +}); diff --git a/mail_edit/static/src/tests/qunit_suite_tests/mail_edit_tests.esm.js b/mail_edit/static/src/tests/qunit_suite_tests/mail_edit_tests.esm.js new file mode 100644 index 0000000000..f30e3ed030 --- /dev/null +++ b/mail_edit/static/src/tests/qunit_suite_tests/mail_edit_tests.esm.js @@ -0,0 +1,92 @@ +/** @odoo-module **/ + +/* global QUnit */ + +import {patchWithCleanup} from "@web/../tests/helpers/utils"; +import {click, contains} from "@web/../tests/utils"; +import {start, startServer} from "@mail/../tests/helpers/test_utils"; + +QUnit.module("mail_edit", {}, function () { + QUnit.module("MessageActionView"); + + QUnit.test("move action opens edit wizard", async function (assert) { + const pyEnv = await startServer(); + const partnerId = pyEnv["res.partner"].create({ + name: "Mail Edit Test Partner", + }); + + const messageId = pyEnv["mail.message"].create({ + body: "

Message to move

", + model: "res.partner", + res_id: partnerId, + message_type: "email", + record_name: "Mail Edit Test Partner", + }); + + const {env, openView} = await start(); + + patchWithCleanup(env.services, { + async rpc(route, params) { + if (route === "/web/action/load") { + assert.strictEqual( + params.action_id, + "mail_edit.mail_edit_action", + "loads the mail edit action" + ); + return { + type: "ir.actions.act_window", + res_model: "mail.message", + res_id: false, + views: [[false, "form"]], + target: "new", + }; + } + return this._super(...arguments); + }, + }); + + patchWithCleanup(env.services.notification, { + add(message, options) { + assert.strictEqual( + options.title, + env._t("Move message"), + "shows the move helper notification" + ); + assert.strictEqual( + options.type, + "info", + "move helper notification is informational" + ); + return this._super(...arguments); + }, + }); + + patchWithCleanup(env.services.action, { + async doAction(action) { + if (action.res_model !== "mail.message") { + return this._super(...arguments); + } + + assert.strictEqual( + action.res_id, + messageId, + "opens the wizard on the clicked message" + ); + assert.strictEqual( + action.res_model, + "mail.message", + "opens the mail.message wizard" + ); + }, + }); + + await openView({ + res_model: "res.partner", + res_id: partnerId, + views: [[false, "form"]], + }); + + await contains(".o_Message"); + await click(".o_MessageActionView_actionMove"); + }); +}); diff --git a/mail_edit/static/src/tests/tours/mail_edit_tour.esm.js b/mail_edit/static/src/tests/tours/mail_edit_tour.esm.js new file mode 100644 index 0000000000..5f0e545033 --- /dev/null +++ b/mail_edit/static/src/tests/tours/mail_edit_tour.esm.js @@ -0,0 +1,39 @@ +/** @odoo-module **/ + +import tour from "web_tour.tour"; + +tour.register( + "mail_edit_move_message_tour", + { + test: true, + }, + [ + { + trigger: ".o_web_client", + content: "Wait for the web client.", + }, + { + trigger: ".o_action_manager", + content: "Wait for the action manager.", + }, + { + trigger: ".o_Message", + content: "Hover the chatter message.", + run: function (actions) { + actions.auto(".o_Message"); + }, + }, + { + trigger: ".o_MessageActionView_actionMove", + content: "Click the move message button.", + }, + { + trigger: ".o_notification", + content: "Move helper notification is shown.", + }, + { + trigger: ".modal-dialog", + content: "Mail edit wizard is opened.", + }, + ] +); diff --git a/mail_edit/tests/__init__.py b/mail_edit/tests/__init__.py new file mode 100644 index 0000000000..d62e75db81 --- /dev/null +++ b/mail_edit/tests/__init__.py @@ -0,0 +1,5 @@ +# © 2016 Sunflower IT (http://sunflowerweb.nl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_ui +from . import test_mail_edit diff --git a/mail_edit/tests/test_mail_edit.py b/mail_edit/tests/test_mail_edit.py new file mode 100644 index 0000000000..559cb41a62 --- /dev/null +++ b/mail_edit/tests/test_mail_edit.py @@ -0,0 +1,82 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestMailMessage(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create( + { + "name": "Mail Edit Destination Partner", + } + ) + cls.message = cls.env["mail.message"].create( + { + "body": "

Message body

", + "model": "res.partner", + "res_id": cls.partner.id, + "message_type": "comment", + "author_id": cls.env.user.partner_id.id, + "record_name": cls.partner.display_name, + } + ) + + def test_get_model_selection_contains_partner(self): + selection = dict(self.env["mail.message"]._get_model_selection()) + self.assertIn("res.partner", selection) + + def test_change_destination_object_sets_message_values(self): + message = self.env["mail.message"].create( + { + "body": "

Message to move

", + "message_type": "comment", + } + ) + + message.destination_object_id = self.partner + message.change_destination_object() + + self.assertEqual(message.model, "res.partner") + self.assertEqual(message.res_id, self.partner.id) + self.assertIn(self.partner.display_name, message.record_name) + + def test_change_destination_object_clears_message_values(self): + self.message.destination_object_id = False + self.message.change_destination_object() + + self.assertFalse(self.message.model) + self.assertFalse(self.message.res_id) + self.assertFalse(self.message.record_name) + + def test_message_read_dict_postprocess_adds_author_flag(self): + message_dict = { + "author_id": [self.env.user.partner_id.id, self.env.user.name], + } + messages = [message_dict] + + result = self.env["mail.message"]._message_read_dict_postprocess( + messages, + {}, + ) + + self.assertEqual(result, messages) + self.assertTrue(message_dict["is_author"]) + + def test_message_read_dict_postprocess_adds_superuser_flag(self): + group = self.env.ref("mail_edit.group_mail_edit_superuser") + self.env.user.write({"groups_id": [(4, group.id)]}) + + message_dict = { + "author_id": [self.env.user.partner_id.id, self.env.user.name], + } + messages = [message_dict] + + self.env["mail.message"]._message_read_dict_postprocess( + messages, + {}, + ) + + self.assertTrue(message_dict["is_superuser"]) + self.assertTrue(message_dict["is_author"]) diff --git a/mail_edit/tests/test_ui.py b/mail_edit/tests/test_ui.py new file mode 100644 index 0000000000..1585697b3e --- /dev/null +++ b/mail_edit/tests/test_ui.py @@ -0,0 +1,41 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl) + +from odoo.tests import HttpCase, tagged + + +@tagged("post_install", "-at_install") +class TestMailEditTour(HttpCase): + def setUp(self): + super().setUp() + + self.partner = self.env["res.partner"].create( + { + "name": "Mail Edit Tour Partner", + } + ) + + self.partner.message_post( + body="

Message to move

", + message_type="email", + subtype_xmlid="mail.mt_comment", + ) + + self.partner_action = self.env["ir.actions.act_window"].create( + { + "name": "Mail Edit Partner Test", + "res_model": "res.partner", + "view_mode": "form", + "target": "current", + } + ) + + def test_mail_edit_move_message_tour(self): + url = "/web#action=%s&id=%s&model=res.partner&view_type=form" % ( + self.partner_action.id, + self.partner.id, + ) + self.start_tour( + url, + "mail_edit_move_message_tour", + login="admin", + ) diff --git a/mail_edit/views/compose_message.xml b/mail_edit/views/compose_message.xml new file mode 100644 index 0000000000..fc1ee58fd6 --- /dev/null +++ b/mail_edit/views/compose_message.xml @@ -0,0 +1,53 @@ + + + + + Edit Email Form + mail.message + 50 + +
+ + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + Edit or Move Message + mail.message + ir.actions.act_window + + form + new + + +
diff --git a/setup/mail_edit/odoo/addons/mail_edit b/setup/mail_edit/odoo/addons/mail_edit new file mode 120000 index 0000000000..90464b1db3 --- /dev/null +++ b/setup/mail_edit/odoo/addons/mail_edit @@ -0,0 +1 @@ +../../../../mail_edit \ No newline at end of file diff --git a/setup/mail_edit/setup.py b/setup/mail_edit/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mail_edit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)