From edbdf1be683151b41434e9bdba9adfaa79cd7e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Demont=C3=A9?= Date: Tue, 16 Jan 2024 09:50:07 +0100 Subject: [PATCH] SUP-29258: Give opinion editor roles for road decree's bound licence --- news/SUP-29258.feature | 2 ++ src/Products/urban/workflows/adapter.py | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 news/SUP-29258.feature diff --git a/news/SUP-29258.feature b/news/SUP-29258.feature new file mode 100644 index 000000000..99d0a9de1 --- /dev/null +++ b/news/SUP-29258.feature @@ -0,0 +1,2 @@ +Give opinion editor roles on road decree's bound licence +[daggelpop] \ No newline at end of file diff --git a/src/Products/urban/workflows/adapter.py b/src/Products/urban/workflows/adapter.py index 95976e9a6..c2dd08707 100644 --- a/src/Products/urban/workflows/adapter.py +++ b/src/Products/urban/workflows/adapter.py @@ -10,14 +10,18 @@ from plone import api from plone.memoize.request import cache +from Products.Archetypes.config import REFERENCE_CATALOG from Products.CMFCore.WorkflowCore import WorkflowException +from Products.CMFCore.utils import getToolByName +from Products.urban.content.licence.RoadDecree import RoadDecree from Products.urban.interfaces import ICODT_IntegratedLicence from Products.urban.interfaces import ICODT_UniqueLicence from Products.urban.interfaces import IEnvironmentBase from Products.urban.interfaces import IIntegratedLicence from Products.urban.interfaces import IUniqueLicence +from zope.component import getAdapters from zope.interface import implements @@ -56,6 +60,22 @@ def get_allowed_groups(self, licence): else: return 'urban_only' + def get_linked_opinion_editors(self): + linked_opinion_editors = [] + if self.context.portal_type in RoadDecree.schema['bound_licence'].allowed_types: + reference_catalog = getToolByName(self.context, REFERENCE_CATALOG) + back_refs = reference_catalog.getBackReferences(self.context, 'bound_licence') + if back_refs: + back_obj = [ref.getSourceObject() for ref in back_refs][0] + back_obj_local_role_adapters = [ + adapter for name, adapter in getAdapters((back_obj,), ILocalRoleProvider) + if hasattr(adapter, 'get_opinion_editors') + ] + for back_obj_local_role_adapter in back_obj_local_role_adapters: + f = back_obj_local_role_adapter.get_opinion_editors() + linked_opinion_editors.extend(f) + return linked_opinion_editors + def get_opinion_editors(self): """ Return groups who have external opinion to give on the licence. @@ -80,7 +100,10 @@ def get_opinion_editors(self): if group not in exceptions: opinion_editors.append(group) - return opinion_editors + back_ref_opinion_editors = self.get_linked_opinion_editors() + opinion_editors.extend(back_ref_opinion_editors) + + return list(set(opinion_editors)) def get_editors(self): """ """