schemas/workflow.py
changeset 3998 94cc7cad3d2d
parent 3890 d7a270f50f54
parent 3983 e2dc12753436
child 4004 c52619c738a5
equal deleted inserted replaced
3895:92ead039d3d0 3998:94cc7cad3d2d
    25     workflow_of = SubjectRelation('CWEType', cardinality='+*',
    25     workflow_of = SubjectRelation('CWEType', cardinality='+*',
    26                                   description=_('entity types which may use this workflow'),
    26                                   description=_('entity types which may use this workflow'),
    27                                   constraints=[RQLConstraint('O final FALSE')])
    27                                   constraints=[RQLConstraint('O final FALSE')])
    28 
    28 
    29     initial_state = SubjectRelation('State', cardinality='?*',
    29     initial_state = SubjectRelation('State', cardinality='?*',
    30                                    constraints=[RQLConstraint('O state_of S')],
    30                                    constraints=[RQLConstraint('O state_of S',
       
    31                                                               msg=_('state doesn\'t belong to this workflow'))],
    31                                    description=_('initial state for this workflow'))
    32                                    description=_('initial state for this workflow'))
    32 
    33 
    33 
    34 
    34 class default_workflow(RelationType):
    35 class default_workflow(RelationType):
    35     """default workflow for an entity type"""
    36     """default workflow for an entity type"""
    36     __permissions__ = META_RTYPE_PERMS
    37     __permissions__ = META_RTYPE_PERMS
    37 
    38 
    38     subject = 'CWEType'
    39     subject = 'CWEType'
    39     object = 'Workflow'
    40     object = 'Workflow'
    40     cardinality = '?*'
    41     cardinality = '?*'
    41     constraints = [RQLConstraint('S final FALSE, O workflow_of S')]
    42     constraints = [RQLConstraint('S final FALSE, O workflow_of S',
       
    43                                  msg=_('workflow isn\'t a workflow of this type'))]
    42 
    44 
    43 
    45 
    44 class State(EntityType):
    46 class State(EntityType):
    45     """used to associate simple states to an entity type and/or to define
    47     """used to associate simple states to an entity type and/or to define
    46     workflows
    48     workflows
    47     """
    49     """
    48     __permissions__ = META_ETYPE_PERMS
    50     __permissions__ = META_ETYPE_PERMS
    49 
    51 
    50     name = String(required=True, indexed=True, internationalizable=True,
    52     name = String(required=True, indexed=True, internationalizable=True,
    51                   maxsize=256)
    53                   maxsize=256,
       
    54                   constraints=[RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N', 'Y',
       
    55                                                    _('workflow already have a state of that name'))])
    52     description = RichString(fulltextindexed=True, default_format='text/rest',
    56     description = RichString(fulltextindexed=True, default_format='text/rest',
    53                              description=_('semantic description of this state'))
    57                              description=_('semantic description of this state'))
    54 
    58 
    55     # XXX should be on BaseTransition w/ AND/OR selectors when we will
    59     # XXX should be on BaseTransition w/ AND/OR selectors when we will
    56     # implements #345274
    60     # implements #345274
    57     allowed_transition = SubjectRelation('BaseTransition', cardinality='**',
    61     allowed_transition = SubjectRelation('BaseTransition', cardinality='**',
    58                                          constraints=[RQLConstraint('S state_of WF, O transition_of WF')],
    62                                          constraints=[RQLConstraint('S state_of WF, O transition_of WF',
       
    63                                                                     msg=_('state and transition don\'t belong the the same workflow'))],
    59                                          description=_('allowed transitions from this state'))
    64                                          description=_('allowed transitions from this state'))
    60     state_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    65     state_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    61                                description=_('workflow to which this state belongs'),
    66                                description=_('workflow to which this state belongs'),
    62                                constraints=[RQLUniqueConstraint('S name N, Y state_of O, Y name N')])
    67                                constraints=[RQLUniqueConstraint('S name N, Y state_of O, Y name N', 'Y',
       
    68                                                                 _('workflow already have a state of that name'))])
    63 
    69 
    64 
    70 
    65 class BaseTransition(EntityType):
    71 class BaseTransition(EntityType):
    66     """abstract base class for transitions"""
    72     """abstract base class for transitions"""
    67     __permissions__ = META_ETYPE_PERMS
    73     __permissions__ = META_ETYPE_PERMS
    68 
    74 
    69     name = String(required=True, indexed=True, internationalizable=True,
    75     name = String(required=True, indexed=True, internationalizable=True,
    70                   maxsize=256)
    76                   maxsize=256,
       
    77                   constraints=[RQLUniqueConstraint('S name N, S transition_of WF, Y transition_of WF, Y name N', 'Y',
       
    78                                                    _('workflow already have a transition of that name'))])
    71     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    79     type = String(vocabulary=(_('normal'), _('auto')), default='normal')
    72     description = RichString(fulltextindexed=True,
    80     description = RichString(fulltextindexed=True,
    73                          description=_('semantic description of this transition'))
    81                          description=_('semantic description of this transition'))
    74     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
    82     condition = SubjectRelation('RQLExpression', cardinality='*?', composite='subject',
    75                                 description=_('a RQL expression which should return some results, '
    83                                 description=_('a RQL expression which should return some results, '
    81     require_group = SubjectRelation('CWGroup', cardinality='**',
    89     require_group = SubjectRelation('CWGroup', cardinality='**',
    82                                     description=_('group in which a user should be to be '
    90                                     description=_('group in which a user should be to be '
    83                                                   'allowed to pass this transition'))
    91                                                   'allowed to pass this transition'))
    84     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    92     transition_of = SubjectRelation('Workflow', cardinality='1*', composite='object',
    85                                     description=_('workflow to which this transition belongs'),
    93                                     description=_('workflow to which this transition belongs'),
    86                                     constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N')])
    94                                     constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N', 'Y',
       
    95                                                                      _('workflow already have a transition of that name'))])
    87 
    96 
    88 
    97 
    89 class Transition(BaseTransition):
    98 class Transition(BaseTransition):
    90     """use to define a transition from one or multiple states to a destination
    99     """use to define a transition from one or multiple states to a destination
    91     states in workflow's definitions.
   100     states in workflow's definitions.
    92     """
   101     """
    93     __specializes_schema__ = True
   102     __specializes_schema__ = True
    94 
   103 
    95     destination_state = SubjectRelation(
   104     destination_state = SubjectRelation(
    96         'State', cardinality='1*',
   105         'State', cardinality='1*',
    97         constraints=[RQLConstraint('S transition_of WF, O state_of WF')],
   106         constraints=[RQLConstraint('S transition_of WF, O state_of WF',
       
   107                                    msg=_('state and transition don\'t belong the the same workflow'))],
    98         description=_('destination state for this transition'))
   108         description=_('destination state for this transition'))
    99 
   109 
   100 
   110 
   101 class WorkflowTransition(BaseTransition):
   111 class WorkflowTransition(BaseTransition):
   102     """special transition allowing to go through a sub-workflow"""
   112     """special transition allowing to go through a sub-workflow"""
   103     __specializes_schema__ = True
   113     __specializes_schema__ = True
   104 
   114 
   105     subworkflow = SubjectRelation('Workflow', cardinality='1*',
   115     subworkflow = SubjectRelation('Workflow', cardinality='1*',
   106                                   constraints=[RQLConstraint('S transition_of WF, WF workflow_of ET, O workflow_of ET')])
   116                                   constraints=[RQLConstraint('S transition_of WF, WF workflow_of ET, O workflow_of ET',
       
   117                                                              msg=_('subworkflow isn\'t a workflow for the same types as the transition\'s workflow'))]
       
   118                                   )
   107     # XXX use exit_of and inline it
   119     # XXX use exit_of and inline it
   108     subworkflow_exit = SubjectRelation('SubWorkflowExitPoint', cardinality='*1',
   120     subworkflow_exit = SubjectRelation('SubWorkflowExitPoint', cardinality='*1',
   109                                        composite='subject')
   121                                        composite='subject')
   110 
   122 
   111 
   123 
   112 class SubWorkflowExitPoint(EntityType):
   124 class SubWorkflowExitPoint(EntityType):
   113     """define how we get out from a sub-workflow"""
   125     """define how we get out from a sub-workflow"""
   114     subworkflow_state = SubjectRelation(
   126     subworkflow_state = SubjectRelation(
   115         'State', cardinality='1*',
   127         'State', cardinality='1*',
   116         constraints=[RQLConstraint('T subworkflow_exit S, T subworkflow WF, O state_of WF')],
   128         constraints=[RQLConstraint('T subworkflow_exit S, T subworkflow WF, O state_of WF',
       
   129                                    msg=_('exit state must a subworkflow state'))],
   117         description=_('subworkflow state'))
   130         description=_('subworkflow state'))
   118     destination_state = SubjectRelation(
   131     destination_state = SubjectRelation(
   119         'State', cardinality='?*',
   132         'State', cardinality='?*',
   120         constraints=[RQLConstraint('T subworkflow_exit S, T transition_of WF, O state_of WF')],
   133         constraints=[RQLConstraint('T subworkflow_exit S, T transition_of WF, O state_of WF',
       
   134                                    msg=_('destination state must be in the same workflow as our parent transition'))],
   121         description=_('destination state. No destination state means that transition '
   135         description=_('destination state. No destination state means that transition '
   122                       'should go back to the state from which we\'ve entered the '
   136                       'should go back to the state from which we\'ve entered the '
   123                       'subworkflow.'))
   137                       'subworkflow.'))
   124 
   138 
   125 
   139 
   212 class custom_workflow(RelationType):
   226 class custom_workflow(RelationType):
   213     """allow to set a specific workflow for an entity"""
   227     """allow to set a specific workflow for an entity"""
   214     __permissions__ = META_RTYPE_PERMS
   228     __permissions__ = META_RTYPE_PERMS
   215 
   229 
   216     cardinality = '?*'
   230     cardinality = '?*'
   217     constraints = [RQLConstraint('S is ET, O workflow_of ET')]
   231     constraints = [RQLConstraint('S is ET, O workflow_of ET',
       
   232                                  msg=_('workflow isn\'t a workflow for this type'))]
   218     object = 'Workflow'
   233     object = 'Workflow'
   219 
   234 
   220 
   235 
   221 class wf_info_for(RelationType):
   236 class wf_info_for(RelationType):
   222     """link a transition information to its object"""
   237     """link a transition information to its object"""
   241     # not inlined intentionnaly since when using ldap sources, user'state
   256     # not inlined intentionnaly since when using ldap sources, user'state
   242     # has to be stored outside the CWUser table
   257     # has to be stored outside the CWUser table
   243     inlined = False
   258     inlined = False
   244 
   259 
   245     cardinality = '1*'
   260     cardinality = '1*'
   246     constraints = [RQLConstraint('S is ET, O state_of WF, WF workflow_of ET')]
   261     constraints = [RQLConstraint('S is ET, O state_of WF, WF workflow_of ET',
       
   262                                  msg=_('state doesn\'t apply to this entity\'s type'))]
   247     object = 'State'
   263     object = 'State'