Skip to content

Commit

Permalink
[FIX] mail: chatter attachments without thread
Browse files Browse the repository at this point in the history
This fix prevents the chatter and attachment box
from assuming that there is a mail_thread on the record;

Reason: if a chatter is set on a record that doesn't inherit
mail_thread, the attachment box will generate errors.

closes #31206
  • Loading branch information
ThanhDodeurOdoo committed Feb 19, 2019
1 parent 8a4fe6d commit d12c993
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions addons/mail/static/src/js/chatter.js
Expand Up @@ -90,6 +90,7 @@ var Chatter = Widget.extend({
this._$topbar = this.$('.o_chatter_topbar');
if(!this._disableAttachmentBox) {
this.$('.o_topbar_right_area').append(QWeb.render('mail.chatter.Attachment.Button', {
displayCounter: !!this.fields.thread,
count: this.record.data.message_attachment_count || 0,
}));
}
Expand Down Expand Up @@ -362,7 +363,9 @@ var Chatter = Widget.extend({
if (this._isAttachmentBoxOpen) {
this._fetchAttachments().then(this._openAttachmentBox.bind(this));
}
this.trigger_up('reload', { fieldNames: ['message_attachment_count'] });
if (this.fields.thread) {
this.trigger_up('reload', { fieldNames: ['message_attachment_count'] });
}
},
/**
* @private
Expand Down Expand Up @@ -490,7 +493,9 @@ var Chatter = Widget.extend({
})
.then(function () {
self._reloadAttachmentBox();
self.fields.thread.removeAttachments([ev.data.attachmentId]);
if (self.fields.thread) {
self.fields.thread.removeAttachments([ev.data.attachmentId]);
}
self.trigger_up('reload');
});
}
Expand Down
8 changes: 7 additions & 1 deletion addons/mail/static/src/xml/chatter.xml
Expand Up @@ -105,11 +105,17 @@

</t>

<!--
Chatter attachment paperclip button.
@param {boolean} [displayCounter]
@param {integer} [count]
-->
<t t-name="mail.chatter.Attachment.Button">
<button class="btn btn-link o_chatter_button_attachment" title="View all the attachments of the current record">
<span>
<i class="fa fa-paperclip"/>
<span class="o_chatter_attachment_button_count">
<span t-if="displayCounter" class="o_chatter_attachment_button_count">
<t t-esc="count"/>
</span>
</span>
Expand Down

0 comments on commit d12c993

Please sign in to comment.