[schema] tweaks meta-relations and schema/workflow entities attributes permissions stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 02 Mar 2010 15:44:26 +0100
branchstable
changeset 4755 13a5d3a7410e
parent 4754 6bf17f810975
child 4756 a2c73b272c9b
[schema] tweaks meta-relations and schema/workflow entities attributes permissions
schema.py
schemas/base.py
schemas/bootstrap.py
--- a/schema.py	Tue Mar 02 15:43:26 2010 +0100
+++ b/schema.py	Tue Mar 02 15:44:26 2010 +0100
@@ -394,7 +394,8 @@
         if need_has_text is None:
             need_has_text = may_need_has_text
         if need_has_text and not has_has_text and not deletion:
-            rdef = ybo.RelationDefinition(self.type, 'has_text', 'String')
+            rdef = ybo.RelationDefinition(self.type, 'has_text', 'String',
+                                          __permissions__=RO_ATTR_PERMS)
             self.schema.add_relation_def(rdef)
         elif not need_has_text and has_has_text:
             self.schema.del_relation_def(self.type, 'has_text', 'String')
@@ -516,9 +517,11 @@
         if not eschema.final:
             # automatically add the eid relation to non final entity types
             rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Int',
-                                          cardinality='11', uid=True)
+                                          cardinality='11', uid=True,
+                                          __permissions__=RO_ATTR_PERMS)
             self.add_relation_def(rdef)
-            rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type)
+            rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type,
+                                          __permissions__=RO_REL_PERMS)
             self.add_relation_def(rdef)
         self._eid_index[eschema.eid] = eschema
         return eschema
--- a/schemas/base.py	Tue Mar 02 15:43:26 2010 +0100
+++ b/schemas/base.py	Tue Mar 02 15:44:26 2010 +0100
@@ -118,18 +118,21 @@
 
 class creation_date(RelationType):
     """creation time of an entity"""
+    __permissions__ = PUB_SYSTEM_ATTR_PERMS
     cardinality = '11'
     subject = '*'
     object = 'Datetime'
 
 class modification_date(RelationType):
     """latest modification time of an entity"""
+    __permissions__ = PUB_SYSTEM_ATTR_PERMS
     cardinality = '11'
     subject = '*'
     object = 'Datetime'
 
 class cwuri(RelationType):
     """internal entity uri"""
+    __permissions__ = PUB_SYSTEM_ATTR_PERMS
     cardinality = '11'
     subject = '*'
     object = 'String'
--- a/schemas/bootstrap.py	Tue Mar 02 15:43:26 2010 +0100
+++ b/schemas/bootstrap.py	Tue Mar 02 15:44:26 2010 +0100
@@ -307,3 +307,13 @@
     cardinality = '?*'
     subject = 'CWEType'
     object = 'CWEType'
+
+def post_build_callback(schema):
+    """set attributes permissions for schema/workflow entities"""
+    from cubicweb.schema import SCHEMA_TYPES, WORKFLOW_TYPES, META_RTYPES
+    for eschema in schema.entities():
+        if eschema in SCHEMA_TYPES or eschema in WORKFLOW_TYPES:
+            for rschema in eschema.subject_relations():
+                if rschema.final and not rschema in META_RTYPES:
+                    rdef = eschema.rdef(rschema)
+                    rdef.permissions = PUB_SYSTEM_ATTR_PERMS