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, SubjectRelation, |
25 RichString, String) |
25 RichString, String, Int) |
26 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint |
26 from cubicweb.schema import RQLConstraint, RQLUniqueConstraint |
27 from cubicweb.schemas import (META_ETYPE_PERMS, META_RTYPE_PERMS, |
27 from cubicweb.schemas import (META_ETYPE_PERMS, META_RTYPE_PERMS, |
28 HOOKS_RTYPE_PERMS) |
28 HOOKS_RTYPE_PERMS) |
29 |
29 |
30 class Workflow(EntityType): |
30 class Workflow(EntityType): |
157 'read': ('managers', 'users', 'guests',), # XXX U has_read_permission O ? |
157 'read': ('managers', 'users', 'guests',), # XXX U has_read_permission O ? |
158 'add': ('managers', 'users', 'guests',), |
158 'add': ('managers', 'users', 'guests',), |
159 'delete': (), # XXX should we allow managers to delete TrInfo? |
159 'delete': (), # XXX should we allow managers to delete TrInfo? |
160 'update': ('managers', 'owners',), |
160 'update': ('managers', 'owners',), |
161 } |
161 } |
162 |
162 # The unique_together constraint ensures that 2 repositories |
163 from_state = SubjectRelation('State', cardinality='1*') |
163 # sharing the db won't be able to fire a transition simultaneously |
164 to_state = SubjectRelation('State', cardinality='1*') |
164 # on the same entity tr_count is filled in the FireTransitionHook |
|
165 # to the number of TrInfo attached to the entity on which we |
|
166 # attempt to fire a transition. In other word, it contains the |
|
167 # rank of the TrInfo for that entity, and the constraint says we |
|
168 # cannot have 2 TrInfo with the same rank. |
|
169 __unique_together__ = [('tr_count', 'wf_info_for')] |
|
170 from_state = SubjectRelation('State', cardinality='1*', inlined=True) |
|
171 to_state = SubjectRelation('State', cardinality='1*', inlined=True) |
165 # make by_transition optional because we want to allow managers to set |
172 # make by_transition optional because we want to allow managers to set |
166 # entity into an arbitrary state without having to respect wf transition |
173 # entity into an arbitrary state without having to respect wf transition |
167 by_transition = SubjectRelation('BaseTransition', cardinality='?*') |
174 by_transition = SubjectRelation('BaseTransition', cardinality='?*') |
168 comment = RichString(fulltextindexed=True) |
175 comment = RichString(fulltextindexed=True) |
|
176 tr_count = Int(description='autocomputed attribute used to ensure transition coherency') |
169 # get actor and date time using owned_by and creation_date |
177 # get actor and date time using owned_by and creation_date |
170 |
178 |
171 class from_state(RelationType): |
179 class from_state(RelationType): |
172 __permissions__ = HOOKS_RTYPE_PERMS.copy() |
180 __permissions__ = HOOKS_RTYPE_PERMS.copy() |
173 inlined = True |
181 inlined = True |