From 9d5ae16ecea67e931ed69c8639dd6a67741c04aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt?= Date: Mon, 26 Oct 2026 23:40:34 +0100 Subject: [PATCH] [FIX] restrict partner access --- project_customer_access/models/res_users.py | 35 +++++++++++++++++++ .../project_customer_access_security.xml | 14 ++++++++ .../tests/test_project_customer_access.py | 25 +++++++++++++ 3 files changed, 74 insertions(+) diff --git a/project_customer_access/models/res_users.py b/project_customer_access/models/res_users.py index c9538964..9fe6b167 100644 --- a/project_customer_access/models/res_users.py +++ b/project_customer_access/models/res_users.py @@ -7,6 +7,41 @@ class ResUsers(models.Model): _inherit = "res.users" + def _get_support_partner_domain(self): + """Domain of the partners visible by a customer user (used by the record + rule on res.partner): the partners of the users sharing the same + cross-connect client (i.e. the members of his company), the internal + users (internal users without cross-connect client, needed to display + the assignees / authors / followers of the tasks) and the customer + partners of the projects of this client, plus his commercial partner, the + companies and OdooBot. + + The relations are traversed by SQL, so the domain stays up to date when + users/projects change. Users without a cross-connect client are not + restricted. + """ + self.ensure_one() + client = self.cross_connect_client_id + if not client: + return [(1, "=", 1)] + return [ + "|", + "|", + "|", + "|", + "|", + "|", + ("user_ids.cross_connect_client_id", "in", client.ids), + "&", + ("user_ids.groups_id", "in", [self.env.ref("base.group_user").id]), + ("user_ids.cross_connect_client_id", "=", False), + ("project_ids.cross_connect_client_id", "in", client.ids), + ("task_ids.project_id.cross_connect_client_id", "in", client.ids), + ("id", "=", self.commercial_partner_id.id), + ("id", "in", self.company_ids.partner_id.ids), + ("id", "=", self.env.ref("base.partner_root").id), + ] + @api.depends("cross_connect_client_id") def _compute_display_name(self): return super()._compute_display_name() diff --git a/project_customer_access/security/project_customer_access_security.xml b/project_customer_access/security/project_customer_access_security.xml index 0db99ba9..242cd885 100644 --- a/project_customer_access/security/project_customer_access_security.xml +++ b/project_customer_access/security/project_customer_access_security.xml @@ -63,6 +63,20 @@ + + Project Customer Access: Partners + + user._get_support_partner_domain() + + + + + + +