Skip to content

Commit

Permalink
Fix rolemap
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Sep 4, 2023
1 parent bf1a824 commit e256848
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 227 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

149 changes: 79 additions & 70 deletions src/redturtle/prenotazioni/locales/redturtle.prenotazioni.pot

Large diffs are not rendered by default.

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>1800</version>
<version>1801</version>
<dependencies>
<dependency>profile-plone.app.dexterity:default</dependency>
<dependency>profile-collective.z3cform.datagridfield:default</dependency>
Expand Down
21 changes: 16 additions & 5 deletions src/redturtle/prenotazioni/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
@@ -1,52 +1,63 @@
<?xml version="1.0"?>
<rolemap>
<roles>
<role name="Bookings Manager" />
</roles>

<permissions>

<permission name="redturtle.prenotazioni: Add Prenotazione" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Owner"/>
<role name="Bookings Manager" />
<role name="Contributor"/>
</permission>

<permission name="redturtle.prenotazioni: Add PrenotazioniDay" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Owner"/>
<role name="Contributor"/>
<role name="Bookings Manager" />
</permission>

<permission name="redturtle.prenotazioni: Add PrenotazioniWeek" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Owner"/>
<role name="Contributor"/>
<role name="Bookings Manager" />
</permission>

<permission name="redturtle.prenotazioni: Add PrenotazioniYear" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Owner"/>
<role name="Contributor"/>
<role name="Bookings Manager" />
</permission>

<permission name="redturtle.prenotazioni: Add PrenotazioniFolder" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Owner"/>
<role name="Contributor"/>
<role name="Bookings Manager" />
</permission>

<permission name="redturtle.prenotazioni: search prenotazioni" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Contributor"/>
<role name="Bookings Manager" />
</permission>

<permission name="redturtle.prenotazioni: Manage Prenotazioni" acquire="True">
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Bookings Manager" />
</permission>

</permissions>
</rolemap>
9 changes: 9 additions & 0 deletions src/redturtle/prenotazioni/profiles/default/sharing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<sharing xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="redturtle.prenotazioni">
<role
id="Bookings Manager"
title="Can Manage Bookings"
permission="Manage portal"
i18n:attributes="title"
/>
</sharing>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def query(self):

if api.user.is_anonymous():
raise Unauthorized("You must be logged in to perform this action")
elif api.user.has_permission("redturtle.prenotazioni: search prenotazioni"):
elif api.user.has_permission(
"redturtle.prenotazioni: search prenotazioni", obj=self.context
):
userid = self.request.get("userid", None)
else:
userid = api.user.get_current().getUserId()
Expand Down
44 changes: 34 additions & 10 deletions src/redturtle/prenotazioni/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from plone.app.contentrules.actions.workflow import WorkflowAction
from plone.app.contentrules.conditions.portaltype import PortalTypeCondition
from plone.app.contentrules.conditions.wfstate import WorkflowStateCondition
from plone.app.contentrules.conditions.wftransition import WorkflowTransitionCondition
from plone.app.contentrules.conditions.wftransition import (
WorkflowTransitionCondition,
)
from plone.app.event.base import default_timezone
from plone.app.upgrade.utils import loadMigrationProfile
from plone.app.workflow.remap import remap_workflow
Expand Down Expand Up @@ -56,6 +58,10 @@ def update_contentrules(context):
update_profile(context, "contentrules")


def update_sharing(context):
update_profile(context, "sharing")


def reload_gs_profile(context):
loadMigrationProfile(
context,
Expand Down Expand Up @@ -148,13 +154,19 @@ def to_1400(context):
)

for portal_type_condition in portal_type_conditions:
if "Prenotazione" in getattr(portal_type_condition, "check_types", []):
for workflow_transition_condition in workflow_transition_conditions:
if "Prenotazione" in getattr(
portal_type_condition, "check_types", []
):
for (
workflow_transition_condition
) in workflow_transition_conditions:
if isinstance(
workflow_transition_condition,
WorkflowTransitionCondition,
):
wf_states = list(workflow_transition_condition.wf_transitions)
wf_states = list(
workflow_transition_condition.wf_transitions
)

if "publish" in wf_states:
wf_states.remove("publish")
Expand All @@ -165,7 +177,9 @@ def to_1400(context):
)

for workflow_state_condition in workflow_state_conditions:
if isinstance(workflow_state_condition, WorkflowStateCondition):
if isinstance(
workflow_state_condition, WorkflowStateCondition
):
wf_states = list(workflow_state_condition.wf_states)

if "publish" in wf_states:
Expand Down Expand Up @@ -201,13 +215,17 @@ def to_1401(context):

def to_1402(context):
# load new content rules
context.runImportStepFromProfile(CONTENT_RULES_EVOLUTION_PROFILE, "contentrules")
context.runImportStepFromProfile(
CONTENT_RULES_EVOLUTION_PROFILE, "contentrules"
)


def to_1403(context):
update_catalog(context)

for brain in api.portal.get_tool("portal_catalog")(portal_type="Prenotazione"):
for brain in api.portal.get_tool("portal_catalog")(
portal_type="Prenotazione"
):
brain.getObject().reindexObject(idxs=["fiscalcode"])


Expand All @@ -220,7 +238,9 @@ def to_1500(context):
def to_1502(context):
update_catalog(context)

for brain in api.portal.get_tool("portal_catalog")(portal_type="Prenotazione"):
for brain in api.portal.get_tool("portal_catalog")(
portal_type="Prenotazione"
):
logger.info(f"[ 1500 - 1501 ] - Rindexing <{brain.getPath()}>")
brain.getObject().reindexObject(idxs=["booking_type"])

Expand Down Expand Up @@ -342,7 +362,9 @@ def to_1600_upgrade_contentrules(context):


def to_1601(context):
for brain in api.portal.get_tool("portal_catalog")(portal_type="Prenotazione"):
for brain in api.portal.get_tool("portal_catalog")(
portal_type="Prenotazione"
):
brain.getObject().reindexObject(idxs=["SearchableText"])


Expand Down Expand Up @@ -374,7 +396,9 @@ def to_1800(self):
brains = api.content.find(portal_type="PrenotazioniFolder")
for brain in brains:
item = brain.getObject()
same_day_booking_disallowed = getattr(item, "same_day_booking_disallowed", None)
same_day_booking_disallowed = getattr(
item, "same_day_booking_disallowed", None
)
if same_day_booking_disallowed not in ("yes", "no"):
item.same_day_booking_disallowed = "no"
logger.info(
Expand Down
14 changes: 14 additions & 0 deletions src/redturtle/prenotazioni/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,19 @@
handler=".upgrades.to_1800"
/>

</genericsetup:upgradeSteps>
<genericsetup:upgradeSteps
profile="redturtle.prenotazioni:default"
source="1800"
destination="1801"
>
<genericsetup:upgradeStep
title="Update rolemap"
handler=".upgrades.update_rolemap"
/>
<genericsetup:upgradeStep
title="Update sharing"
handler=".upgrades.update_sharing"
/>
</genericsetup:upgradeSteps>
</configure>

0 comments on commit e256848

Please sign in to comment.