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