# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.mail.tests.common import MailCommon
from odoo.exceptions import AccessError
from odoo.tests import Form, users
class TestMailTemplate(MailCommon):
@classmethod
def setUpClass(cls):
super(TestMailTemplate, cls).setUpClass()
# Enable the Jinja rendering restriction
cls.env['ir.config_parameter'].set_param('mail.restrict.template.rendering', True)
cls.user_employee.groups_id -= cls.env.ref('mail.group_mail_template_editor')
cls.mail_template = cls.env['mail.template'].create({
'name': 'Test template',
'subject': '{{ 1 + 5 }}',
'body_html': '
foo
'}) employee_template.with_user(self.user_employee).body_html = 'bar
' employee_template = self.env['mail.template'].with_user(self.user_employee).create({'email_to': 'foo@bar.com'}) employee_template.with_user(self.user_employee).email_to = 'bar@foo.com' # Standard employee cannot create and edit templates with dynamic qweb with self.assertRaises(AccessError): self.env['mail.template'].with_user(self.user_employee).create({'body_html': ''}) # Standard employee cannot edit templates from another user, non-dynamic and dynamic with self.assertRaises(AccessError): mail_template.with_user(self.user_employee).body_html = 'foo
' with self.assertRaises(AccessError): mail_template.with_user(self.user_employee).body_html = '' # Standard employee can edit his own templates if not dynamic employee_template.with_user(self.user_employee).body_html = 'foo
' # Standard employee cannot create and edit templates with dynamic inline fields with self.assertRaises(AccessError): self.env['mail.template'].with_user(self.user_employee).create({'email_to': '{{ object.partner_id.email }}'}) # Standard employee cannot edit his own templates if dynamic with self.assertRaises(AccessError): employee_template.with_user(self.user_employee).body_html = '' with self.assertRaises(AccessError): employee_template.with_user(self.user_employee).email_to = '{{ object.partner_id.email }}' def test_mail_template_acl_translation(self): ''' Test that a user that doenn't have the group_mail_template_editor cannot create / edit translation with dynamic code if he cannot write dynamic code on the related record itself. ''' self.env.ref('base.lang_fr').sudo().active = True employee_template = self.env['mail.template'].with_user(self.user_employee).create({ 'model_id': self.env.ref('base.model_res_partner').id, 'subject': 'The subject', 'body_html': 'foo
', }) Translation = self.env['ir.translation'] ### check qweb dynamic Translation.insert_missing(employee_template._fields['body_html'], employee_template) employee_translations_of_body = Translation.with_user(self.user_employee).search( [('res_id', '=', employee_template.id), ('name', '=', 'mail.template,body_html'), ('lang', '=', 'fr_FR')], limit=1 ) # keep a copy to create new translation later body_translation_vals = employee_translations_of_body.read([])[0] # write on translation for template without dynamic code is allowed employee_translations_of_body.value = 'non-qweb' # cannot write dynamic code on mail_template translation for employee without the group mail_template_editor. with self.assertRaises(AccessError): employee_translations_of_body.value = '