[Amedes-cvs-commit] [ame] src

sebd at users.labs.libre-entreprise.org sebd at users.labs.libre-entreprise.org
Fri Feb 11 17:31:39 CET 2005


Changement dans le répertoire ame/src:
---
Fixed everything, more or less.
---  (par sebd)

Fichiers affectés:
-----------------
queries_containers.py ajouté      (1.1)
queries_descriptions.py ajouté      (1.1)
things_descriptions.py ajouté      (1.1)
ame.py               modifié     (1.1.1.1 -> 1.2)
criterias_descriptions.py modifié     (1.1.1.1 -> 1.2)
dynamicgroups.py     modifié     (1.2 -> 1.3)
permissions.py       modifié     (1.2 -> 1.3)
permissions_containers.py modifié     (1.1.1.1 -> 1.2)
permissions_descriptions.py modifié     (1.2 -> 1.3)
queries.py           modifié     (1.2 -> 1.3)
roles.py             modifié     (1.2 -> 1.3)
staticgroups.py      modifié     (1.2 -> 1.3)
things.py            modifié     (1.2 -> 1.3)
users.py             modifié     (1.2 -> 1.3)
users_descriptions.py modifié     (1.1.1.1 -> 1.2)
-------------- next part --------------
Index: ame/src/ame.py
diff -u ame/src/ame.py:1.1.1.1 ame/src/ame.py:1.2
--- ame/src/ame.py:1.1.1.1	Wed Jan 26 14:55:44 2005
+++ ame/src/ame.py	Fri Feb 11 16:31:33 2005
@@ -1,3 +1,28 @@
+# -*- coding: UTF-8 -*-
+
+
+# Copyright (C) 2004-2005 Les Développements Durables, Antoine, Nicolas & Sébastien Ducoulombier
+#
+# This file is part of Ame.
+#
+# Ame is free software; you can redistribute it and/or
+# modify it under the terms of the Affero General Public License
+# as published by Affero Inc.; either version 1
+# of the License, or (at your option) any later version.
+#
+# Ame is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# Affero General Public License for more details.
+#
+# You should have received a copy of the Affero General Public License
+# along with Ame; if not, write to Affero, Inc. at
+# 510 Third Street - Suite 225, San Francisco, CA 94107, USA
+# or visit http://www.affero.org.
+
+
+""" Ame
+"""
 
 import accounts
 import containers_directories
@@ -12,6 +37,7 @@
 import roles
 import staticgroups_containers
 import staticgroups
+import things_descriptions
 import things
 import users_containers
 import users

Index: ame/src/criterias_descriptions.py
diff -u ame/src/criterias_descriptions.py:1.1.1.1 ame/src/criterias_descriptions.py:1.2
--- ame/src/criterias_descriptions.py:1.1.1.1	Wed Jan 26 14:55:44 2005
+++ ame/src/criterias_descriptions.py	Fri Feb 11 16:31:33 2005
@@ -323,10 +323,13 @@
     def appendMyOwnControls(self, context):
         node = self.node.newChild(None, "select1", None)
         node.setProp("ref", "@fieldId")
-        for name in context.specimen.getElementClass().getReadableFieldNames():
-            itemNode = node.newChild(None, "item", None)
-            itemNode.newTextChild(None, "value", name)
-            itemNode.newTextChild(None, "label", name)
+        elementClass = context.specimen.getElementClass()
+        permission = environs.getVar("user").getSelectedRole().getPermissionForClass(elementClass)
+        if permission:
+            for name in permission.getReadableFieldNames():
+                itemNode = node.newChild(None, "item", None)
+                itemNode.newTextChild(None, "value", name)
+                itemNode.newTextChild(None, "label", name)
         node = self.node.newChild(None, "select1", None)
         node.setProp("ref", "@operator")
         for name in criterias.FieldComparisonCriteria.supportedOperators:

Index: ame/src/dynamicgroups.py
diff -u ame/src/dynamicgroups.py:1.2 ame/src/dynamicgroups.py:1.3
--- ame/src/dynamicgroups.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/dynamicgroups.py	Fri Feb 11 16:31:33 2005
@@ -54,5 +54,7 @@
         clas,
         "http://www.lesdeveloppementsdurables.org/ame/schemas/%s.xsd" % clas.__name__,
         "http://www.lesdeveloppementsdurables.org/ame/descriptions/%s.xml" % clas.__name__,
+        typeNamespace = namespaces.ame.uri,
+        typeName = clas.__name__,
     )
 

Index: ame/src/permissions.py
diff -u ame/src/permissions.py:1.2 ame/src/permissions.py:1.3
--- ame/src/permissions.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/permissions.py	Fri Feb 11 16:31:33 2005
@@ -37,25 +37,43 @@
     """ A permission to manage a type of element.
     """
     def _getAccessibleFieldNames(self, W=False):
