schemas/bootstrap.py
changeset 2140 1cba3393ba01
parent 2129 fbfab570a276
child 2438 576f4d51f826
--- a/schemas/bootstrap.py	Mon Jun 22 14:20:46 2009 +0200
+++ b/schemas/bootstrap.py	Tue Jun 23 13:31:16 2009 +0200
@@ -5,14 +5,19 @@
 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
+__docformat__ = "restructuredtext en"
+_ = unicode
 
-from cubicweb.schema import RichString
-
+from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
+                            ObjectRelation, String, Boolean, Int)
+from cubicweb.schema import RichString, RQLConstraint
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
 
 # not restricted since as "is" is handled as other relations, guests need
 # access to this
-class CWEType(MetaEntityType):
+class CWEType(EntityType):
     """define an entity type, used to build the application schema"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
     description = RichString(internationalizable=True,
@@ -21,8 +26,9 @@
     final = Boolean(description=_('automatic'))
 
 
-class CWRType(MetaEntityType):
+class CWRType(EntityType):
     """define a relation type, used to build the application schema"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
     description = RichString(internationalizable=True,
@@ -36,12 +42,13 @@
     final = Boolean(description=_('automatic'))
 
 
-class CWAttribute(MetaEntityType):
+class CWAttribute(EntityType):
     """define a final relation: link a final relation type from a non final
     entity to a final entity type.
 
     used to build the application schema
     """
+    permissions = META_ETYPE_PERMS
     relation_type = SubjectRelation('CWRType', cardinality='1*',
                                     constraints=[RQLConstraint('O final TRUE')],
                                     composite='object')
@@ -72,12 +79,13 @@
                      _('?1'), _('11'), _('+1'), _('*1'),
                      _('??'), _('1?'), _('+?'), _('*?')]
 
-class CWRelation(MetaEntityType):
+class CWRelation(EntityType):
     """define a non final relation: link a non final relation type from a non
     final entity to a non final entity type.
 
     used to build the application schema
     """
+    permissions = META_ETYPE_PERMS
     relation_type = SubjectRelation('CWRType', cardinality='1*',
                                     constraints=[RQLConstraint('O final FALSE')],
                                     composite='object')
@@ -106,8 +114,9 @@
 
 
 # not restricted since it has to be read when checking allowed transitions
-class RQLExpression(MetaEntityType):
+class RQLExpression(EntityType):
     """define a rql expression used to define permissions"""
+    permissions = META_ETYPE_PERMS
     exprtype = String(required=True, vocabulary=['ERQLExpression', 'RRQLExpression'])
     mainvars = String(maxsize=8,
                       description=_('name of the main variables which should be '
@@ -132,21 +141,24 @@
                                         description=_('rql expression allowing to update entities of this type'))
 
 
-class CWConstraint(MetaEntityType):
+class CWConstraint(EntityType):
     """define a schema constraint"""
+    permissions = META_ETYPE_PERMS
     cstrtype = SubjectRelation('CWConstraintType', cardinality='1*')
     value = String(description=_('depends on the constraint type'))
 
 
-class CWConstraintType(MetaEntityType):
+class CWConstraintType(EntityType):
     """define a schema constraint type"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
 
 
 # not restricted since it has to be read when checking allowed transitions
-class CWGroup(MetaEntityType):
+class CWGroup(EntityType):
     """define a CubicWeb users group"""
+    permissions = META_ETYPE_PERMS
     name = String(required=True, indexed=True, internationalizable=True,
                   unique=True, maxsize=64)
 
@@ -161,40 +173,55 @@
 
 
 
-class relation_type(MetaRelationType):
+class relation_type(RelationType):
     """link a relation definition to its relation type"""
-    inlined = True
-class from_entity(MetaRelationType):
-    """link a relation definition to its subject entity type"""
+    permissions = META_RTYPE_PERMS
     inlined = True
-class to_entity(MetaRelationType):
-    """link a relation definition to its object entity type"""
-    inlined = True
-class constrained_by(MetaRelationType):
-    """constraints applying on this relation"""
 
-class cstrtype(MetaRelationType):
-    """constraint factory"""
+class from_entity(RelationType):
+    """link a relation definition to its subject entity type"""
+    permissions = META_RTYPE_PERMS
     inlined = True
 
-class read_permission(MetaRelationType):
+class to_entity(RelationType):
+    """link a relation definition to its object entity type"""
+    permissions = META_RTYPE_PERMS
+    inlined = True
+
+class constrained_by(RelationType):
+    """constraints applying on this relation"""
+    permissions = META_RTYPE_PERMS
+
+class cstrtype(RelationType):
+    """constraint factory"""
+    permissions = META_RTYPE_PERMS
+    inlined = True
+
+class read_permission(RelationType):
     """core relation giving to a group the permission to read an entity or
     relation type
     """
-class add_permission(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+
+class add_permission(RelationType):
     """core relation giving to a group the permission to add an entity or
     relation type
     """
-class delete_permission(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+
+class delete_permission(RelationType):
     """core relation giving to a group the permission to delete an entity or
     relation type
     """
-class update_permission(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+
+class update_permission(RelationType):
     """core relation giving to a group the permission to update an entity type
     """
+    permissions = META_RTYPE_PERMS
 
 
-class is_(MetaRelationType):
+class is_(RelationType):
     """core relation indicating the type of an entity
     """
     name = 'is'
@@ -209,7 +236,7 @@
     subject = '**'
     object = 'CWEType'
 
-class is_instance_of(MetaRelationType):
+class is_instance_of(RelationType):
     """core relation indicating the types (including specialized types)
     of an entity
     """
@@ -224,7 +251,7 @@
     subject = '**'
     object = 'CWEType'
 
-class specializes(MetaRelationType):
+class specializes(RelationType):
     name = 'specializes'
     permissions = {
         'read':   ('managers', 'users', 'guests'),