From 328f8803efb9b3062f6fed60381807caf527a5b6 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 9 Feb 2024 17:11:10 +0100 Subject: [PATCH] fix upgrade-step, remote unused user action and add actions to @feedbacks endpoint --- CHANGES.rst | 4 +++ src/collective/feedback/configure.zcml | 10 ++++++- src/collective/feedback/permissions.zcml | 9 +++++-- .../feedback/profiles/default/actions.xml | 27 ------------------- .../feedback/profiles/default/metadata.xml | 2 +- .../feedback/profiles/default/rolemap.xml | 8 +++++- .../profiles/default/to_1100/rolemap.xml | 6 +++++ .../feedback/restapi/services/configure.zcml | 2 +- .../feedback/restapi/services/get.py | 4 +++ src/collective/feedback/setuphandlers.py | 1 + .../feedback/tests/test_feedbacks_get.py | 24 +++++++++++++++++ src/collective/feedback/upgrades.py | 5 ++++ 12 files changed, 69 insertions(+), 33 deletions(-) delete mode 100644 src/collective/feedback/profiles/default/actions.xml create mode 100644 src/collective/feedback/profiles/default/to_1100/rolemap.xml diff --git a/CHANGES.rst b/CHANGES.rst index 4e185a3..6d65af8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ------------------ diff --git a/src/collective/feedback/configure.zcml b/src/collective/feedback/configure.zcml index fa1ec55..5e3e5f4 100644 --- a/src/collective/feedback/configure.zcml +++ b/src/collective/feedback/configure.zcml @@ -9,10 +9,10 @@ + - + + + + diff --git a/src/collective/feedback/profiles/default/actions.xml b/src/collective/feedback/profiles/default/actions.xml deleted file mode 100644 index 75411c0..0000000 --- a/src/collective/feedback/profiles/default/actions.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - Feedback dashboard - string:${globals_view/navigationRootUrl}/feedback-dashboard - - - - - - True - - - - diff --git a/src/collective/feedback/profiles/default/metadata.xml b/src/collective/feedback/profiles/default/metadata.xml index 7640786..37cad1a 100644 --- a/src/collective/feedback/profiles/default/metadata.xml +++ b/src/collective/feedback/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 1000 + 1100 profile-plone.restapi:default profile-souper.plone:default diff --git a/src/collective/feedback/profiles/default/rolemap.xml b/src/collective/feedback/profiles/default/rolemap.xml index 701d996..cfdb62b 100644 --- a/src/collective/feedback/profiles/default/rolemap.xml +++ b/src/collective/feedback/profiles/default/rolemap.xml @@ -3,7 +3,7 @@ @@ -20,5 +20,11 @@ + + + + + + diff --git a/src/collective/feedback/profiles/default/to_1100/rolemap.xml b/src/collective/feedback/profiles/default/to_1100/rolemap.xml new file mode 100644 index 0000000..1bad339 --- /dev/null +++ b/src/collective/feedback/profiles/default/to_1100/rolemap.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/collective/feedback/restapi/services/configure.zcml b/src/collective/feedback/restapi/services/configure.zcml index 6e84c4e..c80e9b3 100644 --- a/src/collective/feedback/restapi/services/configure.zcml +++ b/src/collective/feedback/restapi/services/configure.zcml @@ -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" /> diff --git a/src/collective/feedback/restapi/services/get.py b/src/collective/feedback/restapi/services/get.py index dc7a7fa..1cdd527 100644 --- a/src/collective/feedback/restapi/services/get.py +++ b/src/collective/feedback/restapi/services/get.py @@ -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 diff --git a/src/collective/feedback/setuphandlers.py b/src/collective/feedback/setuphandlers.py index e923759..f77ff3f 100644 --- a/src/collective/feedback/setuphandlers.py +++ b/src/collective/feedback/setuphandlers.py @@ -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): diff --git a/src/collective/feedback/tests/test_feedbacks_get.py b/src/collective/feedback/tests/test_feedbacks_get.py index 5f565e6..c283acb 100644 --- a/src/collective/feedback/tests/test_feedbacks_get.py +++ b/src/collective/feedback/tests/test_feedbacks_get.py @@ -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"]) diff --git a/src/collective/feedback/upgrades.py b/src/collective/feedback/upgrades.py index bbdc324..757c8b4 100644 --- a/src/collective/feedback/upgrades.py +++ b/src/collective/feedback/upgrades.py @@ -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"]