-        return [
-            node.content
-            for node in self.getElementTypeSchema().evaluateXpath(
-                "xsd:group[%s]/xsd:sequence/xsd:element/@name" % " or ".join(
-                    [
-                        "@name='%s'" % name
-                        for name in self._getAccessibleGroupNames(W)
-                    ]
-                )
-            )
-        ]
+        type = self.getElementType()
+        list = []
+        for node in type.getAttributeNodeList():
+            name = node.prop("name")
+            if name in self._getAccessibleNames("attributeAccess", W):
+                list.append("@%s" % node.prop("name"))
+        for node in type.getAttributeGroupNodeList():
+            if node.prop("name") in self._getAccessibleNames("attributeGroupAccess", W):
+                for attributeNode in type.evaluateXpath("xsd:attribute", node):
+                    list.append("@%s" % attributeNode.prop("name"))
+        for node in type.getElementNodeList():
+            name = node.prop("name")
+            if name in self._getAccessibleNames("elementAccess", W):
+                list.append(name)
+        for node in type.getGroupNodeList():
+            if node.prop("name") in self._getAccessibleNames("groupAccess", W):
+                for elementNode in type.evaluateXpath("xsd:sequence/xsd:element", node):
+                    list.append(elementNode.prop("name"))
+        return list
 
-    def _getAccessibleGroupNames(self, W=False):
+    def _getAccessibleNames(self, elementName, W=False):
         if W:
-            xpath = "ame:access[@writeAccess=\"1\"]/@fieldGroupName"
+            xpath = "ame:%s[@writeAccess=\"1\"]/@name" % elementName
         else:
-            xpath = "ame:access/@fieldGroupName"
+            xpath = "ame:%s/@name" % elementName
         return [node.content for node in self.evaluateXpath(xpath)]
 
+    def _setAccess(self, elementName, name, access):
+        for node in self.evaluateXpath("ame:%s[@name='%s']" % (elementName, name)):
+            node.unlinkNode()
+            node.freeNode()
+        if access in ("R", "W"):
+            node = self.node.newTextChild(None, elementName, None)
+            node.setProp("name", name)
+            if access == "W":
+                node.setProp("writeAccess", "1")
+
     def canCreateAndDelete(self):
         """ Returns the value of the boolean canCreateAndDelete.
         """
@@ -71,12 +89,33 @@
         """
         return self._getAccessibleFieldNames()
 
+    def getReadableAttributeNames(self):
+        """ Returns the list of readable field groups
+
+            Writable fields are assumed to be readable, this is not a read-only field group list.
+        """
+        return self._getAccessibleNames("attributeAccess")
+
+    def getReadableAttributeGroupNames(self):
+        """ Returns the list of readable field groups
+
+            Writable fields are assumed to be readable, this is not a read-only field group list.
+        """
+        return self._getAccessibleNames("attributeGroupAccess")
+
+    def getReadableElementNames(self):
+        """ Returns the list of readable field groups
+
+            Writable fields are assumed to be readable, this is not a read-only field group list.
+        """
+        return self._getAccessibleNames("elementAccess")
+
     def getReadableGroupNames(self):
         """ Returns the list of readable field groups
 
             Writable fields are assumed to be readable, this is not a read-only field group list.
         """
-        return self._getAccessibleGroupNames()
+        return self._getAccessibleNames("groupAccess")
 
     def getWritableFieldNames(self):
         """ Returns the list of writable fields
