Added form field permission checker
authortflorac@dagon.home
Mon, 02 Jul 2018 22:59:44 +0200
changeset 788 88c885042341
parent 787 93f9a8b859fc
child 789 7c0f6dfc6387
Added form field permission checker
src/pyams_content/shared/form/field.py
--- a/src/pyams_content/shared/form/field.py	Mon Jul 02 18:33:03 2018 +0200
+++ b/src/pyams_content/shared/form/field.py	Mon Jul 02 22:59:44 2018 +0200
@@ -17,8 +17,9 @@
 from collections import OrderedDict
 
 # import interfaces
-from pyams_content.shared.form.interfaces import IFormFieldFactory, IFormField, IFormFieldContainer, \
+from pyams_content.shared.form.interfaces import IWfForm, IFormFieldFactory, IFormField, IFormFieldContainer, \
     IFormFieldContainerTarget, FORM_FIELD_CONTAINER_KEY
+from pyams_form.interfaces.form import IFormContextPermissionChecker
 from pyams_i18n.interfaces import II18n
 from zope.location.interfaces import ISublocations
 from zope.traversing.interfaces import ITraversable
@@ -29,6 +30,7 @@
 from pyams_utils.registry import utility_config, get_global_registry
 from pyams_utils.request import check_request
 from pyams_utils.schema import MailAddressField
+from pyams_utils.traversing import get_parent
 from pyams_utils.vocabulary import vocabulary_config
 from zope.container.contained import Contained
 from zope.container.ordered import OrderedContainer
@@ -55,6 +57,13 @@
     visible = FieldProperty(IFormField['visible'])
 
 
+@adapter_config(context=IFormField, provides=IFormContextPermissionChecker)
+def form_field_permission_checker(context):
+    """Form field permission checker"""
+    form = get_parent(context, IWfForm)
+    return IFormContextPermissionChecker(form)
+
+
 @implementer(IFormFieldContainer)
 class FormFieldContainer(OrderedContainer):
     """Form fields container persistent class"""