Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/URBBDC-3312.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add group for housing editor and reader
[jchandelle]
1 change: 1 addition & 0 deletions src/Products/urban/browser/portlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def available(self):
"Manager" in roles
or "urban_editors" in groups
or "environment_editors" in groups
or "housing_editors" in groups
or "urban_managers" in groups
)
return available
Expand Down
121 changes: 121 additions & 0 deletions src/Products/urban/migration/update_290.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from Products.urban.migration.utils import cook_javascript_resources
from Products.urban.setuphandlers import add_new_urban_licence_type
from Products.urban.utils import moveElementAfter
from Products.urban.utils import getLicenceFolderId
from Products.urban.migration.utils import refresh_workflow_permissions
from Products.urban.setuphandlers import set_licence_folder_security
from dm.historical import getHistory
from imio.helpers.catalog import reindexIndexes
Expand Down Expand Up @@ -721,3 +723,122 @@ def setup_referenceFT_PM(context):
reindexIndexes(None, ["referenceFT_PM"])

logger.info("upgrade step done!")


def _reindex_security(catalog, brains):
"""Reindex only 'allowedRolesAndUsers' on the given brains."""
for brain in brains:
obj = brain._unrestrictedGetObject()
if obj is None:
continue
catalog.reindexObject(
obj,
idxs=["allowedRolesAndUsers"],
update_metadata=0,
uid=brain.getPath(),
)


def add_housing_group(context):
logger = logging.getLogger("urban: Add housing groups")
logger.info("starting upgrade step")

HOUSING_GROUPS = {
"housing_editors": {
"title": "Housing Editors",
"description": "Group for housing editor",
},
"housing_readers": {
"title": "Housing Readers",
"description": "Group for housing reader",
},
}

for group_id, values in HOUSING_GROUPS.items():
if api.group.get(groupname=group_id) is None:
api.group.create(
groupname=group_id,
title=values["title"],
description=values["description"],
roles=["UrbanMapReader"],
)
portal_groups = api.portal.get_tool("portal_groups")
portal_groups.addPrincipalToGroup("housing_editors", "housing_readers")

portal = api.portal.get()
urban_folder = portal["urban"]
portal_urban = api.portal.get_tool("portal_urban")
housing_folder = getattr(urban_folder, getLicenceFolderId("Housing"), None)
if housing_folder is None:
logger.error("could not find the housing folder, aborting!")
return

urban_folder.manage_addLocalRoles("housing_readers", ("Reader",))
urban_folder.manage_addLocalRoles("housing_editors", ("Reader",))

portal_urban.manage_addLocalRoles("housing_readers", ("Reader",))
portal_urban.manage_addLocalRoles("housing_editors", ("Reader",))

housing_folder.manage_addLocalRoles("housing_editors", ("Contributor",))

objects_folder_names = ["architects", "geometricians", "notaries", "parcellings"]
for folder_name in objects_folder_names:
folder = getattr(urban_folder, folder_name, None)
if folder is None:
continue
folder.manage_addLocalRoles("housing_readers", ("Reader",))
folder.manage_addLocalRoles("housing_editors", ("Editor", "Contributor"))

catalog = api.portal.get_tool("portal_catalog")
urban_path = "/".join(urban_folder.getPhysicalPath())
config_path = "/".join(portal_urban.getPhysicalPath())

# housing business content: licences + collection_housing
housing_folder.reindexObjectSecurity()

# "procedure" links in the /urban collection widget
_reindex_security(
catalog,
catalog.unrestrictedSearchResults(
path={"query": urban_path},
object_provides="plone.app.collection.interfaces.ICollection",
),
)

# procedure listing in portal_urban
_reindex_security(
catalog,
catalog.unrestrictedSearchResults(
path={"query": config_path},
portal_type="LicenceConfig",
),
)

# contact folders: needed for the search-by-name form
for folder_name in objects_folder_names:
_reindex_security(
catalog,
catalog.unrestrictedSearchResults(
path={"query": "{}/{}".format(urban_path, folder_name)},
),
)

# folder managers
foldermanagers_folder = getattr(portal_urban, "foldermanagers", None)
if foldermanagers_folder is not None:
foldermanagers_folder.reindexObjectSecurity()

urban_folder.reindexObject(idxs=["allowedRolesAndUsers"])
portal_urban.reindexObject(idxs=["allowedRolesAndUsers"])

