Added Permission and PermissionsSet fields
authorThierry Florac <thierry.florac@onf.fr>
Mon, 20 Apr 2015 09:50:51 +0200
changeset 32 5b6650d040c2
parent 31 862bed30e85b
child 33 c422e7f61f19
Added Permission and PermissionsSet fields
src/pyams_security/schema.py
--- a/src/pyams_security/schema.py	Fri Apr 17 14:55:45 2015 +0200
+++ b/src/pyams_security/schema.py	Mon Apr 20 09:50:51 2015 +0200
@@ -16,11 +16,39 @@
 # import standard library
 
 # import interfaces
-from zope.schema.interfaces import ITextLine, ISet
+from zope.schema.interfaces import ITextLine, IChoice, ISet
 
 # import packages
 from zope.interface import implementer, Interface
-from zope.schema import TextLine, Set
+from zope.schema import TextLine, Choice, Set
+
+
+class IPermissionField(IChoice):
+    """Permission field interface"""
+
+
+@implementer(IPermissionField)
+class PermissionField(Choice):
+    """Permission field"""
+
+    def __init__(self, **kwargs):
+        if 'vocabulary' in kwargs:
+            del kwargs['vocabulary']
+        super(PermissionField, self).__init__(vocabulary='PyAMS permissions', **kwargs)
+
+
+class IPermissionsSetField(ISet):
+    """Permissions set field interface"""
+
+
+@implementer(IPermissionsSetField)
+class PermissionsSetField(Set):
+    """Permissions set field"""
+
+    def __init__(self, **kwargs):
+        if 'value_type'in kwargs:
+            del kwargs['value_type']
+        super(PermissionsSetField, self).__init__(value_type=PermissionField(), **kwargs)
 
 
 class IRoleField(Interface):