@@ -85,36 +124,68 @@
         """
         return self._getAccessibleFieldNames(W=True)
 
+    def getWritableAttributeNames(self):
+        """ Returns the list of writable field groups
+
+            Writable fields are also readable.
+        """
+        return self._getAccessibleNames("attributeAccess", W=True)
+
+    def getWritableAttributeGroupNames(self):
+        """ Returns the list of writable field groups
+
+            Writable fields are also readable.
+        """
+        return self._getAccessibleNames("attributeGroupAccess", W=True)
+
+    def getWritableElementNames(self):
+        """ Returns the list of writable field groups
+
+            Writable fields are also readable.
+        """
+        return self._getAccessibleNames("elementAccess", W=True)
+
     def getWritableGroupNames(self):
         """ Returns the list of writable field groups
 
             Writable fields are also readable.
         """
-        return self._getAccessibleGroupNames(W=True)
+        return self._getAccessibleNames("groupAccess", W=True)
 
     def isContentAccessAuthorized(self, contentName, command):
         """ only allow users that can manage roles
         """
         return environs.getVar("user").canCreateAndDelete("Permission")
 
+    def setAttributeAccess(self, name, access):
+        """ Sets the access to the attribute.
+        Access is either "R", "W" or None.
+        """
+        self._setAccess("attributeAccess", name, access)
+
+    def setAttributeGroupAccess(self, name, access):
+        """ Sets the access to the attribute group.
+        Access is either "R", "W" or None.
+        """
+        self._setAccess("attributeGroupAccess", name, access)
+
+    def setElementAccess(self, name, access):
+        """ Sets the access to the element.
+        Access is either "R", "W" or None.
+        """
+        self._setAccess("elementAccess", name, access)
+
+    def setGroupAccess(self, name, access):
+        """ Sets the access to the group.
+        Access is either "R", "W" or None.
+        """
+        self._setAccess("groupAccess", name, access)
+
     def setName(self, name):
         """ Sets the name of this permission.
         """
         self.node.setProp("name", name)
 
-    def setAccess(self, fieldGroupName, access):
-        """ Sets the access to the field group.
-        Access is either "R", "W" or anything else (considered as no access).
-        """
-        for node in self.evaluateXpath("ame:access[@fieldGroupName='%s']" % fieldGroupName):
-            node.unlinkNode()
-            node.freeNode()
-        if access in ("R", "W"):
-            node = self.node.newTextChild(None, "access", None)
-            node.setProp("fieldGroupName", fieldGroupName)
-            if access == "W":
-                node.setProp("writeAccess", "1")
-
 
 for clas in [
     Permission,
@@ -125,4 +196,6 @@
         clas,
         "http://www.lesdeveloppementsdurables.org/ame/schemas/%s.xsd" % clas.__name__,
         "http://www.lesdeveloppementsdurables.org/ame/descriptions/%s.xml" % clas.__name__,
+        typeNamespace = namespaces.ame.uri,
+        typeName = clas.__name__,
     )

Index: ame/src/permissions_containers.py
diff -u ame/src/permissions_containers.py:1.1.1.1 ame/src/permissions_containers.py:1.2
--- ame/src/permissions_containers.py:1.1.1.1	Wed Jan 26 14:55:45 2005
+++ ame/src/permissions_containers.py	Fri Feb 11 16:31:33 2005
@@ -28,10 +28,11 @@
 
 import containers
 import containers_directories
+import queries_containers
 
 
-class PermissionContainer(containers.Container):
-    """ A container that contains roles
+class PermissionContainer(queries_containers.AbstractQueryContainer):
+    """ A container that contains roles.
     """
     storableThingName = "permission"
     def getLabel(self):

Index: ame/src/permissions_descriptions.py
diff -u ame/src/permissions_descriptions.py:1.2 ame/src/permissions_descriptions.py:1.3
--- ame/src/permissions_descriptions.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/permissions_descriptions.py	Fri Feb 11 16:31:33 2005
@@ -27,27 +27,60 @@
 import expression.core.elements as elements
 import expression.core.environs as environs
 import expression.core.html as html
+import expression.core.modules as modules
 import expression.core.namespaces as namespaces
+import expression.core.xmlschemas as xmlschemas
 import expression.modules.xforms.descriptions as descriptions
 import expression.modules.xforms.xforms as xforms
 
 import permissions_containers
 import roles_containers
+import things
 import xformsextensions
 
 
 class PermissionWidget(xforms.WidgetElement):
     """ A widget to edit permissions.
     """