if housing_folder.objectIds("Housing"):
refresh_workflow_permissions("housing_workflow", folder_path=urban_path)
refresh_workflow_permissions("urbanevent_workflow", folder_path=urban_path)
refresh_workflow_permissions("opinion_request_workflow", folder_path=urban_path)
else:
logger.info(
"no housing licence found in %s, skipping workflow permissions refresh",
"/".join(housing_folder.getPhysicalPath()),
)

logger.info("upgrade step done!")
8 changes: 8 additions & 0 deletions src/Products/urban/migration/upgrades_290.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,12 @@
handler=".update_290.setup_referenceFT_PM"
profile="Products.urban:default" />

<gs:upgradeStep
title="Add housing group"
description=""
source="2919"
destination="2920"
handler=".update_290.add_housing_group"
profile="Products.urban:default" />

</configure>
2 changes: 1 addition & 1 deletion src/Products/urban/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>2919</version>
<version>2920</version>
<dependencies>
<dependency>profile-Products.urban:preinstall</dependency>
</dependencies>
Expand Down
16 changes: 16 additions & 0 deletions src/Products/urban/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,12 @@ def addUrbanGroups(context):
site.portal_groups.addGroup("inspection_editors", title="Inspection Editors")
site.portal_groups.setRolesForGroup("inspection_editors", ("UrbanMapReader",))
site.portal_groups.addPrincipalToGroup("inspection_editors", "urban_readers")
# add housing editors group
site.portal_groups.addGroup("housing_editors", title="Housing Editors")
site.portal_groups.setRolesForGroup("housing_editors", ("UrbanMapReader",))
site.portal_groups.addGroup("housing_readers", title="Housing Readers")
site.portal_groups.setRolesForGroup("housing_readers", ("UrbanMapReader",))
site.portal_groups.addPrincipalToGroup("housing_editors", "housing_readers")


def setDefaultApplicationSecurity(context):
Expand Down Expand Up @@ -737,6 +743,8 @@ def setDefaultApplicationSecurity(context):
site.portal_urban.manage_addLocalRoles("environment_readers", ("Reader",))
site.portal_urban.manage_addLocalRoles("environment_editors", ("Reader",))
site.portal_urban.manage_addLocalRoles("urban_map_readers", ("Reader",))
site.portal_urban.manage_addLocalRoles("housing_editors", ("Reader",))
site.portal_urban.manage_addLocalRoles("housing_readers", ("Reader",))

# application folders local roles
# global application folder : "urban_readers" and "urban_editors" can read...
Expand All @@ -755,6 +763,8 @@ def setDefaultApplicationSecurity(context):
app_folder.manage_addLocalRoles("urban_editors", ("Reader",))
app_folder.manage_addLocalRoles("environment_readers", ("Reader",))
app_folder.manage_addLocalRoles("environment_editors", ("Reader",))
app_folder.manage_addLocalRoles("housing_editors", ("Reader",))
app_folder.manage_addLocalRoles("housing_readers", ("Reader",))
# set some hardcoded permissions
# sharing is only managed by the 'Managers'
app_folder.manage_permission(
Expand Down Expand Up @@ -806,6 +816,8 @@ def setDefaultApplicationSecurity(context):
folder.manage_addLocalRoles("environment_editors", ("Contributor",))
if folder_name == getLicenceFolderId("Inspection"):
folder.manage_addLocalRoles("inspection_editors", ("Contributor",))
if folder_name == getLicenceFolderId("Housing"):
folder.manage_addLocalRoles("housing_editors", ("Contributor",))

# objects application folder : "urban_readers" can read and "urban_editors" can edit...
objectsfolder_names = ["architects", "geometricians", "notaries", "parcellings"]
Expand Down Expand Up @@ -836,6 +848,8 @@ def setDefaultApplicationSecurity(context):
folder.manage_addLocalRoles("environment_readers", ("Reader",))
folder.manage_addLocalRoles("environment_editors", ("Contributor",))
folder.manage_addLocalRoles("opinions_editors", ("Reader",))
folder.manage_addLocalRoles("housing_readers", ("Reader",))
folder.manage_addLocalRoles("housing_editors", ("Editor", "Contributor"))
# mark them with IContactFolder interface use some view methods, like 'getemails', on it
alsoProvides(folder, IContactFolder)

Expand Down Expand Up @@ -1975,6 +1989,8 @@ def set_licence_folder_security(urban_type, urban_folder=None):
urban_folder.manage_addLocalRoles("environment_editors", ("Contributor",))
if urban_type == "Inspection":
urban_folder.manage_addLocalRoles("inspection_editors", ("Contributor",))
if urban_type == "Housing":
urban_folder.manage_addLocalRoles("housing_editors", ("Contributor",))


def add_imio_dashboard(urban_type, urban_folder=None):
Expand Down
11 changes: 11 additions & 0 deletions src/Products/urban/workflows/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Products.urban.interfaces import IEnvironmentBase
from Products.urban.interfaces import IIntegratedLicence
from Products.urban.interfaces import IUniqueLicence
from Products.urban.interfaces import IHousing
from borg.localrole.interfaces import ILocalRoleProvider
from imio.schedule.config import DONE
from imio.schedule.config import STARTED
Expand Down Expand Up @@ -41,6 +42,8 @@ def __init__(self, context):
self.licence = self.context

def get_allowed_groups(self, licence):
if IHousing.providedBy(licence):
return "housing"
if (
IUniqueLicence.providedBy(licence)
or ICODT_UniqueLicence.providedBy(licence)
Expand Down Expand Up @@ -96,6 +99,10 @@ def get_editors(self):
"urban_editors",
"environment_editors",
],
"housing": [
"housing_editors",
"urban_editors",
]
}
allowed_group = self.get_allowed_groups(licence)
if allowed_group in mapping:
Expand All @@ -115,6 +122,10 @@ def get_readers(self):
"urban_readers",
"environment_readers",
],
"housing": [
"housing_readers",
"urban_readers",
]
}
allowed_group = self.get_allowed_groups(licence)
if allowed_group in mapping:
Expand Down
9 changes: 7 additions & 2 deletions src/Products/urban/workflows/opinionsrequest_workflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

