[FIX] mail: Force the writing of the attachment when the user can post

To reproduce:
1) Enable multi-company
2) Create two companies: c1, c2
3) Create two users: bob in c1 and alice in c2
4) Install subscription
5) Remove the ir.rule that forbid users from accessing subscriptions
   made in other companies: "Subscription multi-company"
6) Using u1, create a new subscription in c1
7) Using u2, follow the chatter of the newly created subscription
   allowing the user to post messages/log notes.
8) Using u2, send a message with an attachment. Access Error.

The problem raises only for the **first** attachment. That
attchement is written on the record as the main attachment thus
raises an error if the user doesn't have write access.

There is no problem to add attachment to any following record or
when the user has write access on the model. If the user doesn't
have access to the chatter, he is blocked before accessing the
write thus it is safe to sudo it.

opw-1915606

closes odoo/odoo#30659
This commit is contained in:
Julien (juc) Castiaux
2019-01-30 10:46:01 +00:00
parent d609dbdd11
commit e65446fe42
+1 -1
View File
@@ -2070,7 +2070,7 @@ class MailThread(models.AbstractModel):
prioritary_attachments = all_attachments.filtered(lambda x: x.mimetype.endswith('pdf')) \
or all_attachments.filtered(lambda x: x.mimetype.startswith('image')) \
or all_attachments
self.write({'message_main_attachment_id': prioritary_attachments[0].id})
self.sudo().write({'message_main_attachment_id': prioritary_attachments[0].id})
# Notify recipients of the newly-created message (Inbox / Email + channels)
if msg_vals.get('moderation_status') != 'pending_moderation':
message._notify(