[Zope3-checkins] CVS: Zope3/src/zope/app/utilities - configure.zcml:1.1.2.4 schema.py:1.1.2.7

Sidnei da Silva sidnei at x3ng.com.br
Wed Aug 13 11:42:53 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/utilities
In directory cvs.zope.org:/tmp/cvs-serv8242/src/zope/app/utilities

Modified Files:
      Tag: dreamcatcher-ttwschema-branch
	configure.zcml schema.py 
Log Message:
Half-workiing schemaPermissions plus some whitespace here and there

=== Zope3/src/zope/app/utilities/configure.zcml 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zope/app/utilities/configure.zcml:1.1.2.3	Wed Aug 13 09:51:18 2003
+++ Zope3/src/zope/app/utilities/configure.zcml	Wed Aug 13 10:42:18 2003
@@ -20,8 +20,7 @@
   </browser:view>
 
 
-  <content
-    class=".schema.SchemaUtility">
+  <content class=".schema.SchemaUtility">
 
     <factory
       permission="zope.ManageServices"
@@ -42,6 +41,7 @@
 
     <require
       permission="zope.ManageServices"
+      interface="zope.app.interfaces.utilities.ISchemaUtility"
       set_schema="zope.app.interfaces.utilities.ISchemaUtility"
       />
 
@@ -83,7 +83,7 @@
 
 
   <browser:defaultView
-      for="zope.app.interfaces.utilities.IMutableSchema" 
+      for="zope.app.interfaces.utilities.IMutableSchema"
       name="editschema.html" />
 
   <browser:page
@@ -94,6 +94,15 @@
       class="zope.app.utilities.schema.EditSchema"
       attribute="edit"
    />
+
+  <browser:editform
+      schema="zope.app.interfaces.utilities.IMutableSchema"
+      name="editpermissions.html"
+      template="permission_edit.pt"
+      class=".schema.MutableSchemaPermsEdit"
+      menu="zmi_views" title="Schema Permissions"
+      label="Schema Permissions"
+      permission="zope.ManageContent"/>
 
 
   <!-- Widgets for the MutableSchemaField -->


=== Zope3/src/zope/app/utilities/schema.py 1.1.2.6 => 1.1.2.7 ===
--- Zope3/src/zope/app/utilities/schema.py:1.1.2.6	Wed Aug 13 10:01:11 2003
+++ Zope3/src/zope/app/utilities/schema.py	Wed Aug 13 10:42:18 2003
@@ -32,6 +32,7 @@
 from zope.interface import implements
 from zope.publisher.browser import BrowserView
 from zope.schema import getFieldsInOrder, getFieldNamesInOrder
+from persistence.dict import PersistentDict
 
 class SchemaUtility(PersistentInterfaceClass):
 
@@ -39,6 +40,7 @@
 
     def __init__(self):
         super(SchemaUtility, self).__init__('', (PersistentInterface,))
+        self.schemaPermissions = PersistentDict()
 
     def setName(self, name):
         """See zope.app.interfaces.utilities.IMutableSchema"""
@@ -155,6 +157,69 @@
 
         self.update_status = status
         return status
+
+
+class MutableSchemaPermsEdit(EditView):
+
+    def __init__(self, context, request):
+        super(MutableSchemaPermsEdit, self).__init__(context, request)
+        self.buildPermissionWidgets()
+
+    def buildPermissionWidgets(self):
+        schema = self.context
+        for name, field in getFieldsInOrder(schema):
+            # Try to get current settings
+            if not hasattr(self.context, 'schemaPermissions'):
+                self.context.schemaPermissions = PersistentDict()
+            if self.context.schemaPermissions.has_key(name):
+                get_perm, set_perm = self.context.schemaPermissions[name]
+            else:
+                get_perm, set_perm = None, None
+
+            # Create the Accessor Permission Widget for this field
+            permField = PermissionField(
+                __name__=name+'_get_perm',
+                title=u"Accessor Permission",
+                default=CheckerPublic,
+                required=False)
+            setUpWidget(self, name+'_get_perm', permField, value=get_perm)
+
+            # Create the Mutator Permission Widget for this field
+            permField = PermissionField(
+                __name__=name+'_set_perm',
+                title=u"Mutator Permission",
+                default=CheckerPublic,
+                required=False)
+            setUpWidget(self, name+'_set_perm', permField, value=set_perm)
+
+    def update(self):
+        status = ''
+
+        if Update in self.request:
+            status = super(MutableSchemaPermsEdit, self).update()
+            self.buildPermissionWidgets()
+        elif 'CHANGE' in self.request:
+            schema = self.context
+            perms = trustedRemoveSecurityProxy(self.context.schemaPermissions)
+            for name, field in getFieldsInOrder(schema):
+                getPerm = getattr(self, name+'_get_perm_widget').getData()
+                setPerm = getattr(self, name+'_set_perm_widget').getData()
+                perms[name] = (getPerm, setPerm)
+            status = 'Fields permissions mapping updated.'
+
+        return status
+
+    def getPermissionWidgets(self):
+        schema = self.context
+        info = []
+        for name, field in getFieldsInOrder(schema):
+            field = trustedRemoveSecurityProxy(field)
+            info.append(
+                {'fieldName': name,
+                 'fieldTitle': field.title,
+                 'getter': getattr(self, name+'_get_perm_widget'),
+                 'setter': getattr(self, name+'_set_perm_widget')} )
+        return info
 
 class EditMutableSchema(EditView):
 




More information about the Zope3-Checkins mailing list