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

SerializeToJson: Cannot find a permission with name 'collective.easyform.DownloadSavedInput' #431

Open
mbarde opened this issue Oct 1, 2024 · 1 comment
Labels

Comments

@mbarde
Copy link

mbarde commented Oct 1, 2024

Serializer throws this error (plone.api.exc.InvalidParameterError: Cannot find a permission with name 'collective.easyform.DownloadSavedInput') when you try to retrieve an Easyform via the REST-API with an unauthenticated user or as an user who does not have this permission.

Reproduce

  1. Setup Plone 6.x and collective.easyform 4.2.0
  2. Create easyform named my-easyform & publish
  3. Retrieve it via REST-API (curl -i -X GET http://localhost:8080/Plone/my-easyform -H "Accept: application/json")

Possible solutions

Variant A

Wrap if api.user.has_permission(DOWNLOAD_SAVED_PERMISSION, obj=self.context): in serializer.py into a try-except-block. If the InvalidParameterError exception is thrown, we know the user does not have this permission.

Variant B

Instead of using 'collective.easyform.DownloadSavedInput' (via DOWNLOAD_SAVED_PERMISSION) we can use 'collective.easyform: Download Saved Input'. For reasons I dont understand this solves the issue:

if api.user.has_permission('collective.easyform: Download Saved Input', obj=self.context):
@mbarde mbarde added the bug label Oct 1, 2024
@davisagli
Copy link
Member

Each permission has an id (collective.easyform.DownloadSavedInput) and a title (collective.easyform: Download Saved Input). plone.api.user.has_permission checks the permission in a way that uses the title. So probably variant B is the better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants