schemas/workflow.py
branchstable
changeset 7782 40a49f4350a5
parent 7780 a1d5365fefc1
child 7797 a71618a75b53
equal deleted inserted replaced
7781:e95cfd5eca61 7782:40a49f4350a5
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    19 
    19 
    20 """
    20 """
    21 __docformat__ = "restructuredtext en"
    21 __docformat__ = "restructuredtext en"
    22 _ = unicode
    22 _ = unicode
    23 
    23 
    24 from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
    24 from yams.buildobjs import (EntityType, RelationType, SubjectRelation,
    25                             SubjectRelation,
       
    26                             RichString, String, Int)
    25                             RichString, String, Int)
    27 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    26 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint
    28 from cubicweb.schemas import (PUB_SYSTEM_ENTITY_PERMS, PUB_SYSTEM_REL_PERMS,
    27 from cubicweb.schemas import (META_ETYPE_PERMS, META_RTYPE_PERMS,
    29                               RO_REL_PERMS)
    28                               HOOKS_RTYPE_PERMS)
    30 
    29 
    31 class Workflow(EntityType):
    30 class Workflow(EntityType):
    32     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    31     __permissions__ = META_ETYPE_PERMS
    33 
    32 
    34     name = String(required=True, indexed=True, internationalizable=True,
    33     name = String(required=True, indexed=True, internationalizable=True,
    35                   maxsize=256)
    34                   maxsize=256)
    36     description = RichString(default_format='text/rest',
    35     description = RichString(default_format='text/rest',
    37                              description=_('semantic description of this workflow'))
    36                              description=_('semantic description of this workflow'))
    46                                    description=_('initial state for this workflow'))
    45                                    description=_('initial state for this workflow'))
    47 
    46 
    48 
    47 
    49 class default_workflow(RelationType):
    48 class default_workflow(RelationType):
    50     """default workflow for an entity type"""
    49     """default workflow for an entity type"""
    51     __permissions__ = PUB_SYSTEM_REL_PERMS
    50     __permissions__ = META_RTYPE_PERMS
    52 
    51 
    53     subject = 'CWEType'
    52     subject = 'CWEType'
    54     object = 'Workflow'
    53     object = 'Workflow'
    55     cardinality = '?*'
    54     cardinality = '?*'
    56     constraints = [RQLConstraint('S final FALSE, O workflow_of S',
    55     constraints = [RQLConstraint('S final FALSE, O workflow_of S',
    59 
    58 
    60 class State(EntityType):
    59 class State(EntityType):
    61     """used to associate simple states to an entity type and/or to define
    60     """used to associate simple states to an entity type and/or to define
    62     workflows
    61     workflows
    63     """
    62     """
    64     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    63     __permissions__ = META_ETYPE_PERMS
    65 
    64 
    66     name = String(required=True, indexed=True, internationalizable=True,
    65     name = String(required=True, indexed=True, internationalizable=True,
    67                   maxsize=256,
    66                   maxsize=256,
    68                   constraints=[RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N', 'Y',
    67                   constraints=[RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N', 'Y',
    69                                                    _('workflow already have a state of that name'))])
    68                                                    _('workflow already have a state of that name'))])
    82                                                                 _('workflow already have a state of that name'))])
    81                                                                 _('workflow already have a state of that name'))])
    83 
    82 
    84 
    83 
    85 class BaseTransition(EntityType):
    84 class BaseTransition(EntityType):
    86     """abstract base class for transitions"""
    85     """abstract base class for transitions"""
    87     __permissions__ = PUB_SYSTEM_ENTITY_PERMS
    86     __permissions__ = META_ETYPE_PERMS
    88 
    87 
    89     name = String(required=True, indexed=True, internationalizable=True,
    88     name = String(required=True, indexed=True, internationalizable=True,
    90                   maxsize=256,
    89                   maxsize=256,
    91                   constraints=[RQLUniqueConstraint('S name N, S transition_of WF, Y transition_of WF, Y name N', 'Y',
    90                   constraints=[RQLUniqueConstraint('S name N, S transition_of WF, Y transition_of WF, Y name N', 'Y',
    92                                                    _('workflow already have a transition of that name'))])
    91                                                    _('workflow already have a transition of that name'))])
    93     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    92     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    94     description = RichString(description=_('semantic description of this transition'))
    93     description = RichString(description=_('semantic description of this transition'))
    95 
    94     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
       
    95                                 description=_('a RQL expression which should return some results, '
       
    96                                               'else the transition won\'t be available. '
       
    97                                               'This query may use X and U variables '
       
    98                                               'that will respectivly represents '
       
    99                                               'the current entity and the current user'))
       
   100 
       
   101     require_group = SubjectRelation('CWGroup', cardinality='**',
       
   102                                     description=_('group in which a user should be to be '
       
   103                                                   'allowed to pass this transition'))
    96     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
   104     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    97                                     description=_('workflow to which this transition belongs'),
   105                                     description=_('workflow to which this transition belongs'),
    98                                     constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N', 'Y',
   106                                     constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N', 'Y',
    99                                                                      _('workflow already have a transition of that name'))])
   107                                                                      _('workflow already have a transition of that name'))])
   100 
       
   101 
       
   102 class require_group(RelationDefinition):
       
   103     """group in which a user should be to be allowed to pass this transition"""
       
   104     __permissions__ = PUB_SYSTEM_REL_PERMS
       
   105     subject = 'BaseTransition'
       
   106     object = 'CWGroup'
       
   107 
       
   108 
       
   109 class condition(RelationDefinition):
       
   110     """a RQL expression which should return some results, else the transition
       
   111     won't be available.
       
   112 
       
   113     This query may use X and U variables that will respectivly represents the
       
   114     current entity and the current user.
       
   115     """
       
   116     __permissions__ = PUB_SYSTEM_REL_PERMS
       
   117     subject = 'BaseTransition'
       
   118     object = 'RQLExpression'
       
   119     cardinality = '*?'
       
   120     composite = 'subject'
       
   121 
   108 
   122 
   109 
   123 class Transition(BaseTransition):
   110 class Transition(BaseTransition):
   124     """use to define a transition from one or multiple states to a destination
   111     """use to define a transition from one or multiple states to a destination
   125     states in workflow's definitions. Transition without destination state will
   112     states in workflow's definitions. Transition without destination state will
   188     comment = RichString(fulltextindexed=True)
   175     comment = RichString(fulltextindexed=True)
   189     tr_count = Int(description='autocomputed attribute used to ensure transition coherency')
   176     tr_count = Int(description='autocomputed attribute used to ensure transition coherency')
   190     # get actor and date time using owned_by and creation_date
   177     # get actor and date time using owned_by and creation_date
   191 
   178 
   192 class from_state(RelationType):
   179 class from_state(RelationType):
   193     __permissions__ = RO_REL_PERMS.copy()
   180     __permissions__ = HOOKS_RTYPE_PERMS.copy()
   194     inlined = True
   181     inlined = True
   195 
   182 
   196 class to_state(RelationType):
   183 class to_state(RelationType):
   197     __permissions__ = RO_REL_PERMS.copy()
   184     __permissions__ = HOOKS_RTYPE_PERMS.copy()
   198     inlined = True
   185     inlined = True
   199 
   186 
   200 class by_transition(RelationType):
   187 class by_transition(RelationType):
   201     # 'add' security actually done by hooks
   188     # 'add' security actually done by hooks
   202     __permissions__ = {
   189     __permissions__ = {
   207     inlined = True
   194     inlined = True
   208 
   195 
   209 
   196 
   210 class workflow_of(RelationType):
   197 class workflow_of(RelationType):
   211     """link a workflow to one or more entity type"""
   198     """link a workflow to one or more entity type"""
   212     __permissions__ = PUB_SYSTEM_REL_PERMS
   199     __permissions__ = META_RTYPE_PERMS
   213 
   200 
   214 class state_of(RelationType):
   201 class state_of(RelationType):
   215     """link a state to one or more workflow"""
   202     """link a state to one or more workflow"""
   216     __permissions__ = PUB_SYSTEM_REL_PERMS
   203     __permissions__ = META_RTYPE_PERMS
   217     inlined = True
   204     inlined = True
   218 
   205 
   219 class transition_of(RelationType):
   206 class transition_of(RelationType):
   220     """link a transition to one or more workflow"""
   207     """link a transition to one or more workflow"""
   221     __permissions__ = PUB_SYSTEM_REL_PERMS
   208     __permissions__ = META_RTYPE_PERMS
   222     inlined = True
   209     inlined = True
   223 
   210 
   224 class destination_state(RelationType):
   211 class destination_state(RelationType):
   225     """destination state of a transition"""
   212     """destination state of a transition"""
   226     __permissions__ = PUB_SYSTEM_REL_PERMS
   213     __permissions__ = META_RTYPE_PERMS
   227     inlined = True
   214     inlined = True
   228 
   215 
   229 class allowed_transition(RelationType):
   216 class allowed_transition(RelationType):
   230     """allowed transitions from this state"""
   217     """allowed transitions from this state"""
   231     __permissions__ = PUB_SYSTEM_REL_PERMS
   218     __permissions__ = META_RTYPE_PERMS
   232 
   219 
   233 class initial_state(RelationType):
   220 class initial_state(RelationType):
   234     """indicate which state should be used by default when an entity using
   221     """indicate which state should be used by default when an entity using
   235     states is created
   222     states is created
   236     """
   223     """
   237     __permissions__ = PUB_SYSTEM_REL_PERMS
   224     __permissions__ = META_RTYPE_PERMS
   238     inlined = True
   225     inlined = True
   239 
   226 
   240 
   227 
   241 class subworkflow(RelationType):
   228 class subworkflow(RelationType):
   242     __permissions__ = PUB_SYSTEM_REL_PERMS
   229     __permissions__ = META_RTYPE_PERMS
   243     inlined = True
   230     inlined = True
   244 
   231 
   245 class exit_point(RelationType):
   232 class exit_point(RelationType):
   246     __permissions__ = PUB_SYSTEM_REL_PERMS
   233     __permissions__ = META_RTYPE_PERMS
   247 
   234 
   248 class subworkflow_state(RelationType):
   235 class subworkflow_state(RelationType):
   249     __permissions__ = PUB_SYSTEM_REL_PERMS
   236     __permissions__ = META_RTYPE_PERMS
   250     inlined = True
   237     inlined = True
       
   238 
       
   239 
       
   240 class condition(RelationType):
       
   241     __permissions__ = META_RTYPE_PERMS
       
   242 
       
   243 # already defined in base.py
       
   244 # class require_group(RelationType):
       
   245 #     __permissions__ = META_RTYPE_PERMS
   251 
   246 
   252 
   247 
   253 # "abstract" relations, set by WorkflowableEntityType ##########################
   248 # "abstract" relations, set by WorkflowableEntityType ##########################
   254 
   249 
   255 class custom_workflow(RelationType):
   250 class custom_workflow(RelationType):
   256     """allow to set a specific workflow for an entity"""
   251     """allow to set a specific workflow for an entity"""
   257     __permissions__ = PUB_SYSTEM_REL_PERMS
   252     __permissions__ = META_RTYPE_PERMS
   258 
   253 
   259     cardinality = '?*'
   254     cardinality = '?*'
   260     constraints = [RQLConstraint('S is ET, O workflow_of ET',
   255     constraints = [RQLConstraint('S is ET, O workflow_of ET',
   261                                  msg=_('workflow isn\'t a workflow for this type'))]
   256                                  msg=_('workflow isn\'t a workflow for this type'))]
   262     object = 'Workflow'
   257     object = 'Workflow'
   278     subject = 'TrInfo'
   273     subject = 'TrInfo'
   279 
   274 
   280 
   275 
   281 class in_state(RelationType):
   276 class in_state(RelationType):
   282     """indicate the current state of an entity"""
   277     """indicate the current state of an entity"""
   283     __permissions__ = RO_REL_PERMS
   278     __permissions__ = HOOKS_RTYPE_PERMS
   284 
   279 
   285     # not inlined intentionnaly since when using ldap sources, user'state
   280     # not inlined intentionnaly since when using ldap sources, user'state
   286     # has to be stored outside the CWUser table
   281     # has to be stored outside the CWUser table
   287     inlined = False
   282     inlined = False
   288 
   283