Both developments6c4910aand7563b44have been introduced nearly at the same time in the saas-14.5 version, but the later one is introducing a side effect that breaks the project sharing feature. Indeed, before there was one assignee per task (user_id), and now we can assign several collaborators (user_ids). As the read on a M2O is just calling the name_get method, it wasn't an issue. Now, as it implies to read the res.users (and the res.partner) model, the assigned users were filtered according to a specific ir.rule for the portal users: <record id="res_partner_rule" model="ir.rule"> <field name="name">openerp.portal.res.partner</field> <field name="model_id" ref="base.model_res_partner"/> <field name="groups" eval="[(6,0,[ref('group_openerp_portal')])]"/> <field name="domain_force">[('id','child_of',user.commercial_partner_id.id)]</field> </record> This commit creates a new compute non-stored field called `portal_user_names` to display the name of all assignees in each task in the project sharing feature. Thus, the portal user can see all assignees via this char field. The `user_ids` field is removed in the views of project sharing since the portal cannot see all assignees with this field. By doing this, a collaborator cannot edit the field to assign or unassign himself to a task. To keep this behaviour, two buttons are added in the form view of task. One called 'Assign To Me', the current collaborator will be able to assign himself to the task when he will click on this button. The other button called 'Unassign Me' is to allow the collaborator to unassign himself to the task. part of task-2633229 closes odoo/odoo#78538 X-original-commit: 3b5a657df086b54def0bc0bdae89c19c89cb39f5 Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com> Co-authored-by: Xavier BOL (xbo) <xbo@odoo.com> Co-authored-by: Raphael Collet <rco@odoo.com>
209 lines
11 KiB
Python
209 lines
11 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import Command
|
|
from odoo.exceptions import AccessError
|
|
from odoo.tests import tagged
|
|
from odoo.tests.common import Form
|
|
|
|
from .test_project_base import TestProjectCommon
|
|
|
|
|
|
class TestProjectSharingCommon(TestProjectCommon):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super().setUpClass()
|
|
|
|
project_sharing_stages_vals_list = [
|
|
(0, 0, {'name': 'To Do', 'sequence': 1}),
|
|
(0, 0, {'name': 'Done', 'sequence': 10}),
|
|
]
|
|
|
|
cls.partner_portal = cls.env['res.partner'].create({
|
|
'name': 'Chell Gladys',
|
|
'email': 'chell@gladys.portal',
|
|
'company_id': False,
|
|
'user_ids': [Command.link(cls.user_portal.id)]})
|
|
|
|
cls.project_cows = cls.env['project.project'].with_context({'mail_create_nolog': True}).create({
|
|
'name': 'Cows',
|
|
'privacy_visibility': 'portal',
|
|
'alias_name': 'project+cows',
|
|
'type_ids': project_sharing_stages_vals_list,
|
|
})
|
|
cls.project_portal = cls.env['project.project'].with_context({'mail_create_nolog': True}).create({
|
|
'name': 'Portal',
|
|
'privacy_visibility': 'portal',
|
|
'alias_name': 'project+portal',
|
|
'partner_id': cls.user_portal.partner_id.id,
|
|
'type_ids': project_sharing_stages_vals_list,
|
|
})
|
|
|
|
cls.task_cow = cls.env['project.task'].with_context({'mail_create_nolog': True}).create({
|
|
'name': 'Cow UserTask',
|
|
'user_ids': cls.user_projectuser,
|
|
'project_id': cls.project_cows.id,
|
|
})
|
|
cls.task_portal = cls.env['project.task'].with_context({'mail_create_nolog': True}).create({
|
|
'name': 'Portal UserTask',
|
|
'user_ids': cls.user_projectuser,
|
|
'project_id': cls.project_portal.id,
|
|
})
|
|
|
|
def get_project_sharing_form_view(self, record, with_user=None):
|
|
return Form(
|
|
record.with_user(with_user or self.env.user),
|
|
view="project.project_sharing_project_task_view_form"
|
|
)
|
|
|
|
@tagged('project_sharing')
|
|
class TestProjectSharing(TestProjectSharingCommon):
|
|
|
|
def test_project_share_wizard(self):
|
|
""" Test Project Share Wizard
|
|
|
|
Test Cases:
|
|
==========
|
|
1) Create the wizard record
|
|
2) Check if no access rights are given to a portal user
|
|
3) Add access rights to a portal user
|
|
"""
|
|
project_share_wizard = self.env['project.share.wizard'].create({
|
|
'res_model': 'project.project',
|
|
'res_id': self.project_portal.id,
|
|
'access_mode': 'edit',
|
|
})
|
|
self.assertFalse(project_share_wizard.partner_ids, 'No collaborator should be in the wizard.')
|
|
self.assertFalse(self.project_portal.with_user(self.user_portal)._check_project_sharing_access(), 'The portal user should not have accessed in project sharing views.')
|
|
project_share_wizard.write({'partner_ids': [Command.link(self.user_portal.partner_id.id)]})
|
|
project_share_wizard.action_send_mail()
|
|
self.assertEqual(len(self.project_portal.collaborator_ids), 1, 'The access right added in project share wizard should be added in the project when the user confirm the access in the wizard.')
|
|
self.assertDictEqual({
|
|
'partner_id': self.project_portal.collaborator_ids.partner_id,
|
|
'project_id': self.project_portal.collaborator_ids.project_id,
|
|
}, {
|
|
'partner_id': self.user_portal.partner_id,
|
|
'project_id': self.project_portal,
|
|
}, 'The access rights added should be the read access for the portal project for Chell Gladys.')
|
|
self.assertTrue(self.project_portal.with_user(self.user_portal)._check_project_sharing_access(), 'The portal user should have read access to the portal project with project sharing feature.')
|
|
|
|
def test_project_sharing_access(self):
|
|
""" Check if the different user types can access to project sharing feature as expected. """
|
|
with self.assertRaises(AccessError, msg='The public user should not have any access to project sharing feature of the portal project.'):
|
|
self.project_portal.with_user(self.user_public)._check_project_sharing_access()
|
|
self.assertTrue(self.project_portal.with_user(self.user_projectuser)._check_project_sharing_access(), 'The internal user should have all accesses to project sharing feature of the portal project.')
|
|
self.assertFalse(self.project_portal.with_user(self.user_portal)._check_project_sharing_access(), 'The portal user should not have any access to project sharing feature of the portal project.')
|
|
self.project_portal.write({'collaborator_ids': [Command.create({'partner_id': self.user_portal.partner_id.id})]})
|
|
self.assertTrue(self.project_portal.with_user(self.user_portal)._check_project_sharing_access(), 'The portal user can access to project sharing feature of the portal project.')
|
|
|
|
def test_create_task_in_project_sharing(self):
|
|
""" Test when portal user creates a task in project sharing views.
|
|
|
|
Test Cases:
|
|
==========
|
|
1) Give the 'read' access mode to a portal user in a project and try to create task with this user.
|
|
2) Give the 'comment' access mode to a portal user in a project and try to create task with this user.
|
|
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.
|
|
"""
|
|
# 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."):
|
|
with self.get_project_sharing_form_view(self.env['project.task'].with_context({'tracking_disable': True, 'default_project_id': self.project_portal.id}), self.user_portal) as form:
|
|
form.name = 'Test'
|
|
task = form.save()
|
|
|
|
self.project_portal.write({
|
|
'collaborator_ids': [
|
|
Command.create({'partner_id': self.user_portal.partner_id.id}),
|
|
],
|
|
})
|
|
with self.get_project_sharing_form_view(self.env['project.task'].with_context({'tracking_disable': True, 'default_project_id': self.project_portal.id}), self.user_portal) as form:
|
|
form.name = 'Test'
|
|
task = form.save()
|
|
self.assertEqual(task.name, 'Test')
|
|
self.assertEqual(task.project_id, self.project_portal)
|
|
self.assertEqual(task.portal_user_names, self.user_portal.name)
|
|
# 3.1) Try to change the project of the new task with this user.
|
|
with self.assertRaises(AssertionError, msg="Should not accept the portal user changes the project of the task."):
|
|
form.project_id = self.project_cows
|
|
task = form.save()
|
|
|
|
def test_edit_task_in_project_sharing(self):
|
|
""" Test when portal user creates a task in project sharing views.
|
|
|
|
Test Cases:
|
|
==========
|
|
1) Give the 'read' access mode to a portal user in a project and try to edit task with this user.
|
|
2) Give the 'comment' access mode to a portal user in a project and try to edit task with this user.
|
|
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.
|
|
"""
|
|
# 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."):
|
|
with self.get_project_sharing_form_view(self.task_cow.with_context({'tracking_disable': True, 'default_project_id': self.project_cows.id}), self.user_portal) as form:
|
|
form.name = 'Test'
|
|
task = form.save()
|
|
|
|
project_share_wizard = self.env['project.share.wizard'].create({
|
|
'access_mode': 'edit',
|
|
'res_model': 'project.project',
|
|
'res_id': self.project_cows.id,
|
|
'partner_ids': [
|
|
Command.link(self.user_portal.partner_id.id),
|
|
],
|
|
})
|
|
project_share_wizard.action_send_mail()
|
|
|
|
with self.get_project_sharing_form_view(self.task_cow.with_context({'tracking_disable': True, 'default_project_id': self.project_cows.id, 'uid': self.user_portal.id}), self.user_portal) as form:
|
|
form.name = 'Test'
|
|
task = form.save()
|
|
self.assertEqual(task.name, 'Test')
|
|
self.assertEqual(task.project_id, self.project_cows)
|
|
|
|
# 3.1) Try to change the project of the new task with this user.
|
|
with self.assertRaises(AssertionError, msg="Should not accept the portal user changes the project of the task."):
|
|
with self.get_project_sharing_form_view(task, self.user_portal) as form:
|
|
form.project_id = self.project_portal
|
|
|
|
# 3.2) Create a 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'
|
|
with self.assertRaises(AssertionError, msg="Should not accept the portal user changes the project of the task."):
|
|
subtask_form.display_project_id = self.project_portal
|
|
self.assertEqual(task.child_ids.name, 'Test Subtask')
|
|
self.assertEqual(task.child_ids.project_id, self.project_cows)
|
|
self.assertEqual(task.child_ids.portal_user_names, self.user_portal.name)
|
|
self.assertEqual(task.child_ids.user_ids, self.user_portal)
|
|
|
|
def test_portal_user_cannot_see_all_assignees(self):
|
|
""" Test when the portal sees a task he cannot see all the assignees.
|
|
|
|
Because of a ir.rule in res.partner filters the assignees, the portal
|
|
can only see the assignees in the same company than him.
|
|
|
|
Test Cases:
|
|
==========
|
|
1) add many assignees in a task
|
|
2) check the portal user can read no assignee in this task. Should have an AccessError exception
|
|
"""
|
|
self.task_cow.write({'user_ids': [Command.link(self.user_projectmanager.id)]})
|
|
with self.assertRaises(AccessError, msg="Should not accept the portal user to access to a task he does not follow it and its project."):
|
|
self.task_cow.with_user(self.user_portal).read(['portal_user_names'])
|
|
self.assertEqual(len(self.task_cow.user_ids), 2, '2 users should be assigned in this task.')
|
|
|
|
project_share_wizard = self.env['project.share.wizard'].create({
|
|
'access_mode': 'edit',
|
|
'res_model': 'project.project',
|
|
'res_id': self.project_cows.id,
|
|
'partner_ids': [
|
|
Command.link(self.user_portal.partner_id.id),
|
|
],
|
|
})
|
|
project_share_wizard.action_send_mail()
|
|
|
|
self.assertFalse(self.task_cow.with_user(self.user_portal).user_ids, 'the portal user should see no assigness in the task.')
|
|
task_portal_read = self.task_cow.with_user(self.user_portal).read(['portal_user_names'])
|
|
self.assertEqual(self.task_cow.portal_user_names, task_portal_read[0]['portal_user_names'], 'the portal user should see assignees name in the task via the `portal_user_names` field.')
|