diff options
| author | Thanh Dodeur <tso@odoo.com> | 2020-10-30 07:19:29 +0000 |
|---|---|---|
| committer | Thanh Dodeur <tso@odoo.com> | 2020-12-10 13:44:05 +0000 |
| commit | 528adfb313ab3c8d4aeb3309aa7371301ab8085e (patch) | |
| tree | 4d9f74dc37c03267dff7cd39287634704bbe9d40 /addons/mail/static/src/models | |
| parent | e702399ceb9b84ad1ce82371eeaeddb492907eda (diff) | |
[FIX] mail: handles unlink button spam on attachments
Before this commit, attempting to delete attachments multiple times
could result in errors, especially on slow networks.
This commit fixes this issue.
task-2363522
closes odoo/odoo#61017
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail/static/src/models')
| -rw-r--r-- | addons/mail/static/src/models/attachment/attachment.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/addons/mail/static/src/models/attachment/attachment.js b/addons/mail/static/src/models/attachment/attachment.js index 7399dee7b33..3cea681a3bf 100644 --- a/addons/mail/static/src/models/attachment/attachment.js +++ b/addons/mail/static/src/models/attachment/attachment.js @@ -97,12 +97,20 @@ function factory(dependencies) { * Remove this attachment globally. */ async remove() { + if (this.isUnlinkPending) { + return; + } if (!this.isTemporary) { - await this.async(() => this.env.services.rpc({ - model: 'ir.attachment', - method: 'unlink', - args: [this.id], - }, { shadow: true })); + this.update({ isUnlinkPending: true }); + try { + await this.async(() => this.env.services.rpc({ + model: 'ir.attachment', + method: 'unlink', + args: [this.id], + }, { shadow: true })); + } finally { + this.update({ isUnlinkPending: false }); + } } else if (this.uploadingAbortController) { this.uploadingAbortController.abort(); } @@ -333,6 +341,12 @@ function factory(dependencies) { compute: '_computeIsTextFile', dependencies: ['fileType'], }), + /** + * True if an unlink RPC is pending, used to prevent multiple unlink attempts. + */ + isUnlinkPending: attr({ + default: false, + }), isViewable: attr({ compute: '_computeIsViewable', dependencies: [ |
