[FW][FIX] project: create subtask in project sharing

Before this commit, when the current user is in project sharing and see
the form view of a task with at least a subtask. He cannot create
another one because of an error in the `_compute_portal_user_names`
method. Indeed, it is because we want to update the cache to get the
user_ids of the task related since the portal user cannot see the
users assigned to the task since he cannot access an internal user. This
update cache is made by calling the `_read` method but this method
checks after having fetching the data if the self is equal to the
recordset fetched. If the `self` contained newIds, then the method will
raise an error because a Task with newId != Task with id in db.

This commit fixes the compute method to call the _read method only on a
self with no NewIds to avoid this issue and correctly updates the cache
to get the name of the users assigned to a task in project sharing for
the portal user.

Fix found by Florian Damhaut <flda@odoo.com>

Co-authored-by Florian Damhaut <flda@odoo.com>

opw-2745857

closes odoo/odoo#84298

X-original-commit: f61c4f43365d38a955c497e022f0e8f18f50a6b2
Forward-port-of: #84189
Related: odoo/enterprise#24207
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
This commit is contained in:
Xavier BOL (xbo)
2022-02-09 20:41:50 +00:00
parent 5ad8369bdb
commit 68a3c80d30
2 changed files with 10 additions and 2 deletions
+3 -2
View File
@@ -1451,8 +1451,9 @@ class Task(models.Model):
(In other words, this compute is only used in project sharing views to see all assignees for each task)
"""
if self.ids:
# fetch 'user_ids' in superuser mode (and override value in cache)
self._read(['user_ids'])
# fetch 'user_ids' in superuser mode (and override value in cache
# browse is useful to avoid miscache because of the newIds contained in self
self.browse(self.ids)._read(['user_ids'])
for task in self.with_context(prefetch_fields=False):
task.portal_user_names = ', '.join(task.user_ids.mapped('name'))
@@ -141,6 +141,7 @@ class TestProjectSharing(TestProjectSharingCommon):
3) Give the 'edit' access mode to a portal user in a project and try to create task with this user.
3.1) Try to change the project of the new task with this user.
3.2) Create a sub-task
3.3) Create a second sub-task
"""
# 1) Give the 'read' access mode to a portal user in a project and try to create task with this user.
with self.assertRaises(AccessError, msg="Should not accept the portal user create a task in the project when he has not the edit access right."):
@@ -190,6 +191,12 @@ class TestProjectSharing(TestProjectSharingCommon):
.create({'name': 'Test'})
self.assertFalse(task2.portal_user_names, 'the portal user should not be assigned when the portal user creates a task into the project shared.')
# 3.3) Create a second sub-task
with self.get_project_sharing_form_view(task, self.user_portal) as form:
with form.child_ids.new() as subtask_form:
subtask_form.name = 'Test Subtask'
self.assertEqual(len(task.child_ids), 2, 'Check 2 subtasks has correctly been created by the user portal.')
def test_portal_user_cannot_see_all_assignees(self):
""" Test when the portal sees a task he cannot see all the assignees.