[FIX] mail: fix ACLs issue with mail composer in new mode

As create_uid has no value on mail.compose.message model when being in onchange
or new mode, 'Mail Compose Message Rule' record rule may crash. In this
commit we fix that issue by adding a value for create_uid. An unit test is
added to ensure it effectively fixes the use case.

Steps to reproduce this warning:
 1. Create automated action for the 'mail.compose.message' model
 2. Try to open 'Email compose Wizard'

Warning:

"Due to security restrictions, you are not allowed to modify 'Email composition
wizard' (mail.compose.message) records.

Records: mail.compose.message,NewId_0x7f8e99762310 (id=NewId_0x7f8e99762310)
User: USERNAME (id=2)

This restriction is due to the following rules:

Contact your administrator to request access if necessary."

Task-2641572
opw-2628005
PR odoo#76159
Closes#75369

X-original-commit: 26d64c0b84b76bb9164a8895bcc21b66754478ae
Part-of: odoo/odoo#77005
Co-authored-by: Thibault Delavallee <tde@odoo.com>
This commit is contained in:
Jinal Patel
2021-09-22 19:25:55 +00:00
committed by Thibault Delavallée
co-authored by Thibault Delavallee
parent a8518ae75d
commit 223b51c462
4 changed files with 46 additions and 1 deletions
+2
View File
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_automation
from . import test_mail_composer
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests.common import tagged, HttpCase
@tagged('-at_install', 'post_install', 'mail_composer')
class TestMailFullComposer(HttpCase):
def test_full_composer_tour(self):
self.env['mail.template'].create({
'name': 'Test template', # name hardcoded for test
'partner_to': '${object.id}',
'lang': '${object.lang}',
'auto_delete': True,
'model_id': self.ref('base.model_res_partner'),
})
test_user = self.env['res.users'].create({
'email': 'testuser@testuser.com',
'groups_id': [
(6, 0, [self.ref('base.group_user'), self.ref('base.group_partner_manager')]),
],
'name': 'Test User',
'login': 'testuser',
'password': 'testuser',
})
automated_action = self.env['base.automation'].create({
'name': 'Test',
'active': True,
'trigger': 'on_change',
'on_change_field_ids': (4, self.ref('mail.field_mail_compose_message__template_id'),),
'state': 'code',
'model_id': self.env.ref('mail.model_mail_compose_message').id,
})
self.start_tour("/web#id=%d&model=res.partner" % test_user.partner_id, 'mail/static/tests/tours/mail_full_composer_test_tour.js', login='testuser')
automated_action.unlink()
+1 -1
View File
@@ -5,7 +5,7 @@ from odoo.tests.common import tagged, HttpCase
from odoo import Command
@tagged('-at_install', 'post_install')
@tagged('-at_install', 'post_install', 'mail_composer')
class TestMailFullComposer(HttpCase):
def test_full_composer_tour(self):
@@ -75,6 +75,10 @@ class MailComposer(models.TransientModel):
if result.get('composition_mode') == 'comment' and (set(fields) & set(['model', 'res_id', 'partner_ids', 'record_name', 'subject'])):
result.update(self.get_record_data(result))
# when being in new mode, create_uid is not granted -> ACLs issue may arise
if 'create_uid' in fields and 'create_uid' not in result:
result['create_uid'] = self.env.uid
filtered_result = dict((fname, result[fname]) for fname in result if fname in fields)
return filtered_result