-
-
Notifications
You must be signed in to change notification settings - Fork 25
Description
The default edit form for dexterity content is only protected by a view permission setting in ZCML with the Modify portal content
permission. There is no additional check on the form itself before new data is applied to the content.
Individual field permissions applied to a schema are checked by the tagged value settings of plone.autoform.utils
, but fields without a specific read or write permission are ignored.
There is aDXFieldPermissionChecker
(using Modify portal content
as default permission), but it is only called and used for the vocabulary view for AJAX requests.
Adding a permission check in the DefaultEditForm
would help to secure the write operation:
class DefaultEditForm(DexterityExtensibleForm, form.EditForm):
success_message = _(u"Changes saved")
DEFAULT_PERMISSION = 'Modify portal content'
@button.buttonAndHandler(_(u'Save'), name='save')
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
# Additional check start
checker = getSecurityManager().checkPermission
if not checker(self.DEFAULT_PERMISSION, self.context):
raise Unauthorized()
# Additional check end
self.applyChanges(data)
IStatusMessage(self.request).addStatusMessage(
self.success_message, "info"
)
self.request.response.redirect(self.nextURL())
notify(EditFinishedEvent(self.context))
def update(self):
self.portal_type = self.context.portal_type
super(DefaultEditForm, self).update()
# Additional check start
checker = getSecurityManager().checkPermission
if not checker(self.DEFAULT_PERMISSION, self.context):
raise Unauthorized()
# Additional check end
# fire the edit begun only if no action was executed
if len(self.actions.executedActions) == 0:
notify(EditBegunEvent(self.context))
If someone needs to customize the default edit form and requires a different permission, the DEFAULT_PERMISSION
can be adjusted as well:
class MyCustomEditForm(DefaultEditForm):
DEFAULT_PERMISSION = 'My custom permission'