-    def generateXmlContext(self, context, layout):
-        """ Generates a table of access selectors to the type of thing given as attributes typeName and typeNamespace.
+    def generateAccessSelectorsContext(self, context, layout, permissionId, type, names, readableNames, writableNames):
+        """ Generates selectors.
+        """
+        for name in names:
+            div = html.div()
+            div.append(html.label(_(name)))
+            select = html.select(
+                name = "access_%s_%s_%s" % (type, permissionId, name),
+            )
+            for value, label, selected in [
+                ("N", _("No Access"), name not in readableNames),
+                ("R", _("Read Only"), name in readableNames and name not in writableNames),
+                ("W", _("Modification"), name in writableNames)
+            ]:
+                option = html.option(
+                    label,
+                    value = value,
+                    class_ = value,
+                )
+                if selected:
+                    option.setAttribute("selected", "true")
+                    select.setAttribute("class", value)
+                select.append(option)
+            div.append(select)
+            layout.append(div)
+
+    def generateTableContext(self, context, layout, clas):
+        """ Generates a table of access selectors for a class of element.
         """
-        typeName = self.node.prop("typeName")
-        typeNamespace = self.node.prop("typeNamespace") or namespaces.ame.uri
-        typeClass = Thing # FIXME: not Thing; look at modules.getFeatures
+        elementNamespace, elementName = modules.getElementClassNamespaceUriAndName(clas)
+        elementFeature = modules.getElementFeature(elementNamespace, elementName)
+        schema = xmlschemas.getSchemaHolder(elementFeature.schemaAbsolutePath).getRootElement()
+        nsPrefix = namespaces.getName(elementNamespace)
+        elementNode = schema.getGlobalElementNode(elementName)
+        typeName = elementNode.prop("type")
+        typeNamespace = schema.getTargetNamespace()
+        type = schema.getGlobalType(None, typeName).prototype
         table = html.ul()
-        fieldGroupNames = typeClass.getAllFieldGroupNames()
-        for permissionId, permissionName in permissions_containers.getPermissionContainer().getIdsAndNamesForType(typeName, typeNamespace):
+        for permissionId, permissionName in permissions_containers.getPermissionContainer().getIdsAndNamesForElementType(typeNamespace, typeName):
             permission = self.walkToLocation(permissionId).getRootElement()
             li = html.li(
                 html.input(
@@ -58,58 +91,84 @@
                 html.input(
                     type = "text",
                     name = "permissionName_%s" % permissionId,
-                    value = permission.getGroupName()
+                    value = permission.getName()
                 )
             )
-            readableGroupNames = permission.getReadableGroupNames()
-            writableGroupNames = permission.getWritableGroupNames()
-            for name in fieldGroupNames:
-                div = html.div()
-                div.append(html.label(_(name)))
-                select = html.select(
-                    name = "access_%s_%s" % (permissionId, name),
-                )
-                for value, label, selected in [
-                    ("N", _("No Access"), name not in readableGroupNames),
-                    ("R", _("Read Only"), name in readableGroupNames and name not in writableGroupNames),
-                    ("W", _("Modification"), name in writableGroupNames)
-                ]:
-                    option = html.option(
-                        label,
-                        value = value,
-                        class_ = value,
-                    )
-                    if selected:
-                        option.setAttribute("selected", "true")
-                        select.setAttribute("class", value)
-                    select.append(option)
-                div.append(select)
-                li.append(div)
+            self.generateAccessSelectorsContext(context, li, permissionId, "attribute",
+                [ "@%s" % node.prop("name") for node in type.getAttributeNodeList() ],
+                permission.getReadableAttributeNames(),
+                permission.getWritableAttributeNames()
+            )
+            self.generateAccessSelectorsContext(context, li, permissionId, "attributeGroup",
+                [ node.prop("name") for node in type.getAttributeGroupNodeList() ],
+                permission.getReadableAttributeGroupNames(),
+                permission.getWritableAttributeGroupNames()
+            )
+            self.generateAccessSelectorsContext(context, li, permissionId, "element",
+                [ node.prop("name") for node in type.getElementNodeList() ],
+                permission.getReadableElementNames(),
+                permission.getWritableElementNames()
+            )
+            self.generateAccessSelectorsContext(context, li, permissionId, "group",
+                [ node.prop("name") for node in type.getGroupNodeList() ],
+                permission.getReadableGroupNames(),
+                permission.getWritableGroupNames()
+            )
             table.append(li)
+        layout.append(html.p(typeName))
         layout.append(table)
         return True
 
+    def generateXmlContext(self, context, layout):
+        """ Generates tables.
+        """
+        for clas in modules.getRegisteredElementClasses():
+            if issubclass(clas, things.Thing):
+                self.generateTableContext(context, layout, clas)
+
     def submitContext(self, context):
-        """ records the changes
+        """ Records the changes.
         """
+        for clas in modules.getRegisteredElementClasses():
+            if issubclass(clas, things.Thing):
+                self.submitTableContext(context, clas)
+
+    def submitTableContext(self, context, clas):
         submission = environs.getVar("submission")
-        fieldGroupNames = cards_schemas.getAllFieldGroupNames() # FIXME
         deleteUncheckedPermissions = submission.getField("deleteUncheckedPermissions")
-        for permissionId, permissionName in permissions_containers.getPermissionContainer().getIdsAndNames():
+
+        elementNamespace, elementName = modules.getElementClassNamespaceUriAndName(clas)
+        elementFeature = modules.getElementFeature(elementNamespace, elementName)
+        schema = xmlschemas.getSchemaHolder(elementFeature.schemaAbsolutePath).getRootElement()
+        nsPrefix = namespaces.getName(elementNamespace)
+        elementNode = schema.getGlobalElementNode(elementName)
+        typeName = elementNode.prop("type")
+        typeNamespace = schema.getTargetNamespace()
+        type = schema.getGlobalType(None, typeName).prototype
+        for permissionId, permissionName in permissions_containers.getPermissionContainer().getIdsAndNamesForElementType(typeNamespace, typeName):
             permission = self.walkToLocation(permissionId).getRootElement()
+
             permissionName = submission.getField("permissionName_%s" % permissionId)
-            if permissionName != permission.getGroupName():
-                permission.setGroupName(permissionName)
-            for name in fieldGroupNames:
-                access = submission.getField("access_%s_%s" % (permissionId, name))
-                permission.setFieldGroupAccess(name, access)
+            if permissionName != permission.getName():
+                permission.setName(permissionName)
+
+            for name in [ "@%s" % node.prop("name") for node in type.getAttributeNodeList() ]:
+                permission.setAttributeAccess(name, submission.getField("access_attribute_%s_%s" % (permissionId, name)))
+            for name in [ node.prop("name") for node in type.getAttributeGroupNodeList() ]:
+                permission.setAttributeGroupAccess(name, submission.getField("access_attributeGroup_%s_%s" % (permissionId, name)))
+            for name in [ node.prop("name") for node in type.getElementNodeList() ]:
+                permission.setElementAccess(name, submission.getField("access_element_%s_%s" % (permissionId, name)))
+            for name in [ node.prop("name") for node in type.getGroupNodeList() ]:
+                permission.setGroupAccess(name, submission.getField("access_group_%s_%s" % (permissionId, name)))
+
             permission.getDocument().save()
