8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 _ = unicode |
9 _ = unicode |
10 |
10 |
11 from yams.buildobjs import (EntityType, RelationType, SubjectRelation, |
11 from yams.buildobjs import (EntityType, RelationType, SubjectRelation, |
12 ObjectRelation, RichString, String) |
12 ObjectRelation, RichString, String) |
13 from cubicweb.schema import RQLConstraint |
13 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint |
14 from cubicweb.schemas import META_ETYPE_PERMS, META_RTYPE_PERMS, HOOKS_RTYPE_PERMS |
14 from cubicweb.schemas import (META_ETYPE_PERMS, META_RTYPE_PERMS, |
|
15 HOOKS_RTYPE_PERMS) |
15 |
16 |
16 class Workflow(EntityType): |
17 class Workflow(EntityType): |
17 permissions = META_ETYPE_PERMS |
18 permissions = META_ETYPE_PERMS |
18 |
19 |
19 name = String(required=True, indexed=True, internationalizable=True, |
20 name = String(required=True, indexed=True, internationalizable=True, |
32 initial_state = SubjectRelation('State', cardinality='?*', |
33 initial_state = SubjectRelation('State', cardinality='?*', |
33 # S initial_state O, O state_of S |
34 # S initial_state O, O state_of S |
34 constraints=[RQLConstraint('O state_of S')], |
35 constraints=[RQLConstraint('O state_of S')], |
35 description=_('initial state for this workflow')) |
36 description=_('initial state for this workflow')) |
36 |
37 |
37 # XXX ensure state/transition name is unique in a given workflow |
|
38 |
38 |
39 class State(EntityType): |
39 class State(EntityType): |
40 """used to associate simple states to an entity type and/or to define |
40 """used to associate simple states to an entity type and/or to define |
41 workflows |
41 workflows |
42 """ |
42 """ |
45 name = String(required=True, indexed=True, internationalizable=True, |
45 name = String(required=True, indexed=True, internationalizable=True, |
46 maxsize=256) |
46 maxsize=256) |
47 description = RichString(fulltextindexed=True, default_format='text/rest', |
47 description = RichString(fulltextindexed=True, default_format='text/rest', |
48 description=_('semantic description of this state')) |
48 description=_('semantic description of this state')) |
49 |
49 |
50 state_of = SubjectRelation('Workflow', cardinality='+*', |
|
51 description=_('workflow to which this state belongs')) |
|
52 # XXX should be on BaseTransition w/ AND/OR selectors when we will |
50 # XXX should be on BaseTransition w/ AND/OR selectors when we will |
53 # implements #345274 |
51 # implements #345274 |
54 allowed_transition = SubjectRelation('BaseTransition', cardinality='**', |
52 allowed_transition = SubjectRelation('BaseTransition', cardinality='**', |
55 constraints=[RQLConstraint('S state_of WF, O transition_of WF')], |
53 constraints=[RQLConstraint('S state_of WF, O transition_of WF')], |
56 description=_('allowed transitions from this state')) |
54 description=_('allowed transitions from this state')) |
|
55 state_of = SubjectRelation('Workflow', cardinality='+*', |
|
56 description=_('workflow to which this state belongs'), |
|
57 constraints=[RQLUniqueConstraint('S name N, Y state_of O, Y name N')]) |
57 |
58 |
58 |
59 |
59 class BaseTransition(EntityType): |
60 class BaseTransition(EntityType): |
60 """abstract base class for transitions""" |
61 """abstract base class for transitions""" |
61 permissions = META_ETYPE_PERMS |
62 permissions = META_ETYPE_PERMS |
73 |
74 |
74 require_group = SubjectRelation('CWGroup', cardinality='**', |
75 require_group = SubjectRelation('CWGroup', cardinality='**', |
75 description=_('group in which a user should be to be ' |
76 description=_('group in which a user should be to be ' |
76 'allowed to pass this transition')) |
77 'allowed to pass this transition')) |
77 transition_of = SubjectRelation('Workflow', cardinality='+*', |
78 transition_of = SubjectRelation('Workflow', cardinality='+*', |
78 description=_('workflow to which this transition belongs')) |
79 description=_('workflow to which this transition belongs'), |
|
80 constraints=[RQLUniqueConstraint('S name N, Y transition_of O, Y name N')]) |
79 |
81 |
80 |
82 |
81 class Transition(BaseTransition): |
83 class Transition(BaseTransition): |
82 """use to define a transition from one or multiple states to a destination |
84 """use to define a transition from one or multiple states to a destination |
83 states in workflow's definitions. |
85 states in workflow's definitions. |