Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URB-3165: Remove permission to create integrated licences #266

Open
wants to merge 1 commit into
base: urban2.7.x
Choose a base branch
from
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/URB-3165.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove permission to create integrated licences
[daggelpop]
21 changes: 21 additions & 0 deletions src/Products/urban/migration/update_270.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ def rename_patrimony_certificate(context):
patrimony_config_folder.reindexObject(["Title"])

logger.info("upgrade step done!")


def remove_permission_to_create_integrated_licences(context):
logger = logging.getLogger("urban: remove permission to create integrated licences")
logger.info("starting upgrade step")

portal = api.portal.get()
codt_integratedlicences_folder = getattr(portal.urban, "codt_integratedlicences")
if not codt_integratedlicences_folder:
logger.error("couldn't find codt_integratedlicences folder, aborting!")
return

for principal_id, roles in codt_integratedlicences_folder.get_local_roles():
if "Contributor" in roles:
remaining_roles = tuple(set(roles).difference(["Contributor"]))
codt_integratedlicences_folder.manage_delLocalRoles([principal_id])
if remaining_roles:
codt_integratedlicences_folder.manage_addLocalRoles(principal_id, remaining_roles)

codt_integratedlicences_folder.reindexObjectSecurity()
logger.info("upgrade step done!")
9 changes: 9 additions & 0 deletions src/Products/urban/migration/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,13 @@
profile="Products.urban:default"
/>

<gs:upgradeStep
title="Remove permission to create integrated licences"
description=""
source="1150"
destination="1151"
handler=".update_270.remove_permission_to_create_integrated_licences"
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>1150</version>
<version>1151</version>
<dependencies>
<dependency>profile-Products.urban:preinstall</dependency>
</dependencies>
Expand Down
23 changes: 13 additions & 10 deletions src/Products/urban/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,12 @@ def setDefaultApplicationSecurity(context):
folder.manage_delLocalRoles(["environment_editors"])
if folder_name in urban_folder_names:
folder.manage_addLocalRoles("urban_readers", ("Reader",))
folder.manage_addLocalRoles("urban_editors", ("Contributor",))
if folder_name != getLicenceFolderId("CODT_IntegratedLicence"):
folder.manage_addLocalRoles("urban_editors", ("Contributor",))
if folder_name in environment_folder_names:
folder.manage_addLocalRoles("environment_readers", ("Reader",))
folder.manage_addLocalRoles("environment_editors", ("Contributor",))
if folder_name != getLicenceFolderId("CODT_IntegratedLicence"):
folder.manage_addLocalRoles("environment_editors", ("Contributor",))
if folder_name == getLicenceFolderId("Inspection"):
folder.manage_addLocalRoles("inspection_editors", ("Contributor",))

Expand Down Expand Up @@ -1004,14 +1006,15 @@ def addApplicationFolders(context):
setFolderAllowedTypes(licence_folder, urban_type)
# manage the 'Add' permissions...
try:
licence_folder.manage_permission(
"urban: Add %s" % urban_type,
[
"Manager",
"Contributor",
],
acquire=0,
)
if urban_type != "CODT_IntegratedLicence":
licence_folder.manage_permission(
"urban: Add %s" % urban_type,
[
"Manager",
"Contributor",
],
acquire=0,
)
except ValueError:
# exception for some portal_types having a different meta_type
if urban_type in [
Expand Down