Skip to content

Commit

Permalink
Permissions fix (#106)
Browse files Browse the repository at this point in the history
* Fix bookings manager permissions

* Permission fixes

* Refactor

* Update upgrades.py

* Refactoring

* Refactor
  • Loading branch information
folix-01 authored Oct 20, 2023
1 parent 16d3cd8 commit 3115bd4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Changelog
- Change bookings default limit to 0.
[folix-01]

- Fix Bookings Manager permission in according to expected behavior
[folix-01]

- Add booking_refuse_message to Prenotazione stringinterp variables.
[folix-01]

Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/prenotazioni/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<version>1807</version>
<version>1808</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-collective.z3cform.datagridfield:default</dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/redturtle/prenotazioni/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<role name="Bookings Manager" />
</roles>

<permissions>

<permissions>
<permission name="redturtle.prenotazioni: Add Prenotazione" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<permission>Access contents information</permission>
<permission>Modify portal content</permission>
<permission>View</permission>
<permission>redturtle.prenotazioni: Manage Prenotazioni</permission>
<state state_id="pending" title="In attesa">
<description>Waiting to be reviewed, not editable by the owner and not visible</description>
<exit-transition transition_id="confirm"/>
Expand All @@ -13,17 +14,25 @@
<permission-role>Manager</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Modify portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="View" acquired="False">
<permission-role>Owner</permission-role>
<permission-role>Editor</permission-role>
<permission-role>Manager</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Review portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
</state>
<state state_id="private" title="Private">
Expand All @@ -35,19 +44,27 @@
<permission-role>Manager</permission-role>
<permission-role>Owner</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Modify portal content" acquired="False">
<permission-role>Anonymous</permission-role>
<permission-role>Editor</permission-role>
<permission-role>Manager</permission-role>
<permission-role>Owner</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="View" acquired="False">
<permission-role>Anonymous</permission-role>
<permission-role>Editor</permission-role>
<permission-role>Manager</permission-role>
<permission-role>Owner</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Review portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
</state>
<state state_id="confirmed" title="Confermato">
Expand All @@ -58,17 +75,25 @@
<permission-role>Manager</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Modify portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="View" acquired="False">
<permission-role>Owner</permission-role>
<permission-role>Editor</permission-role>
<permission-role>Manager</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Review portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
</state>
<state state_id="refused" title="Rifiutato">
Expand All @@ -79,17 +104,25 @@
<permission-role>Owner</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Modify portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="View" acquired="False">
<permission-role>Editor</permission-role>
<permission-role>Manager</permission-role>
<permission-role>Owner</permission-role>
<permission-role>Reader</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
<permission-map name="Review portal content" acquired="False">
<permission-role>Manager</permission-role>
<permission-role>Reviewer</permission-role>
<permission-role>Bookings Manager</permission-role>
</permission-map>
</state>
<transition transition_id="confirm" title="Conferma" new_state="confirmed" trigger="USER" before_script="" after_script="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def reply(self):
)()
for i in api.portal.get_tool("portal_catalog")(**query)
]

response["items_total"] = len(response["items"])

return response
Expand Down
24 changes: 18 additions & 6 deletions src/redturtle/prenotazioni/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def update_sharing(context):
update_profile(context, "sharing")


def update_workflow(context):
update_profile(context, "workflow")


def reload_gs_profile(context):
loadMigrationProfile(
context,
Expand Down Expand Up @@ -376,7 +380,7 @@ def to_1700(context):
setattr(prenotazione, field, date.astimezone(tz))


def to_1800(self):
def to_1800(context):
brains = api.content.find(portal_type="PrenotazioniFolder")
for brain in brains:
item = brain.getObject()
Expand All @@ -388,7 +392,7 @@ def to_1800(self):
)


def update_booking_code(self):
def update_booking_code(context):
brains = api.content.find(portal_type="Prenotazione")
for brain in brains:
item = brain.getObject()
Expand All @@ -400,15 +404,15 @@ def update_booking_code(self):
)


def to_1804(self):
def to_1804(context):
for brain in api.portal.get_tool("portal_catalog")(
portal_type="PrenotazioniFolder"
):
logger.info("Updating <{UID}>.max_bookings_allowed=2".format(UID=brain.UID))
brain.getObject().max_bookings_allowed = 2


def to_1805(self):
def to_1805(context):
from plone.app.textfield.value import RichTextValue

for brain in api.portal.get_tool("portal_catalog")(
Expand All @@ -428,7 +432,7 @@ def to_1805(self):
)


def to_1806(self):
def to_1806(context):
for brain in api.portal.get_tool("portal_catalog")(
portal_type="PrenotazioniFolder"
):
Expand All @@ -439,7 +443,7 @@ def to_1806(self):
type["hidden"] = False


def to_1807(self):
def to_1807(context):
for brain in api.portal.get_tool("portal_catalog")(
portal_type="PrenotazioniFolder"
):
Expand All @@ -452,3 +456,11 @@ def to_1807(self):
logger.info(
"Upgraded <{UID}>.notify_on_refuse_message value".format(UID=brain.UID)
)


def to_1808(context):
api.portal.get_tool("portal_workflow").updateRoleMappings()

for brain in api.content.find(portal_type="Prenotazione"):
brain.getObject().reindexObjectSecurity()
logger.info("Upgraded <{UID}> security settings".format(UID=brain.UID))
14 changes: 14 additions & 0 deletions src/redturtle/prenotazioni/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,18 @@
handler=".upgrades.to_1807"
/>
</genericsetup:upgradeSteps>
<genericsetup:upgradeSteps
profile="redturtle.prenotazioni:default"
source="1807"
destination="1808"
>
<genericsetup:upgradeStep
title="Upgrade workflow policy"
handler=".upgrades.update_workflow"
/>
<genericsetup:upgradeStep
title="Upgrade prenotazione security in according to new workflow rules"
handler=".upgrades.to_1808"
/>
</genericsetup:upgradeSteps>
</configure>

0 comments on commit 3115bd4

Please sign in to comment.