+
             if deleteUncheckedPermissions and not submission.getField("keepPermission_%s" % permissionId):
                 if not roles_containers.getRoleContainer().getIdsAndNames(
                     """/ame:role[@permissionId="%s"]""" % permissionId
                 ):
                     permission.getDocument().delete()
-                
+
 elements.registerElement(namespaces.ame.uri, "permissionWidget", PermissionWidget)
 
 
@@ -121,7 +180,7 @@
 
 
 class PermissionSelect(xformsextensions.DynamicSelect):
-    """ a selector with field group access level sets as items
+    """ A selector with permissions as items.
     """
     def getValuesAndLabels(self, context):
         return permissions_containers.getPermissionContainer().getIdsAndNames()

Index: ame/src/queries.py
diff -u ame/src/queries.py:1.2 ame/src/queries.py:1.3
--- ame/src/queries.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/queries.py	Fri Feb 11 16:31:33 2005
@@ -25,12 +25,13 @@
 
 import expression.core.things as things
 import expression.core.modules as modules
+import expression.core.xmlschemas as xmlschemas
 
 import criterias
 
 
 class AbstractQuery(things.Thing):
-    """ A thing with a name and a criteria tree.
+    """ A thing with a name and a criteria tree to filter elements of a specific type.
     """
     def __init__(self, *a, **b):
         super(AbstractQuery, self).__init__(*a, **b)
@@ -42,6 +43,16 @@
         """
         return modules.getElementClass(self.getElementTypeNamespace(), self.getElementTypeName())
 
+    def getElementType(self):
+        """ Returns the Type of the queried elements.
+        """
+        schema = self.getElementTypeSchema()
+        return schema.getGlobalType(None, self.getElementTypeName()).prototype
+        # for node in schema.evaluateXpath(
+        #     "xsd:complexType[@name='%s']" % self.getElementTypeName()
+        # ):
+        #     return xmlschemas.Type(node, previous = schema, owner = )
+
     def getElementTypeName(self):
         """ Returns the type name of the queried elements.
         """
@@ -52,25 +63,17 @@
         """
         return self.node.prop("elementTypeNamespace")
 
-    def getElementTypeNode(self):
-        """ Returns the node describing the type of the queried elements.
-        """
-        for node in self.getTypeSchema().evaluateXpath(
-            "xsd:complexType[@name='%s']" % self.getTypeName()
-        ):
-            return node
-
     def getElementTypeSchema(self):
         """ Caches and returns the XML Schema for the queried elements.
         """
         try:
-            return getTypeSchema._r
+            return self._elementTypeSchema
         except AttributeError:
             pass
-        feature = modules.getElementFeature(self.getTypeNamespace(), self.getTypeName())
+        feature = modules.getElementFeatureFromType(self.getElementTypeNamespace(), self.getElementTypeName())
         schemaHolder = xmlschemas.getSchemaHolder(feature.schemaAbsolutePath)
-        getTypeSchema._r = schemaHolder.getRootElement()
-        return getTypeSchema._r
+        self._elementTypeSchema = schemaHolder.getRootElement()
+        return self._elementTypeSchema
 
     def resetCriteria(self):
         """ Deletes the current criteria if any,

Index: ame/src/roles.py
diff -u ame/src/roles.py:1.2 ame/src/roles.py:1.3
--- ame/src/roles.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/roles.py	Fri Feb 11 16:31:33 2005
@@ -27,6 +27,7 @@
 import expression.core.elements as elements
 import expression.core.faults as faults
 import expression.core.environs as environs
+import expression.core.modules as modules
 import expression.core.namespaces as namespaces
 
 import things
@@ -51,6 +52,14 @@
         """
         return self.node.prop("name")
 
+    def getPermissionForClass(self, clas):
+        """ Returns the permission granted to access elements of Python class clas.
+        """
+        nsUri, name = modules.getElementClassNamespaceUriAndName(clas)
+        for permission in self.getPermissionList():
+            if permission.getElementTypeNamespace() == nsUri and permission.getElementTypeName() == name:
+                return permission
+
     def getPermissionIdList(self):
         """ Returns the id list of permissions granted to this role.
         """
@@ -94,6 +103,8 @@
         clas,
         "http://www.lesdeveloppementsdurables.org/ame/schemas/%s.xsd" % clas.__name__,
         "http://www.lesdeveloppementsdurables.org/ame/descriptions/%s.xml" % clas.__name__,
+        typeNamespace = namespaces.ame.uri,
+        typeName = clas.__name__,
     )
 
 

Index: ame/src/staticgroups.py
diff -u ame/src/staticgroups.py:1.2 ame/src/staticgroups.py:1.3
--- ame/src/staticgroups.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/staticgroups.py	Fri Feb 11 16:31:33 2005
@@ -54,4 +54,6 @@
         clas,
         "http://www.lesdeveloppementsdurables.org/ame/schemas/%s.xsd" % clas.__name__,
         "http://www.lesdeveloppementsdurables.org/ame/descriptions/%s.xml" % clas.__name__,
