@@ -70,12 +70,92 @@ def test_mail_template_acl(self):
7070 with self .assertRaises (AccessError ):
7171 self .env ['mail.template' ].with_user (self .user_employee ).create ({'body_html' : '<p t-esc="\' foo\' "></p>' })
7272
73+ # Standard employee cannot edit templates from another user, non-dynamic and dynamic
74+ with self .assertRaises (AccessError ):
75+ mail_template .with_user (self .user_employee ).body_html = '<p>foo</p>'
7376 with self .assertRaises (AccessError ):
7477 mail_template .with_user (self .user_employee ).body_html = '<p t-esc="\' foo\' "></p>'
7578
79+ # Standard employee can edit his own templates if not dynamic
80+ employee_template .with_user (self .user_employee ).body_html = '<p>foo</p>'
81+
7682 # Standard employee cannot create and edit templates with dynamic inline fields
7783 with self .assertRaises (AccessError ):
7884 self .env ['mail.template' ].with_user (self .user_employee ).create ({'email_to' : '{{ object.partner_id.email }}' })
7985
86+ # Standard employee cannot edit his own templates if dynamic
87+ with self .assertRaises (AccessError ):
88+ employee_template .with_user (self .user_employee ).body_html = '<p t-esc="\' foo\' "></p>'
89+
90+ with self .assertRaises (AccessError ):
91+ employee_template .with_user (self .user_employee ).email_to = '{{ object.partner_id.email }}'
92+
93+ def test_mail_template_acl_translation (self ):
94+ ''' Test that a user that doenn't have the group_mail_template_editor cannot create / edit
95+ translation with dynamic code if he cannot write dynamic code on the related record itself.
96+ '''
97+
98+ self .env .ref ('base.lang_fr' ).sudo ().active = True
99+
100+ employee_template = self .env ['mail.template' ].with_user (self .user_employee ).create ({
101+ 'model_id' : self .env .ref ('base.model_res_partner' ).id ,
102+ 'subject' : 'The subject' ,
103+ 'body_html' : '<p>foo</p>' ,
104+ })
105+
106+ Translation = self .env ['ir.translation' ]
107+
108+ ### check qweb dynamic
109+ Translation .insert_missing (employee_template ._fields ['body_html' ], employee_template )
110+ employee_translations_of_body = Translation .with_user (self .user_employee ).search (
111+ [('res_id' , '=' , employee_template .id ), ('name' , '=' , 'mail.template,body_html' ), ('lang' , '=' , 'fr_FR' )],
112+ limit = 1
113+ )
114+ # keep a copy to create new translation later
115+ body_translation_vals = employee_translations_of_body .read ([])[0 ]
116+
117+ # write on translation for template without dynamic code is allowed
118+ employee_translations_of_body .value = 'non-qweb'
119+
120+ # cannot write dynamic code on mail_template translation for employee without the group mail_template_editor.
121+ with self .assertRaises (AccessError ):
122+ employee_translations_of_body .value = '<t t-esc="foo"/>'
123+
124+ employee_translations_of_body .unlink () # delete old translation, to test the creation now
125+ body_translation_vals ['value' ] = '<p t-esc="foo"/>'
126+
127+ # admin can create
128+ new = Translation .create (body_translation_vals )
129+ new .unlink ()
130+
131+ # Employee without mail_template_editor group cannot create dynamic translation for mail.render.mixin
132+ with self .assertRaises (AccessError ):
133+ Translation .with_user (self .user_employee ).create (body_translation_vals )
134+
135+
136+ ### check qweb inline dynamic
137+ Translation .insert_missing (employee_template ._fields ['subject' ], employee_template )
138+ employee_translations_of_subject = Translation .with_user (self .user_employee ).search (
139+ [('res_id' , '=' , employee_template .id ), ('name' , '=' , 'mail.template,subject' ), ('lang' , '=' , 'fr_FR' )],
140+ limit = 1
141+ )
142+ # keep a copy to create new translation later
143+ subject_translation_vals = employee_translations_of_subject .read ([])[0 ]
144+
145+ # write on translation for template without dynamic code is allowed
146+ employee_translations_of_subject .value = 'non-qweb'
147+
148+ # cannot write dynamic code on mail_template translation for employee without the group mail_template_editor.
149+ with self .assertRaises (AccessError ):
150+ employee_translations_of_subject .value = '{{ object.foo }}'
151+
152+ employee_translations_of_subject .unlink () # delete old translation, to test the creation now
153+ subject_translation_vals ['value' ] = '{{ object.foo }}'
154+
155+ # admin can create
156+ new = Translation .create (subject_translation_vals )
157+ new .unlink ()
158+
159+ # Employee without mail_template_editor group cannot create dynamic translation for mail.render.mixin
80160 with self .assertRaises (AccessError ):
81- mail_template .with_user (self .user_employee ).email_to = '{{ object.partner_id.email }}'
161+ Translation .with_user (self .user_employee ).create ( subject_translation_vals )
0 commit comments