From 3fe33487e1b43c95c65e148500f30769e4fcc762 Mon Sep 17 00:00:00 2001 From: Ipsita Borisagar Date: Mon, 23 May 2022 10:38:36 +0000 Subject: [PATCH] [FIX] im_livechat: disable attachment upload via drag and drop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit: Attachments are not properly supported in livechat, so there is no point in allowing attachments to be uploaded via drag and drop. After this commit: Disable attachment upload via drag and drop in livechat channels. Task-2824502 closes odoo/odoo#95761 X-original-commit: 1aed05eb1c50ee69b974a140b3080e38c802cb2f Signed-off-by: Sébastien Theys (seb) --- .../static/src/models/composer_view.js | 17 +++++++++++++++++ .../components/composer_tests.js | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 addons/im_livechat/static/src/models/composer_view.js diff --git a/addons/im_livechat/static/src/models/composer_view.js b/addons/im_livechat/static/src/models/composer_view.js new file mode 100644 index 00000000000..7e5759625ca --- /dev/null +++ b/addons/im_livechat/static/src/models/composer_view.js @@ -0,0 +1,17 @@ +/** @odoo-module **/ + +import { patchRecordMethods } from '@mail/model/model_core'; +import { clear } from '@mail/model/model_field_command'; +import '@mail/models/composer_view'; + +patchRecordMethods('ComposerView', { + /** + * @override + */ + _computeDropZoneView() { + if (this.composer.thread && this.composer.thread.channel_type === 'livechat') { + return clear(); + } + return this._super(); + }, +}); diff --git a/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js b/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js index 596fc7e64e4..39004005cb1 100644 --- a/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js +++ b/addons/im_livechat/static/tests/qunit_suite_tests/components/composer_tests.js @@ -26,5 +26,23 @@ QUnit.test('livechat: no add attachment button', async function (assert) { ); }); +QUnit.test('livechat: disable attachment upload via drag and drop', async function (assert) { + assert.expect(2); + + const { createComposerComponent, messaging } = await start(); + const thread = messaging.models['Thread'].create({ + channel_type: 'livechat', + id: 10, + model: 'mail.channel', + }); + await createComposerComponent(thread.composer); + assert.containsOnce(document.body, '.o_Composer', "should have a composer"); + assert.containsNone( + document.body, + '.o_Composer_dropZone', + "composer linked to livechat should not have a dropzone" + ); +}); + }); });