+        typeNamespace = namespaces.ame.uri,
+        typeName = clas.__name__,
     )

Index: ame/src/things.py
diff -u ame/src/things.py:1.2 ame/src/things.py:1.3
--- ame/src/things.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/things.py	Fri Feb 11 16:31:33 2005
@@ -24,9 +24,7 @@
 """ Things
 """
 
-import expression.core.elements as elements
 import expression.core.environs as environs
-import expression.core.modules as modules
 import expression.core.namespaces as namespaces
 import expression.core.things as things
 
@@ -34,137 +32,37 @@
 class Thing(things.Thing):
     """ An access controled object. Its content is organised in element groups.
     """
-    def getAllFieldGroupNames(cls):
-        """ Returns the list of all field group names.
-        """
-        try:
-            return getAllFieldGroupNames._r
-        except AttributeError:
-            pass
-        getAllFieldGroupNames._r = [
-            node.content
-            for node in cls.getType().prototype.evaluateXpath(
-                "xsd:complexContent/xsd:extension/xsd:sequence/xsd:group/@name"
-            )
-        ]
-        return getAllFieldGroupNames._r
-    getAllFieldGroupNames = classmethod(getAllFieldGroupNames)
-
-    def getAllFieldNames(cls):
-        """ Looks in the schema and returns the list of all field names.
-        """
-        try:
-            return getAllFieldNames._r
-        except AttributeError:
-            pass
-        getAllFieldNames._r = [
-            node.content
-            for node in cls.getSchema().evaluateXpath(
-                "xsd:group[%s]/xsd:element/@name" % " or ".join(
-                    [
-                        "@name='%s'" % name
-                        for name in cls.getAllFieldGroupNames()
-                    ]
-                )
-            )
-        ]
-        return getAllFieldNames._r
-    getAllFieldNames = classmethod(getAllFieldNames)
-
-    def getPermission(cls, role):
+    def getPermission(self, role):
         """ Returns the permission granted to the given role on this Thing.
         """
-        name = cls.getType().prototype.getName()
-        namespace = cls.getSchema().getTargetNamespace()
-        for access in role.getPermissionList():
-            if access.getTypeName() == name and access.getTypeNamespace() == namespace:
-                return access
-    getPermission = classmethod(getPermission)
+        name = self.getType().prototype.getName()
+        namespace = self.getSchema().prototype.getTargetNamespace()
+        for permission in role.getPermissionList():
+            if permission.getElementTypeName() == name and permission.getElementTypeNamespace() == namespace:
+                return permission
+
+    def getUserPermission(self, user = None):
+        """ Returns the permission granted to the given user (default: current user) to this Thing.
+        """
+        if user is None:
+            user = environs.getVar("user")
+        return user and self.getPermission(user.getSelectedRole())
 
-    def getReadableFieldNames(cls):
+    def getReadableFieldNames(self):
         """ Returns the list of all fields the current user can read.
         """
-        return cls.getPermission(environs.getVar("user").getSelectedRole()).getReadableFieldNames()
-    getReadableFieldNames = classmethod(getReadableFieldNames)
-
-    def getRequiredFieldNames(cls):
-        """ Returns the list of required fields.
-        """
-        return [
-            node.content
-            for node in getSchema().evaluateXpath(
-                "xsd:group[%s]//xsd:element[not(@minOccurs) or @minOccurs > 0]/@name" % " or ".join(
-                    [
-                        "@name='%s'" % name
-                        for name in cls.getAllFieldGroupNames()
-                    ]
-                )
-            )
-        ]
-    getRequiredFieldNames = classmethod(getRequiredFieldNames)
-
-    def getSchema(cls):
-        """ Returns the xmlschema for this type.
-        """
-        try:
-            return getSchema._r
-        except AttributeError:
-            pass
-        feature = modules.getElementFeature(cls.getNamespaceUri(), cls.getName())
-        schemaHolder = xmlschemas.getSchemaHolder(feature.schemaAbsolutePath)
-        getSchema._r = schemaHolder.getRootElement()
-        return getSchema._r
-    getSchema = classmethod(getSchema)
+        permission = self.getUserPermission()
+        return permission and permission.getReadableFieldNames()
 
-    def getValue(self, fieldName):
-        """ Returns the ACFGS field value. fieldName is assumed to be an element name.
-        """
-        for node in self.evaluateXpath(self.prefixFieldName(fieldName)):
-            return node.getContent()
-
-    def getValueList(self, fieldNames):
-        """ Returns a list of values matching the list of fieldNames.
-        """
-        return [self.getValue(fieldName) for fieldName in fieldNames]
-
-    def getWritableFieldNames(cls):
+    def getWritableFieldNames(self):
         """ Returns the list of all fields the current user can write.
         """
