From e5f673087b281f9d74cd1d4960d0d9115711b714 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Fri, 27 Sep 2019 14:48:39 +0000 Subject: [PATCH] [FIX] mail: Support nameless attachments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ir.attachment` records do not require to have a filename set. In `AttachmentBox`, a filename is always set, although in case it's missing it was untranslated. I fixed that. In cases where `AttachmentBox` is not used but its underlying templates are rendered using other means, a user could get a client-side error like this one when browsing a record that had an attachment without filename:
Error ``` Error: TypeError: dict.attachment.filename.split is not a function https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:26 Rastreo de error: anonymous@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:26:45 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:458:58 call@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:154:35 anonymous/<@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:340:33 foreach@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:180:25 anonymous@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:338:25 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:458:58 call@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:154:35 anonymous/<@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:27:31 foreach@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:180:25 anonymous@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:11:23 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:458:58 render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:450:26 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:480:29 call@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:154:35 anonymous@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:20:30 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:458:58 render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:450:26 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:480:29 call@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:154:35 anonymous@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:15:31 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:458:58 render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:450:26 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:480:29 call@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:154:35 anonymous@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js line 469 > Function:11:31 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:458:58 render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:450:26 _render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:480:29 render@https://www.tecnativa.com/web/static/lib/qweb/qweb2.js:450:26 render@https://www.tecnativa.com/mail/static/src/js/thread_widget.js:183:28 _fetchAndRenderThread/<@https://www.tecnativa.com/mail/static/src/js/thread_field.js:124:36 then/ This patch ensures all attachment has a filename, and fixes that problem. -- I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr @Tecnativa TT19555 closes odoo/odoo#37546 Forward-port-of: odoo/odoo#37253 X-original-commit: ebba3c9fa709dccf4cab91e9f37aa3eaa24c7d21 Signed-off-by: Alexandre Kühn (aku) --- addons/mail/static/src/js/attachment_box.js | 3 ++- addons/mail/static/src/js/models/messages/abstract_message.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/attachment_box.js b/addons/mail/static/src/js/attachment_box.js index cc5d53ee1c0..17e91b410e9 100644 --- a/addons/mail/static/src/js/attachment_box.js +++ b/addons/mail/static/src/js/attachment_box.js @@ -7,6 +7,7 @@ var Widget = require('web.Widget'); var DocumentViewer = require('mail.DocumentViewer'); var QWeb = core.qweb; +var _t = core._t; var AttachmentBox = Widget.extend({ template: 'mail.chatter.AttachmentBox', @@ -36,7 +37,7 @@ var AttachmentBox = Widget.extend({ _.each(attachments, function (attachment) { // required for compatibility with the chatter templates. attachment.url = '/web/content/' + attachment.id + '?download=true'; - attachment.filename = attachment.name || 'unnamed'; + attachment.filename = attachment.name || _t('unnamed'); }); var sortedAttachments = _.partition(attachments, function (att) { return att.mimetype && att.mimetype.split('/')[0] === 'image'; diff --git a/addons/mail/static/src/js/models/messages/abstract_message.js b/addons/mail/static/src/js/models/messages/abstract_message.js index 6a7b02d6e94..ee9374996d4 100644 --- a/addons/mail/static/src/js/models/messages/abstract_message.js +++ b/addons/mail/static/src/js/models/messages/abstract_message.js @@ -48,6 +48,9 @@ var AbstractMessage = Class.extend({ this._type = data.message_type || undefined; this._processAttachmentURL(); + this._attachmentIDs.forEach(function (attachment) { + attachment.filename = attachment.filename || attachment.name || _t("unnamed"); + }); }, //--------------------------------------------------------------------------