Skip to content

Commit

Permalink
fix upgrade-step, remote unused user action and add actions to @feedb…
Browse files Browse the repository at this point in the history
…acks endpoint
  • Loading branch information
cekk committed Feb 9, 2024
1 parent 853032d commit 328f880
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Changelog
[cekk]
- Install souper.plone to have its control-panel in backend.
[cekk]
- Remove unused user action.
[cekk]
- Add `actions` infos in @feedback endpoint, to let the frontend know what the user can do.
[cekk]

1.0.0 (2023-02-16)
------------------
Expand Down
10 changes: 9 additions & 1 deletion src/collective/feedback/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<i18n:registerTranslations directory="locales" />

<include file="permissions.zcml" />
<include file="upgrades.zcml" />

<include package=".storage" />
<include package=".restapi" />
<include package=".upgrades" />


<genericsetup:registerProfile
Expand All @@ -33,6 +33,14 @@
post_handler=".setuphandlers.uninstall"
/>

<genericsetup:registerProfile
name="to_1100"
title="collective.feedback (to_1100)"
description=""
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/to_1100"
/>

<utility
factory=".setuphandlers.HiddenProfiles"
name="collective.feedback-hiddenprofiles"
Expand Down
9 changes: 7 additions & 2 deletions src/collective/feedback/permissions.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<configure zcml:condition="installed AccessControl.security">
<permission
id="collective.feedback.ManageFeedbacks"
title="collective.feedback: Manage Feedbacks"
id="collective.feedback.DeleteFeedbacks"
title="collective.feedback: Delete Feedbacks"
/>
<permission
id="collective.feedback.AccessFeedbacks"
Expand All @@ -17,6 +17,11 @@
id="collective.feedback.FeedbacksOverview"
title="collective.feedback: Feedbacks Overview"
/>
<permission
id="collective.feedback.ShowDeletedFeedbacks"
title="collective.feedback: Show Deleted Feedbacks"
/>

</configure>

</configure>
27 changes: 0 additions & 27 deletions src/collective/feedback/profiles/default/actions.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/collective/feedback/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>1000</version>
<version>1100</version>
<dependencies>
<dependency>profile-plone.restapi:default</dependency>
<dependency>profile-souper.plone:default</dependency>
Expand Down
8 changes: 7 additions & 1 deletion src/collective/feedback/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<permissions>

<permission acquire="True"
name="collective.feedback: Manage Feedbacks"
name="collective.feedback: Delete Feedbacks"
>
<role name="Manager" />
<role name="Site Administrator" />
Expand All @@ -20,5 +20,11 @@
<permission acquire="True" name="collective.feedback: Feedbacks Overview">
<role name="Authenticated" />
</permission>

<permission acquire="True" name="collective.feedback: Show Deleted Feedbacks">
<role name="Manager" />
<role name="Site Administrator" />
</permission>

</permissions>
</rolemap>
6 changes: 6 additions & 0 deletions src/collective/feedback/profiles/default/to_1100/rolemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<rolemap>
<permissions>
<permission remove="True" name="collective.feedback: Manage Feedbacks" />
</permissions>
</rolemap>
2 changes: 1 addition & 1 deletion src/collective/feedback/restapi/services/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
method="DELETE"
factory=".delete.FeedbackDelete"
for="plone.app.layout.navigation.interfaces.INavigationRoot"
permission="collective.feedback.ManageFeedbacks"
permission="collective.feedback.DeleteFeedbacks"
layer="collective.feedback.interfaces.ICollectiveFeedbackLayer"
name="@feedback-delete"
/>
Expand Down
4 changes: 4 additions & 0 deletions src/collective/feedback/restapi/services/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ def reply(self):
if links:
data["batching"] = links

data["actions"] = {"can_delete_feedbacks": self.can_delete_feedbacks()}
return data

def can_delete_feedbacks(self):
return api.user.has_permission("collective.feedback: Delete Feedbacks")

def fix_fields(self, data):
"""
Make data json compatible
Expand Down
1 change: 1 addition & 0 deletions src/collective/feedback/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def getNonInstallableProfiles(self):
"""Hide uninstall profile from site-creation and quickinstaller."""
return [
"collective.feedback:uninstall",
"collective.feedback:to_1100",
]

def getNonInstallableProducts(self):
Expand Down
24 changes: 24 additions & 0 deletions src/collective/feedback/tests/test_feedbacks_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,27 @@ def test_only_admins_can_see_deleted_contents(self):
res = response.json()

self.assertEqual(res["items_total"], 1)

def test_actions_list_returned(self):
response = self.api_session.get(self.url)
res = response.json()
self.assertIn("actions", res)

def test_users_with_permission_have_can_delete_feedbacks_action(self):

response = self.api_session.get(self.url)
res = response.json()
self.assertIn("can_delete_feedbacks", res["actions"])
self.assertTrue(res["actions"]["can_delete_feedbacks"])

def test_users_without_permission_dont_have_can_delete_feedbacks_action(self):

api_session = RelativeSession(self.portal_url)
api_session.headers.update({"Accept": "application/json"})
api_session.auth = ("global", "secret!!")

response = api_session.get(self.url)
res = response.json()

self.assertIn("can_delete_feedbacks", res["actions"])
self.assertFalse(res["actions"]["can_delete_feedbacks"])
5 changes: 5 additions & 0 deletions src/collective/feedback/upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ def update_controlpanel(context):

def to_1100(context):
installOrReinstallProduct(api.portal.get(), "souper.plone")
context.runAllImportStepsFromProfile("profile-collective.feedback:to_1100")

# remove broken action
if "feedback-dashboard" in context.portal_actions.user:
del context.portal_actions.user["feedback-dashboard"]

0 comments on commit 328f880

Please sign in to comment.