-        return cls.getPermission(environs.getVar("user").getSelectedRole()).getReadableFieldNames(cls.getTypeName(), self.getNamespaceUri())
-    getWritableFieldNames = classmethod(getWritableFieldNames)
-
-    def isAccessAuthorisedForUser(self, user):
-        """ Returns whether this thing matches the user's current role's permission's criteria.
-        """
-        return user.getSelectedRole().getPermission(self.getTypeName(), self.getNamespaceUri()).getCriteria().match(self)
+        permission = self.getUserPermission()
+        return permission and permission.getWritableFieldNames()
 
     def isContentAccessAuthorized(self, contentName, command):
-        """ Returns whether a user is connected and isAccessAuthorisedForUser says OK.
-        """
-        user = environs.getVar("user")
-        if user:
-            return self.isAccessAuthorisedForUser(user)
-
-    def prefixFieldName(cls, path):
-        """ returns path with element namespaces names prefixed
-
-        examples (assuming the namespace prefix is ame):
-            "ame:name"      -> "ame:name"
-            "name"          -> "ame:name"
-            "fee/amount"    -> "ame:fee/ame:amount"
-            "/card/@userId" -> "/ame:card/@userId"
+        """ Returns whether this thing matches the current user's selected role's permission's criteria.
         """
-        prefix = cls.getNamespacePrefix()
-        if path[0] == "@":
-            return path
-        if path[0] == "/":
-            return "/%s" % prefixFieldName(path[1:])
-        if not path.startswith("%s:" % prefix):
-            path = "%s:%s" % (prefix, path)
-        try:
-            slashPosition = path.index("/")
-        except ValueError:
-            return path
-        return "%s/%s" % (path[:slashPosition], prefixFieldName(path[slashPosition + 1:]))
-    prefixFieldName = classmethod(prefixFieldName)
+        permission = self.getUserPermission()
+        return permission and permission.getCriteria().match(self)
 

Index: ame/src/users.py
diff -u ame/src/users.py:1.2 ame/src/users.py:1.3
--- ame/src/users.py:1.2	Thu Jan 27 09:08:14 2005
+++ ame/src/users.py	Fri Feb 11 16:31:33 2005
@@ -219,6 +219,8 @@
         clas,
         "http://www.lesdeveloppementsdurables.org/ame/schemas/%s.xsd" % clas.__name__,
         "http://www.lesdeveloppementsdurables.org/ame/descriptions/%s.xml" % clas.__name__,
+        typeNamespace = namespaces.ame.uri,
+        typeName = clas.__name__,
     )
 
 elements.registerElement(
@@ -227,6 +229,8 @@
     User,
     "http://www.lesdeveloppementsdurables.org/ame/schemas/User.xsd",
     "http://www.lesdeveloppementsdurables.org/ame/descriptions/User.xml",
+    typeNamespace = namespaces.ame.uri,
+    typeName = clas.__name__,
 )
 
 

Index: ame/src/users_descriptions.py
diff -u ame/src/users_descriptions.py:1.1.1.1 ame/src/users_descriptions.py:1.2
--- ame/src/users_descriptions.py:1.1.1.1	Wed Jan 26 14:55:43 2005
+++ ame/src/users_descriptions.py	Fri Feb 11 16:31:33 2005
@@ -125,7 +125,6 @@
         r = [
             (_("Identity"), "edit"),
             (_("Roles"), "roles"),
-            (_("Super Powers"), "superPowers"),
         ]
         if len(context.specimen.getRoleIdList()) > 1:
             r.append((_("Default Role"), "defaultRole"))

Index: ame/src/queries_containers.py
diff -u /dev/null ame/src/queries_containers.py:1.1
--- /dev/null	Fri Feb 11 16:31:39 2005
+++ ame/src/queries_containers.py	Fri Feb 11 16:31:33 2005
@@ -0,0 +1,39 @@
+# -*- coding: UTF-8 -*-
+
+
+# Copyright (C) 2004-2005 Les Développements Durables, Antoine, Nicolas & Sébastien Ducoulombier
+#
+# This file is part of Ame.
+#
+# Ame is free software; you can redistribute it and/or
+# modify it under the terms of the Affero General Public License
+# as published by Affero Inc.; either version 1
+# of the License, or (at your option) any later version.
+#
+# Ame is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# Affero General Public License for more details.
+#
+# You should have received a copy of the Affero General Public License
+# along with Ame; if not, write to Affero, Inc. at
+# 510 Third Street - Suite 225, San Francisco, CA 94107, USA
+# or visit http://www.affero.org.
+
+
+""" Abstract Query containers
+"""
+
+
+import containers
+
+
+class AbstractQueryContainer(containers.Container):
+    """ A container that contains abstract queries.
+    """
+    def getIdsAndNamesForElementType(self, nsName, name):
+        """ Returns a list of ids and names of queries about elements of that type.
+        """
+        return self.getIdsAndNames(
+            """*[@elementTypeNamespace="%s" and @elementTypeName="%s"]""" % (nsName, name)
+        )

Index: ame/src/queries_descriptions.py
diff -u /dev/null ame/src/queries_descriptions.py:1.1
--- /dev/null	Fri Feb 11 16:31:39 2005
+++ ame/src/queries_descriptions.py	Fri Feb 11 16:31:33 2005
@@ -0,0 +1,62 @@
+# -*- coding: UTF-8 -*-
+
+
+# Copyright (C) 2004-2005 Les Développements Durables, Antoine, Nicolas & Sébastien Ducoulombier
+#
+# This file is part of Ame.
+#
+# Ame is free software; you can redistribute it and/or
+# modify it under the terms of the Affero General Public License
+# as published by Affero Inc.; either version 1
+# of the License, or (at your option) any later version.
+#
+# Ame is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# Affero General Public License for more details.
+#
+# You should have received a copy of the Affero General Public License
+# along with Ame; if not, write to Affero, Inc. at
+# 510 Third Street - Suite 225, San Francisco, CA 94107, USA
+# or visit http://www.affero.org.
+
+
+""" Abstract query descriptions
+"""
+
+import expression.core.environs as environs
+import expression.core.modules as modules
+import expression.core.namespaces as namespaces
+import expression.core.xmlschemas as xmlschemas
+import things
+import xformsextensions
+
+
+class ElementTypeSelect1(xformsextensions.DynamicSelect1):
+    """ A select1 to select a (elementTypeName, elementTypeNamespace) combination.
+    """
+    def getValuesAndLabels(self, context):
+        modules.getElementFeature(self.getNamespaceUri(), self.node.name)
+        return [
+            (clas.__name__, clas.__name__)
+            for clas in modules.getRegisteredElementClasses()
+            if issubclass(clas, things.Thing)
+        ]
+    def submitContext(self, context):
+        submission = environs.getVar("submission")
+        modelContext = self.getModelContext(context)
+        fieldName = self.getFieldName(context, modelContext)
+        value = submission.getField(fieldName, default = "")
+        for clas in modules.getRegisteredElementClasses():
+            if issubclass(clas, things.Thing) and clas.__name__ == value:
+                elementNamespace, elementName = modules.getElementClassNamespaceUriAndName(clas)
+                elementFeature = modules.getElementFeature(elementNamespace, elementName)
+                schema = xmlschemas.getSchemaHolder(elementFeature.schemaAbsolutePath).getRootElement()
+                nsPrefix = namespaces.getName(elementNamespace)
+                typeNode = schema.getGlobalElementNode(elementName)
+                typeName = typeNode.prop("type")
+                query = context.specimen
+                query.node.setProp("elementTypeNamespace", elementNamespace)
+                query.node.setProp("elementTypeName", typeName)
+                return
+

Index: ame/src/things_descriptions.py
diff -u /dev/null ame/src/things_descriptions.py:1.1
--- /dev/null	Fri Feb 11 16:31:39 2005
+++ ame/src/things_descriptions.py	Fri Feb 11 16:31:33 2005
@@ -0,0 +1,49 @@
+# -*- coding: UTF-8 -*-_containers
+
+
+# Copyright (C) 2004-2005 Les Développements Durables, Antoine, Nicolas & Sébastien Ducoulombier
+#
+# This file is part of Ame.
+#
+# Ame is free software; you can redistribute it and/or
+# modify it under the terms of the Affero General Public License
+# as published by Affero Inc.; either version 1
+# of the License, or (at your option) any later version.
+#
+# Ame is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# Affero General Public License for more details.
+#
+# You should have received a copy of the Affero General Public License
+# along with Ame; if not, write to Affero, Inc. at
+# 510 Third Street - Suite 225, San Francisco, CA 94107, USA
+# or visit http://www.affero.org.
+
+
+"""Things descriptions"""
+
+import expression.core.elements as elements
+import expression.core.environs as environs
+import expression.core.namespaces as namespaces
+import expression.modules.xforms.xforms as xforms
+
+import staticgroups_containers
+import things
+
+
+class Bind(xforms.Bind):
+    """ Enforces permissions by binding "relevant" and "readonly" properties to thing fields
+    """
+    def isReadOnly(self, context, modelContext, instanceDataXpath):
+        if issubclass(context.specimen.__class__, things.Thing):
+            return instanceDataXpath.split("/")[0].split(":")[1] not in context.specimen.getWritableFieldNames()
+        return super(Bind, self).isReadOnly(context, modelContext, instanceDataXpath)
+
+    def isRelevant(self, context, modelContext, instanceDataXpath):
+        if issubclass(context.specimen.__class__, things.Thing):
+            return instanceDataXpath.split("/")[0].split(":")[1] in context.specimen.getReadableFieldNames()
+        return super(Bind, self).isRelevant(context, modelContext, instanceDataXpath)
+
+
+elements.registerElement(namespaces.xforms.uri, "bind", Bind)


More information about the Amedes-cvs-commit mailing list