from Products.urban.interfaces import IEnvironmentBase
from Products.urban.interfaces import IHousing
from Products.urban.workflows.adapter import LocalRoleAdapter
from collections import OrderedDict
from plone import api
Expand Down Expand Up @@ -33,15 +34,19 @@ def get_opinion_group(self, groupe_type="editors"):
elif groupe_type == "validators":
return (record["validator_group_id"],)

if IHousing.providedBy(self.licence):
return ("urban_editors", "housing_editors",)
return ("urban_editors", "environment_editors")

def get_editors(self):
if IHousing.providedBy(self.licence):
return ("housing_editors",)
if IEnvironmentBase.providedBy(self.licence):
return ("environment_editors",)
return ("urban_editors",)

def get_editors_roles(self):
if "urban_editors" in self.get_opinion_editor():
if "urban_editors" in self.get_opinion_editor() or "housing_editors" in self.get_opinion_editor():
return (
"Reader",
"Contributor",
Expand All @@ -56,7 +61,7 @@ def get_opinion_validator(self):

def get_opinion_editor_role(self):
groups = self.get_opinion_editor()
if "urban_editors" in groups:
if "urban_editors" in groups or "housing_editors" in groups:
return (
"Reader",
"Contributor",
Expand Down
11 changes: 11 additions & 0 deletions src/Products/urban/workflows/urbanevent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Products.urban.interfaces import IUniqueLicence
from Products.urban.interfaces import IUrbanAndEnvironmentEvent
from Products.urban.interfaces import IUrbanOrEnvironmentEvent
from Products.urban.interfaces import IHousing
from Products.urban.workflows.adapter import LocalRoleAdapter


Expand All @@ -19,6 +20,8 @@ def __init__(self, context):
self.licence = self.context.aq_parent

def get_allowed_groups(self, licence, event):
if IHousing.providedBy(licence):
return "housing"
integrated_licence = IIntegratedLicence.providedBy(licence)
if IEnvironmentBase.providedBy(licence) or integrated_licence:
if IUniqueLicence.providedBy(licence) or ICODT_UniqueLicence.providedBy(
Expand Down Expand Up @@ -55,6 +58,10 @@ def get_editors(self):
"urban_editors",
"environment_editors",
],
"housing": [
"housing_editors",
"urban_editors",
]
}
allowed_group = self.get_allowed_groups(licence, event)
if allowed_group in mapping:
Expand All @@ -75,6 +82,10 @@ def get_readers(self):
"urban_readers",
"environment_readers",
],
"housing": [
"housing_readers",
"urban_readers",
]
}
allowed_group = self.get_allowed_groups(licence, event)
if allowed_group in mapping:
Expand Down