Skip to content

Commit 821156c

Browse files
committed
[FIX] {test_}mail: remove activity assignation check
How to reproduce: - Install hr with demo data - Create a user without access to hr and turn it into an employee - Create a user for Abigail - Assign Abigail as manager of the new user - Click on "onboarding plan" in the chatter of the new user - Then in the dialog, click on "Schedule" button You get the error "Assigned user test has no access to the document and is not able to handle this activity." because the new user has no access to the record employee on which those activities are scheduled. As activities for which the user has no access to the underlying record are now displayed in the systray (with no access to the record), we remove the check that prevent assigning an activity to a user on a record he has no access to. Technical note: before odoo#149965, activities scheduled manually were created with the flag "automated" set to True and when this flag is set the check that ensures that the user has access to the record is skipped. With odoo#149965, as the "automated" flag is set to False when scheduling activities manually, an error is trigerred if the user has no access to the underlying record. Here we always skip that test and mark the method as deprecated because the user can see the activity no matter the access he has on the underlying record. Task-3598836 closes odoo#155576 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
1 parent ad9dc53 commit 821156c

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

addons/mail/models/mail_activity.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,8 @@ def _filter_access_rules_remaining(self, valid, operation, filter_access_rules_m
260260
# if available; otherwise fall back on read for read, write for other operations.
261261
activity_to_documents = dict()
262262
for activity in remaining_sudo:
263-
# write / unlink: if not updating self or assigned, limit to automated activities to avoid
264-
# updating other people's activities. As unlinking a document bypasses access rights checks
265-
# on related activities this will not prevent people from deleting documents with activities
263+
# write / unlink: As unlinking a document bypasses access rights checks on related activities
264+
# this will not prevent people from deleting documents with activities
266265
# create / read: just check rights on related document
267266
activity_to_documents.setdefault(activity.res_model, list()).append(activity.res_id)
268267
for doc_model, doc_ids in activity_to_documents.items():
@@ -283,7 +282,12 @@ def _check_access_assignation(self):
283282
""" Check assigned user (user_id field) has access to the document. Purpose
284283
is to allow assigned user to handle their activities. For that purpose
285284
assigned user should be able to at least read the document. We therefore
286-
raise an UserError if the assigned user has no access to the document. """
285+
raise an UserError if the assigned user has no access to the document.
286+
287+
.. deprecated:: 17.0
288+
Deprecated method, we don't check access to the underlying records anymore
289+
as user can new see activities without having access to the underlying records.
290+
"""
287291
for model, activity_data in self._classify_by_model().items():
288292
# group activities / user, in order to batch the check of ACLs
289293
per_user = dict()
@@ -327,14 +331,10 @@ def create(self, vals_list):
327331
readable_user_partners = self.env.user.partner_id
328332

329333
# when creating activities for other: send a notification to assigned user;
330-
# in case of manually done activity also check target has rights on document
331-
# otherwise we prevent its creation. Automated activities are checked since
332-
# they are integrated into business flows that should not crash.
333334
if self.env.context.get('mail_activity_quick_update'):
334335
activities_to_notify = self.env['mail.activity']
335336
else:
336337
activities_to_notify = activities.filtered(lambda act: act.user_id != self.env.user)
337-
activities_to_notify.filtered(lambda act: not act.automated)._check_access_assignation()
338338
if activities_to_notify:
339339
to_sudo = activities_to_notify.filtered(lambda act: act.user_id.partner_id not in readable_user_partners)
340340
other = activities_to_notify - to_sudo
@@ -370,8 +370,6 @@ def write(self, values):
370370

371371
if values.get('user_id'):
372372
if values['user_id'] != self.env.uid:
373-
to_check = user_changes.filtered(lambda act: not act.automated)
374-
to_check._check_access_assignation()
375373
if not self.env.context.get('mail_activity_quick_update', False):
376374
user_changes.action_notify()
377375
for activity in user_changes:

addons/test_mail/tests/test_mail_activity.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,14 @@ def _employee_crash(*args, **kwargs):
124124
[('id', '=', test_activity.id)],
125125
['summary'])
126126

127-
# cannot create activities for people that cannot access record
127+
# can create activities for people that cannot access record
128128
with patch.object(MailTestActivity, 'check_access_rights', autospec=True, side_effect=_employee_crash):
129-
with self.assertRaises(exceptions.UserError):
130-
activity = self.env['mail.activity'].create({
131-
'activity_type_id': self.env.ref('test_mail.mail_act_test_todo').id,
132-
'res_model_id': self.env.ref('test_mail.model_mail_test_activity').id,
133-
'res_id': self.test_record.id,
134-
'user_id': self.user_employee.id,
135-
})
129+
self.env['mail.activity'].create({
130+
'activity_type_id': self.env.ref('test_mail.mail_act_test_todo').id,
131+
'res_model_id': self.env.ref('test_mail.model_mail_test_activity').id,
132+
'res_id': self.test_record.id,
133+
'user_id': self.user_employee.id,
134+
})
136135

137136
# cannot create activities if no access to the document
138137
with patch.object(MailTestActivity, 'check_access_rights', autospec=True, side_effect=_employee_crash):

0 commit comments

Comments
 (0)