[FIX] mail: allow user to delete other's attachments again
Before this PR, only author of the message and admin could delete attachments inside the chatter. This behavior is now restricted to the channels and allow users to delete attachments inside the chatter. task-2753295 closes odoo/odoo#86302 X-original-commit: 5934dc08b32b422a11324743148083d4daa34350 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
committed by
Alexandre Kühn
parent
24a19a10c9
commit
1b7fb828e0
@@ -268,7 +268,9 @@ class DiscussController(http.Controller):
|
||||
def mail_attachment_delete(self, attachment_id, access_token=None, **kwargs):
|
||||
attachment_sudo = request.env['ir.attachment'].browse(int(attachment_id)).sudo().exists()
|
||||
if not attachment_sudo:
|
||||
raise NotFound()
|
||||
target = request.env.user.partner_id
|
||||
request.env['bus.bus']._sendone(target, 'ir.attachment/delete', {'id': attachment_id})
|
||||
return
|
||||
if not request.env.user.share:
|
||||
# Check through standard access rights/rules for internal users.
|
||||
attachment_sudo.sudo(False)._delete_and_notify()
|
||||
|
||||
@@ -701,7 +701,7 @@ QUnit.test('allow attachment delete on authored message', async function (assert
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('prevent attachment delete on non-authored message', async function (assert) {
|
||||
QUnit.test('prevent attachment delete on non-authored message in channels', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
const { createMessageComponent } = await this.start();
|
||||
@@ -711,6 +711,10 @@ QUnit.test('prevent attachment delete on non-authored message', async function (
|
||||
id: 10,
|
||||
name: "BLAH",
|
||||
mimetype: 'image/jpeg',
|
||||
originThread: insertAndReplace({
|
||||
id: 11,
|
||||
model: 'mail.channel',
|
||||
}),
|
||||
}),
|
||||
author: insert({ id: 11, display_name: "Guy" }),
|
||||
body: "<p>Test</p>",
|
||||
|
||||
@@ -164,13 +164,15 @@ registerModel({
|
||||
if (!this.messaging) {
|
||||
return;
|
||||
}
|
||||
return this.messages.length
|
||||
? this.messages.some(message => (
|
||||
|
||||
if (this.messages.length && this.originThread && this.originThread.model === 'mail.channel') {
|
||||
return this.messages.some(message => (
|
||||
message.canBeDeleted ||
|
||||
(message.author && message.author === this.messaging.currentPartner) ||
|
||||
(message.guestAuthor && message.guestAuthor === this.messaging.currentGuest)
|
||||
))
|
||||
: true;
|
||||
));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user