schemas/workflow.py
changeset 2140 1cba3393ba01
parent 1977 606923dff11b
child 2234 1fbcf202882d
equal deleted inserted replaced
2129:fbfab570a276 2140:1cba3393ba01
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
       
     8 __docformat__ = "restructuredtext en"
       
     9 _ = unicode
     8 
    10 
     9 class State(MetaEntityType):
    11 from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
       
    12                             ObjectRelation, String)
       
    13 from cubicweb.schema import RichString, RQLConstraint
       
    14 from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS
       
    15 
       
    16 class State(EntityType):
    10     """used to associate simple states to an entity type and/or to define
    17     """used to associate simple states to an entity type and/or to define
    11     workflows
    18     workflows
    12     """
    19     """
       
    20     permissions = META_ETYPE_PERMS
       
    21 
    13     name = String(required=True, indexed=True, internationalizable=True,
    22     name = String(required=True, indexed=True, internationalizable=True,
    14                   maxsize=256)
    23                   maxsize=256)
    15     description = RichString(fulltextindexed=True, default_format='text/rest',
    24     description = RichString(fulltextindexed=True, default_format='text/rest',
    16                              description=_('semantic description of this state'))
    25                              description=_('semantic description of this state'))
    17 
    26 
    26                                    # S initial_state O, O state_of S
    35                                    # S initial_state O, O state_of S
    27                                    constraints=[RQLConstraint('O state_of S')],
    36                                    constraints=[RQLConstraint('O state_of S')],
    28                                    description=_('initial state for entities of this type'))
    37                                    description=_('initial state for entities of this type'))
    29 
    38 
    30 
    39 
    31 class Transition(MetaEntityType):
    40 class Transition(EntityType):
    32     """use to define a transition from one or multiple states to a destination
    41     """use to define a transition from one or multiple states to a destination
    33     states in workflow's definitions.
    42     states in workflow's definitions.
    34     """
    43     """
       
    44     permissions = META_ETYPE_PERMS
       
    45 
    35     name = String(required=True, indexed=True, internationalizable=True,
    46     name = String(required=True, indexed=True, internationalizable=True,
    36                   maxsize=256)
    47                   maxsize=256)
    37     description_format = String(meta=True, internationalizable=True, maxsize=50,
    48     description = RichString(fulltextindexed=True,
    38                                 default='text/rest', constraints=[format_constraint])
       
    39     description = String(fulltextindexed=True,
       
    40                          description=_('semantic description of this transition'))
    49                          description=_('semantic description of this transition'))
    41     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
    50     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
    42                                 description=_('a RQL expression which should return some results, '
    51                                 description=_('a RQL expression which should return some results, '
    43                                               'else the transition won\'t be available. '
    52                                               'else the transition won\'t be available. '
    44                                               'This query may use X and U variables '
    53                                               'This query may use X and U variables '
    54     destination_state = SubjectRelation('State', cardinality='?*',
    63     destination_state = SubjectRelation('State', cardinality='?*',
    55                                         constraints=[RQLConstraint('S transition_of ET, O state_of ET')],
    64                                         constraints=[RQLConstraint('S transition_of ET, O state_of ET')],
    56                                         description=_('destination state for this transition'))
    65                                         description=_('destination state for this transition'))
    57 
    66 
    58 
    67 
    59 class TrInfo(MetaEntityType):
    68 class TrInfo(EntityType):
       
    69     permissions = META_ETYPE_PERMS
       
    70 
    60     from_state = SubjectRelation('State', cardinality='?*')
    71     from_state = SubjectRelation('State', cardinality='?*')
    61     to_state = SubjectRelation('State', cardinality='1*')
    72     to_state = SubjectRelation('State', cardinality='1*')
    62     comment_format = String(meta=True, internationalizable=True, maxsize=50,
    73     comment = RichString(fulltextindexed=True)
    63                             default='text/rest', constraints=[format_constraint])
       
    64     comment = String(fulltextindexed=True)
       
    65     # get actor and date time using owned_by and creation_date
    74     # get actor and date time using owned_by and creation_date
    66 
    75 
    67 
    76 
    68 class from_state(MetaRelationType):
    77 class from_state(RelationType):
       
    78     permissions = META_RTYPE_PERMS
    69     inlined = True
    79     inlined = True
    70 class to_state(MetaRelationType):
    80 class to_state(RelationType):
       
    81     permissions = META_RTYPE_PERMS
    71     inlined = True
    82     inlined = True
    72 class wf_info_for(MetaRelationType):
    83 class wf_info_for(RelationType):
    73     """link a transition information to its object"""
    84     """link a transition information to its object"""
    74     permissions = {
    85     permissions = {
    75         'read':   ('managers', 'users', 'guests',),# RRQLExpression('U has_read_permission O')),
    86         'read':   ('managers', 'users', 'guests',),# RRQLExpression('U has_read_permission O')),
    76         'add':    (), # handled automatically, no one should add one explicitly
    87         'add':    (), # handled automatically, no one should add one explicitly
    77         'delete': ('managers',), # RRQLExpression('U has_delete_permission O')
    88         'delete': ('managers',), # RRQLExpression('U has_delete_permission O')
    78         }
    89         }
    79     inlined = True
    90     inlined = True
    80     composite = 'object'
    91     composite = 'object'
    81     fulltext_container = composite
    92     fulltext_container = composite
    82 
    93 
    83 class state_of(MetaRelationType):
    94 class state_of(RelationType):
    84     """link a state to one or more entity type"""
    95     """link a state to one or more entity type"""
    85 class transition_of(MetaRelationType):
    96     permissions = META_RTYPE_PERMS
       
    97 class transition_of(RelationType):
    86     """link a transition to one or more entity type"""
    98     """link a transition to one or more entity type"""
       
    99     permissions = META_RTYPE_PERMS
    87 
   100 
    88 class initial_state(MetaRelationType):
   101 class initial_state(RelationType):
    89     """indicate which state should be used by default when an entity using
   102     """indicate which state should be used by default when an entity using
    90     states is created
   103     states is created
    91     """
   104     """
       
   105     permissions = META_RTYPE_PERMS
    92     inlined = True
   106     inlined = True
    93 
   107 
    94 class destination_state(MetaRelationType):
   108 class destination_state(RelationType):
    95     """destination state of a transition"""
   109     """destination state of a transition"""
       
   110     permissions = META_RTYPE_PERMS
    96     inlined = True
   111     inlined = True
    97 
   112 
    98 class allowed_transition(MetaRelationType):
   113 class allowed_transition(RelationType):
    99     """allowed transition from this state"""
   114     """allowed transition from this state"""
       
   115     permissions = META_RTYPE_PERMS
   100 
   116 
   101 class in_state(UserRelationType):
   117 class in_state(RelationType):
   102     """indicate the current state of an entity"""
   118     """indicate the current state of an entity"""
   103     meta = True
       
   104     # not inlined intentionnaly since when using ldap sources, user'state
   119     # not inlined intentionnaly since when using ldap sources, user'state
   105     # has to be stored outside the CWUser table
   120     # has to be stored outside the CWUser table
   106 
   121 
   107     # add/delete perms given to managers/users, after what most of the job
   122     # add/delete perms given to managers/users, after what most of the job
   108     # is done by workflow enforcment
   123     # is done by workflow enforcment
       
   124     permissions = {
       
   125         'read':   ('managers', 'users', 'guests',),
       
   126         'add':    ('managers', 'users',), # XXX has_update_perm
       
   127         'delete': ('managers', 'users',),
       
   128         }
   109 
   129