Added helper to get edit permission for any object
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Apr 2018 11:02:32 +0200
changeset 95 aafae25003ba
parent 94 2c4e369472fb
child 96 777ba7b212fe
Added helper to get edit permission for any object
src/pyams_form/security.py
--- a/src/pyams_form/security.py	Wed Apr 11 11:02:00 2018 +0200
+++ b/src/pyams_form/security.py	Wed Apr 11 11:02:32 2018 +0200
@@ -22,6 +22,18 @@
 from pyramid.decorator import reify
 
 
+def get_edit_permission(request, context=None):
+    """Get required edit permission"""
+    if context is None:
+        context = request.context
+    registry = request.registry
+    checker = registry.queryMultiAdapter((context, request), IFormContextPermissionChecker)
+    if checker is None:
+        checker = registry.queryAdapter(context, IFormContextPermissionChecker)
+    if checker is not None:
+        return checker.edit_permission
+
+
 class ProtectedFormObjectMixin(object):
     """Form object protected by a permission"""