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
- Setup Plone 6.x and collective.easyform 4.2.0
- Create easyform named
my-easyform & publish
- 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):
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
my-easyform& publishcurl -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):inserializer.pyinto a try-except-block. If theInvalidParameterErrorexception is thrown, we know the user does not have this permission.Variant B
Instead of using
'collective.easyform.DownloadSavedInput'(viaDOWNLOAD_SAVED_PERMISSION) we can use'collective.easyform: Download Saved Input'. For reasons I dont understand this solves the issue: