From e7aff236b8073b952a0e554d9897a8f88d5c4c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Wed, 4 Sep 2019 07:46:45 +0000 Subject: [PATCH] [FIX] mail: no message attachment delete in discuss and chat window Delete attachment from message makes only sense from chatter. Task-Id 2058455 --- addons/mail/static/src/js/thread_field.js | 1 + addons/mail/static/src/js/thread_widget.js | 2 + addons/mail/static/src/xml/thread.xml | 17 ++++-- addons/mail/static/tests/discuss_tests.js | 47 ++++++++++++++++ .../basic_thread_window_tests.js | 53 +++++++++++++++++++ 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/addons/mail/static/src/js/thread_field.js b/addons/mail/static/src/js/thread_field.js index ab8023b06ad..ea64d1fc9e3 100644 --- a/addons/mail/static/src/js/thread_field.js +++ b/addons/mail/static/src/js/thread_field.js @@ -43,6 +43,7 @@ var ThreadField = AbstractField.extend({ displayOrder: ThreadWidget.ORDER.DESC, displayDocumentLinks: false, displayMarkAsRead: false, + hasMessageAttachmentDeletable: true, squashCloseMessages: false, }); diff --git a/addons/mail/static/src/js/thread_widget.js b/addons/mail/static/src/js/thread_widget.js index e5902602a77..9550931ad95 100644 --- a/addons/mail/static/src/js/thread_widget.js +++ b/addons/mail/static/src/js/thread_widget.js @@ -68,6 +68,7 @@ var ThreadWidget = Widget.extend({ displayEmailIcons: true, displayReplyIcons: false, loadMoreOnScroll: false, + hasMessageAttachmentDeletable: false, }); // options when the thread is disabled this._disabledOptions = { @@ -81,6 +82,7 @@ var ThreadWidget = Widget.extend({ displayEmailIcons: false, displayReplyIcons: false, loadMoreOnScroll: this._enabledOptions.loadMoreOnScroll, + hasMessageAttachmentDeletable: false, }; this._selectedMessageID = null; this._currentThreadID = null; diff --git a/addons/mail/static/src/xml/thread.xml b/addons/mail/static/src/xml/thread.xml index ef21b2c5ede..12d41ebd431 100644 --- a/addons/mail/static/src/xml/thread.xml +++ b/addons/mail/static/src/xml/thread.xml @@ -254,6 +254,7 @@ @param {boolean} [options.displayReplyIcons] @param {boolean} [options.displayStars] @param {boolean} [options.displaySubjectsOnMessages] + @param {boolean} options.hasMessageAttachmentDeletable @param {string|integer} [options.messagesSeparatorPosition] 'top' or message ID, the separator is placed just after this message. @param {integer} [options.selectedMessageID] @@ -354,12 +355,16 @@
- + + +
- + + +
@@ -526,6 +531,7 @@ @param {integer} attachment.id @param {string} attachment.name @param {string} attachment.url + @param {boolean} [isDeletable=false] -->
@@ -533,7 +539,7 @@
- + @@ -552,12 +558,15 @@ @param {string} attachment.name @param {boolean} attachment.upload @param {string} attachment.url + @param {boolean} [editable=false] if set, it means the attachment is rendered in the composer. + Some changes are required in that case, such as "delete" button is not visible (pretty unlink is used instead). + @param {boolean} [isDeletable=false] -->
- + diff --git a/addons/mail/static/tests/discuss_tests.js b/addons/mail/static/tests/discuss_tests.js index 9949af7c28c..990f321a39d 100644 --- a/addons/mail/static/tests/discuss_tests.js +++ b/addons/mail/static/tests/discuss_tests.js @@ -1119,6 +1119,53 @@ QUnit.test('drag and drop file in composer [REQUIRE NON-INCOGNITO WINDOW]', asyn discuss.destroy(); }); +QUnit.test('non-deletable message attachments', async function (assert) { + assert.expect(2); + + this.data['mail.message'].records = [{ + attachment_ids: [{ + filename: "text.txt", + id: 250, + mimetype: 'text/plain', + name: "text.txt", + }, { + filename: "image.png", + id: 251, + mimetype: 'image/png', + name: "image.png", + }], + author_id: [5, "Demo User"], + body: "

test

", + id: 1, + needaction: true, + needaction_partner_ids: [3], + model: 'some.document', + record_name: "SomeDocument", + res_id: 100, + }]; + + const discuss = await createDiscuss({ + context: {}, + data: this.data, + params: {}, + services: this.services, + session: { + partner_id: 3, + }, + }); + assert.containsN( + discuss, + '.o_attachment', + 2, + "should display 2 attachments"); + assert.containsNone( + discuss.$('.o_attachment'), + 'o_attachment_delete_cross', + "attachments should not be deletable"); + + discuss.destroy(); +}); + QUnit.test('reply to message from inbox', async function (assert) { assert.expect(11); diff --git a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js index 3200ae38d85..3dc8ac0336d 100644 --- a/addons/mail/static/tests/thread_window/basic_thread_window_tests.js +++ b/addons/mail/static/tests/thread_window/basic_thread_window_tests.js @@ -850,6 +850,59 @@ QUnit.test('receive 2 new DM messages in quick succession (no chat window initia parent.destroy(); }); +QUnit.test('non-deletable message attachments', async function (assert) { + assert.expect(3); + + this.data['mail.channel'].records = [{ + id: 1, + name: "General", + channel_type: 'channel', + }]; + this.data['mail.message'].records = [{ + attachment_ids: [{ + filename: "text.txt", + id: 250, + mimetype: 'text/plain', + name: "text.txt", + }, { + filename: "image.png", + id: 251, + mimetype: 'image/png', + name: "image.png", + }], + author_id: [5, "Demo User"], + body: "

test

", + channel_ids: [1], + id: 100, + model: 'mail.channel', + record_name: "general", + res_id: 1, + }]; + const parent = this.createParent({ + data: this.data, + services: this.services, + }); + await testUtils.nextTick(); + const channel = parent.call('mail_service', 'getChannel', 1); + channel.detach(); + await testUtils.nextTick(); + assert.containsOnce( + $, + '.o_thread_window', + "a thread window should be open"); + assert.containsN( + $('.o_thread_window'), + '.o_attachment', + 2, + "thread window should have 2 attachments"); + assert.containsNone( + $('.o_thread_window .o_attachment'), + 'o_attachment_delete_cross', + "attachments should not be deletable"); + + parent.destroy(); +}); + }); }); });