1 """workflow definition and history related entities |
1 """workflow definition and history related entities |
2 |
2 |
3 :organization: Logilab |
3 :organization: Logilab |
4 :copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 """ |
6 """ |
7 __docformat__ = "restructuredtext en" |
7 __docformat__ = "restructuredtext en" |
8 |
8 |
9 from cubicweb.entities import AnyEntity, fetch_config |
9 from cubicweb.entities import AnyEntity, fetch_config |
15 provides a specific may_be_passed method to check if the relation may be |
15 provides a specific may_be_passed method to check if the relation may be |
16 passed by the logged user |
16 passed by the logged user |
17 """ |
17 """ |
18 id = 'Transition' |
18 id = 'Transition' |
19 fetch_attrs, fetch_order = fetch_config(['name']) |
19 fetch_attrs, fetch_order = fetch_config(['name']) |
20 __rtags__ = {('destination_state', '*', 'subject'): 'create', |
20 |
21 ('allowed_transition', '*', 'object') : 'create', |
|
22 } |
|
23 |
|
24 def may_be_passed(self, eid, stateeid): |
21 def may_be_passed(self, eid, stateeid): |
25 """return true if the logged user may pass this transition |
22 """return true if the logged user may pass this transition |
26 |
23 |
27 `eid` is the eid of the object on which we may pass the transition |
24 `eid` is the eid of the object on which we may pass the transition |
28 `stateeid` is the eid of the current object'state XXX unused |
25 `stateeid` is the eid of the current object'state XXX unused |
45 return False |
42 return False |
46 return True |
43 return True |
47 |
44 |
48 def destination(self): |
45 def destination(self): |
49 return self.destination_state[0] |
46 return self.destination_state[0] |
50 |
47 |
51 def after_deletion_path(self): |
48 def after_deletion_path(self): |
52 """return (path, parameters) which should be used as redirect |
49 """return (path, parameters) which should be used as redirect |
53 information when this entity is being deleted |
50 information when this entity is being deleted |
54 """ |
51 """ |
55 if self.transition_of: |
52 if self.transition_of: |
56 return self.transition_of[0].rest_path(), {'vid': 'workflow'} |
53 return self.transition_of[0].rest_path(), {'vid': 'workflow'} |
57 return super(Transition, self).after_deletion_path() |
54 return super(Transition, self).after_deletion_path() |
58 |
55 |
59 |
56 |
60 class State(AnyEntity): |
57 class State(AnyEntity): |
61 """customized class for State entities |
58 """customized class for State entities |
62 |
59 |
63 provides a specific transitions method returning transitions that may be |
60 provides a specific transitions method returning transitions that may be |
64 passed by the current user for the given entity |
61 passed by the current user for the given entity |
65 """ |
62 """ |
66 id = 'State' |
63 id = 'State' |
67 fetch_attrs, fetch_order = fetch_config(['name']) |
64 fetch_attrs, fetch_order = fetch_config(['name']) |
68 rest_attr = 'eid' |
65 rest_attr = 'eid' |
69 |
66 |
70 __rtags__ = {'destination_state' : 'create', |
|
71 'allowed_transition' : 'create' |
|
72 } |
|
73 |
|
74 def transitions(self, entity, desteid=None): |
67 def transitions(self, entity, desteid=None): |
75 rql = ('Any T,N,DS where S allowed_transition T, S eid %(x)s, ' |
68 rql = ('Any T,N,DS where S allowed_transition T, S eid %(x)s, ' |
76 'T name N, T destination_state DS, ' |
69 'T name N, T destination_state DS, ' |
77 'T transition_of ET, ET name %(et)s') |
70 'T transition_of ET, ET name %(et)s') |
78 if desteid is not None: |
71 if desteid is not None: |
80 rset = self.req.execute(rql, {'x': self.eid, 'et': str(entity.e_schema), |
73 rset = self.req.execute(rql, {'x': self.eid, 'et': str(entity.e_schema), |
81 'ds': desteid}, 'x') |
74 'ds': desteid}, 'x') |
82 for tr in rset.entities(): |
75 for tr in rset.entities(): |
83 if tr.may_be_passed(entity.eid, self.eid): |
76 if tr.may_be_passed(entity.eid, self.eid): |
84 yield tr |
77 yield tr |
85 |
78 |
86 def after_deletion_path(self): |
79 def after_deletion_path(self): |
87 """return (path, parameters) which should be used as redirect |
80 """return (path, parameters) which should be used as redirect |
88 information when this entity is being deleted |
81 information when this entity is being deleted |
89 """ |
82 """ |
90 if self.state_of: |
83 if self.state_of: |
91 return self.state_of[0].rest_path(), {'vid': 'workflow'} |
84 return self.state_of[0].rest_path(), {'vid': 'workflow'} |
92 return super(State, self).after_deletion_path() |
85 return super(State, self).after_deletion_path() |
93 |
86 |
94 |
87 |
95 class TrInfo(AnyEntity): |
88 class TrInfo(AnyEntity): |
96 """customized class for Transition information entities |
89 """customized class for Transition information entities |
97 """ |
90 """ |
98 id = 'TrInfo' |
91 id = 'TrInfo' |
99 fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'], |
92 fetch_attrs, fetch_order = fetch_config(['creation_date', 'comment'], |
102 def for_entity(self): |
95 def for_entity(self): |
103 return self.wf_info_for and self.wf_info_for[0] |
96 return self.wf_info_for and self.wf_info_for[0] |
104 @property |
97 @property |
105 def previous_state(self): |
98 def previous_state(self): |
106 return self.from_state and self.from_state[0] |
99 return self.from_state and self.from_state[0] |
107 |
100 |
108 @property |
101 @property |
109 def new_state(self): |
102 def new_state(self): |
110 return self.to_state[0] |
103 return self.to_state[0] |
111 |
104 |
112 def after_deletion_path(self): |
105 def after_deletion_path(self): |