Skip to content

Commit

Permalink
[MIG] mail_drop_target: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminSForgeFlow authored and LoisRForgeFlow committed Sep 21, 2023
1 parent ea01a04 commit d31eceb
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 121 deletions.
15 changes: 12 additions & 3 deletions mail_drop_target/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Drag & drop emails to Odoo",
"version": "14.0.1.0.1",
"version": "15.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Discuss",
"website": "https://github.com/OCA/social",
"summary": "Attach emails to Odoo by dragging them from your desktop",
"depends": ["mail", "web_drop_target"],
"depends": ["mail"],
"external_dependencies": {"python": ["extract_msg"]},
"data": ["views/templates.xml", "views/res_config_settings_views.xml"],
"data": ["views/res_config_settings_views.xml"],
"assets": {
"web.assets_backend": [
"mail_drop_target/static/src/js/mail_drop_target.esm.js",
"mail_drop_target/static/src/css/mail_drop_target.css",
],
"web.assets_qweb": [
"mail_drop_target/static/src/xml/*.xml",
],
},
}
2 changes: 1 addition & 1 deletion mail_drop_target/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def message_drop_existing(
thread_id=None,
):
message = _("This message is already imported.")
raise exceptions.Warning(message)
raise exceptions.UserError(message)

@api.model
def message_process_msg(
Expand Down
58 changes: 58 additions & 0 deletions mail_drop_target/static/src/js/mail_drop_target.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @odoo-module **/
/* global base64js:false, Uint8Array:false */
// Copyright 2018 Therp BV <https://therp.nl>
// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import {MessageList} from "@mail/components/message_list/message_list";
import {patch} from "web.utils";
import {useDragVisibleDropZone} from "@mail/component_hooks/use_drag_visible_dropzone/use_drag_visible_dropzone";

patch(MessageList.prototype, "mail_drop_target.mail_drop", {
setup() {
this._super();
this.isDropZoneVisible = useDragVisibleDropZone();
},
async _onDropZoneFilesDropped(ev) {
ev.stopPropagation();
this.isDropZoneVisible.value = false;
var self = this;
Promise.all(
Array.from(ev.detail.files).map((drop_file) => {
var reader = new FileReader();
var mail_processor = "";
if (drop_file.name.endsWith(".msg")) {
mail_processor = "message_process_msg";
} else {
mail_processor = "message_drop";
}
reader.readAsArrayBuffer(drop_file);
reader.onload = function (event) {
var data = "";
// TODO: read some config parameter if this should set
// some of the context keys to suppress mail.thread's behavior
if (mail_processor == "message_process_msg") {
data = base64js.fromByteArray(
new Uint8Array(event.target.result)
);
} else {
var reader_array = new Uint8Array(event.target.result);
data = "";
for (var i = 0; i < reader_array.length; i++) {
data += String.fromCharCode(parseInt(reader_array[i]));
}
}
self.env.services.rpc({
model: "mail.thread",
method: mail_processor,
args: [self.threadView.thread.model, data],
kwargs: {
thread_id: self.threadView.thread.id,
},
});
};
})
).then(function () {
return self.trigger("reload");
});
},
});
66 changes: 0 additions & 66 deletions mail_drop_target/static/src/js/mail_drop_target.js

This file was deleted.

16 changes: 16 additions & 0 deletions mail_drop_target/static/src/xml/chatter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">

<t t-inherit="mail.MessageList" t-inherit-mode="extension">
<xpath expr="//div[1]" position="inside">
<t t-if="isDropZoneVisible.value">
<DropZone
class="o_MailBox_dropZone"
t-on-o-dropzone-files-dropped="_onDropZoneFilesDropped"
t-ref="dropzone"
/>
</t>
</xpath>
</t>

</templates>
12 changes: 5 additions & 7 deletions mail_drop_target/tests/test_mail_drop_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from mock import patch

from odoo import exceptions, tools
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestMailDropTarget(SavepointCase):
class TestMailDropTarget(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -15,9 +15,7 @@ def setUpClass(cls):
cls.partner.message_subscribe(partner_ids=cls.partner.ids)

def test_eml(self):
message = tools.file_open(
"sample.eml", subdir="addons/mail_drop_target/tests"
).read()
message = tools.file_open("addons/mail_drop_target/tests/sample.eml").read()
comments = len(self.partner.message_ids)
self.partner.message_process(
self.partner._name, message, thread_id=self.partner.id
Expand All @@ -32,7 +30,7 @@ def test_eml(self):
def test_msg(self):
message = base64.b64encode(
tools.file_open(
"sample.msg", mode="rb", subdir="addons/mail_drop_target/tests"
"addons/mail_drop_target/tests/sample.msg", mode="rb"
).read()
)
comments = len(self.partner.message_ids)
Expand All @@ -57,7 +55,7 @@ def test_no_msgextract(self):
def test_msg_no_notification(self):
message = base64.b64encode(
tools.file_open(
"sample.msg", mode="rb", subdir="addons/mail_drop_target/tests"
"addons/mail_drop_target/tests/sample.msg", mode="rb"
).read()
)
settings = self.env["res.config.settings"].create({})
Expand Down
44 changes: 21 additions & 23 deletions mail_drop_target/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.mail</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="mail.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="emails" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="disable_notify_mail_drop_target" />
</div>
<div class="o_setting_right_pane">
<label
string="Disable Mail Drag&amp;Drop Notification"
for="disable_notify_mail_drop_target"
/>
<div class="text-muted">
When a user drops an email into an existing thread
the followers of the thread will not be notified.
</div>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.mail</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="mail.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="emails" position="inside">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="disable_notify_mail_drop_target" />
</div>
<div class="o_setting_right_pane">
<label
string="Disable Mail Drag&amp;Drop Notification"
for="disable_notify_mail_drop_target"
/>
<div class="text-muted">
When a user drops an email into an existing thread
the followers of the thread will not be notified.
</div>
</div>
</div>
</field>
</record>
</data>
</div>
</field>
</record>
</odoo>
21 changes: 0 additions & 21 deletions mail_drop_target/views/templates.xml

This file was deleted.

0 comments on commit d31eceb

Please sign in to comment.