update schema definition to avoid deprecation warning with new yams api
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 23 Jun 2009 13:31:16 +0200
changeset 2140 1cba3393ba01
parent 2129 fbfab570a276
child 2141 0072247db207
update schema definition to avoid deprecation warning with new yams api
schemas/Bookmark.py
schemas/base.py
schemas/bootstrap.py
schemas/workflow.py
--- a/schemas/Bookmark.py	Mon Jun 22 14:20:46 2009 +0200
+++ b/schemas/Bookmark.py	Tue Jun 23 13:31:16 2009 +0200
@@ -5,9 +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
 
-class Bookmark(MetaUserEntityType):
+from yams.buildobjs import EntityType, RelationType, String
+
+class Bookmark(EntityType):
     """define an entity type, used to build the application schema"""
+    permissions = {
+        'read':   ('managers', 'users', 'guests',),
+        'add':    ('managers', 'users',),
+        'delete': ('managers', 'owners',),
+        'update': ('managers', 'owners',),
+        }
     title = String(required=True, maxsize=128)
     path  = String(maxsize=512, required=True,
                    description=_("relative url of the bookmarked page"))
@@ -16,7 +26,7 @@
                                     description=_("users using this bookmark"))
 
 
-class bookmarked_by(MetaUserRelationType):
+class bookmarked_by(RelationType):
     permissions = {'read':   ('managers', 'users', 'guests',),
                    # test user in users group to avoid granting permission to anonymous user
                    'add':    ('managers', RRQLExpression('O identity U, U in_group G, G name "users"')),
--- a/schemas/base.py	Mon Jun 22 14:20:46 2009 +0200
+++ b/schemas/base.py	Tue Jun 23 13:31:16 2009 +0200
@@ -6,11 +6,15 @@
 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
 """
 __docformat__ = "restructuredtext en"
+_ = unicode
 
+from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
+                            String, Boolean, Datetime)
+from cubicweb.schema import RQLConstraint
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
 
 class CWUser(WorkflowableEntityType):
     """define a CubicWeb user"""
-    meta = True # XXX backported from old times, shouldn't be there anymore
     permissions = {
         'read':   ('managers', 'users', ERQLExpression('X identity U')),
         'add':    ('managers',),
@@ -35,7 +39,7 @@
                                description=_('groups grant permissions to the user'))
 
 
-class EmailAddress(MetaEntityType):
+class EmailAddress(EntityType):
     """an electronic mail address associated to a short alias"""
     permissions = {
         'read':   ('managers', 'users', 'guests',), # XXX if P use_email X, U has_read_permission P
@@ -81,11 +85,11 @@
         'delete': ('managers', RRQLExpression('U has_update_permission S'),),
         }
 
-class in_group(MetaRelationType):
+class in_group(RelationType):
     """core relation indicating a user's groups"""
-    meta = False
+    permissions = META_RTYPE_PERMS
 
-class owned_by(MetaRelationType):
+class owned_by(RelationType):
     """core relation indicating owners of an entity. This relation
     implicitly put the owner into the owners group for the entity
     """
@@ -100,7 +104,7 @@
     subject = '**'
     object = 'CWUser'
 
-class created_by(MetaRelationType):
+class created_by(RelationType):
     """core relation indicating the original creator of an entity"""
     permissions = {
         'read':   ('managers', 'users', 'guests'),
@@ -114,13 +118,13 @@
     object = 'CWUser'
 
 
-class creation_date(MetaAttributeRelationType):
+class creation_date(RelationType):
     """creation time of an entity"""
     cardinality = '11'
     subject = '**'
     object = 'Datetime'
 
-class modification_date(MetaAttributeRelationType):
+class modification_date(RelationType):
     """latest modification time of an entity"""
     cardinality = '11'
     subject = '**'
@@ -137,7 +141,6 @@
         'update': ('managers', 'owners',),
         'delete': ('managers', 'owners',),
         }
-    meta = True
     # key is a reserved word for mysql
     pkey = String(required=True, internationalizable=True, maxsize=256,
                   description=_('defines what\'s the property is applied for. '
@@ -152,7 +155,7 @@
                                              ' a global property'))
 
 
-class for_user(MetaRelationType):
+class for_user(RelationType):
     """link a property to the user which want this property customization. Unless
     you're a site manager, this relation will be handled automatically.
     """
@@ -164,9 +167,11 @@
     inlined = True
 
 
-class CWPermission(MetaEntityType):
+class CWPermission(EntityType):
     """entity type that may be used to construct some advanced security configuration
     """
+    permissions = META_ETYPE_PERMS
+
     name = String(required=True, indexed=True, internationalizable=True, maxsize=100,
                   description=_('name or identifier of the permission'))
     label = String(required=True, internationalizable=True, maxsize=100,
@@ -186,7 +191,7 @@
         'delete': ('managers',),
         }
 
-class require_group(MetaRelationType):
+class require_group(RelationType):
     """used to grant a permission to a group"""
     permissions = {
         'read':   ('managers', 'users', 'guests'),
@@ -200,7 +205,7 @@
     symetric = True
 
 
-class CWCache(MetaEntityType):
+class CWCache(EntityType):
     """a simple cache entity characterized by a name and
     a validity date.
 
@@ -212,7 +217,7 @@
     permissions = {
         'read':   ('managers', 'users', 'guests'),
         'add':    ('managers',),
-        'update': ('managers', 'users',),
+        'update': ('managers', 'users',), # XXX
         'delete': ('managers',),
         }
 
--- 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'),
--- a/schemas/workflow.py	Mon Jun 22 14:20:46 2009 +0200
+++ b/schemas/workflow.py	Tue Jun 23 13:31:16 2009 +0200
@@ -5,11 +5,20 @@
 :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
 
-class State(MetaEntityType):
+from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
+                            ObjectRelation, String)
+from cubicweb.schema import RichString, RQLConstraint
+from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
+
+class State(EntityType):
     """used to associate simple states to an entity type and/or to define
     workflows
     """
+    permissions = META_ETYPE_PERMS
+
     name = String(required=True, indexed=True, internationalizable=True,
                   maxsize=256)
     description = RichString(fulltextindexed=True, default_format='text/rest',
@@ -28,15 +37,15 @@
                                    description=_('initial state for entities of this type'))
 
 
-class Transition(MetaEntityType):
+class Transition(EntityType):
     """use to define a transition from one or multiple states to a destination
     states in workflow's definitions.
     """
+    permissions = META_ETYPE_PERMS
+
     name = String(required=True, indexed=True, internationalizable=True,
                   maxsize=256)
-    description_format = String(meta=True, internationalizable=True, maxsize=50,
-                                default='text/rest', constraints=[format_constraint])
-    description = String(fulltextindexed=True,
+    description = RichString(fulltextindexed=True,
                          description=_('semantic description of this transition'))
     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
                                 description=_('a RQL expression which should return some results, '
@@ -56,20 +65,22 @@
                                         description=_('destination state for this transition'))
 
 
-class TrInfo(MetaEntityType):
+class TrInfo(EntityType):
+    permissions = META_ETYPE_PERMS
+
     from_state = SubjectRelation('State', cardinality='?*')
     to_state = SubjectRelation('State', cardinality='1*')
-    comment_format = String(meta=True, internationalizable=True, maxsize=50,
-                            default='text/rest', constraints=[format_constraint])
-    comment = String(fulltextindexed=True)
+    comment = RichString(fulltextindexed=True)
     # get actor and date time using owned_by and creation_date
 
 
-class from_state(MetaRelationType):
+class from_state(RelationType):
+    permissions = META_RTYPE_PERMS
     inlined = True
-class to_state(MetaRelationType):
+class to_state(RelationType):
+    permissions = META_RTYPE_PERMS
     inlined = True
-class wf_info_for(MetaRelationType):
+class wf_info_for(RelationType):
     """link a transition information to its object"""
     permissions = {
         'read':   ('managers', 'users', 'guests',),# RRQLExpression('U has_read_permission O')),
@@ -80,30 +91,39 @@
     composite = 'object'
     fulltext_container = composite
 
-class state_of(MetaRelationType):
+class state_of(RelationType):
     """link a state to one or more entity type"""
-class transition_of(MetaRelationType):
+    permissions = META_RTYPE_PERMS
+class transition_of(RelationType):
     """link a transition to one or more entity type"""
+    permissions = META_RTYPE_PERMS
 
-class initial_state(MetaRelationType):
+class initial_state(RelationType):
     """indicate which state should be used by default when an entity using
     states is created
     """
-    inlined = True
-
-class destination_state(MetaRelationType):
-    """destination state of a transition"""
+    permissions = META_RTYPE_PERMS
     inlined = True
 
-class allowed_transition(MetaRelationType):
-    """allowed transition from this state"""
+class destination_state(RelationType):
+    """destination state of a transition"""
+    permissions = META_RTYPE_PERMS
+    inlined = True
 
-class in_state(UserRelationType):
+class allowed_transition(RelationType):
+    """allowed transition from this state"""
+    permissions = META_RTYPE_PERMS
+
+class in_state(RelationType):
     """indicate the current state of an entity"""
-    meta = True
     # not inlined intentionnaly since when using ldap sources, user'state
     # has to be stored outside the CWUser table
 
     # add/delete perms given to managers/users, after what most of the job
     # is done by workflow enforcment
+    permissions = {
+        'read':   ('managers', 'users', 'guests',),
+        'add':    ('managers', 'users',), # XXX has_update_perm
+        'delete': ('managers', 'users',),
+        }