author | Erica Marco <erica.marco@logilab.fr> |
Mon, 23 Mar 2015 11:08:04 +0100 | |
changeset 10281 | cc9eb88377f4 |
parent 9615 | 6ba726dbf4fd |
child 10666 | 7f6b5f023884 |
permissions | -rw-r--r-- |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5164
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
18 |
"""Core hooks: workflow related hooks""" |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
|
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
__docformat__ = "restructuredtext en" |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
21 |
_ = unicode |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
22 |
|
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
23 |
from datetime import datetime |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
24 |
|
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
25 |
|
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
26 |
from cubicweb import RepositoryError, validation_error |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7879
diff
changeset
|
27 |
from cubicweb.predicates import is_instance, adaptable |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
28 |
from cubicweb.server import hook |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
29 |
|
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
30 |
|
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
31 |
def _change_state(cnx, x, oldstate, newstate): |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
32 |
nocheck = cnx.transaction_data.setdefault('skip-security', set()) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
33 |
nocheck.add((x, 'in_state', oldstate)) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
34 |
nocheck.add((x, 'in_state', newstate)) |
9469
032825bbacab
[multi-sources-removal] Drop entities.source column
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8695
diff
changeset
|
35 |
# delete previous state first |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
36 |
cnx.delete_relation(x, 'in_state', oldstate) |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
37 |
cnx.add_relation(x, 'in_state', newstate) |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
|
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
39 |
|
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
40 |
# operations ################################################################### |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
41 |
|
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
42 |
class _SetInitialStateOp(hook.Operation): |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
"""make initial state be a default state""" |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7294
diff
changeset
|
44 |
entity = None # make pylint happy |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
|
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
46 |
def precommit_event(self): |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
47 |
cnx = self.cnx |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
48 |
entity = self.entity |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
49 |
iworkflowable = entity.cw_adapt_to('IWorkflowable') |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
50 |
# if there is an initial state and the entity's state is not set, |
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
# use the initial state as a default state |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
52 |
if not (cnx.deleted_in_transaction(entity.eid) or entity.in_state) \ |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
53 |
and iworkflowable.current_workflow: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
54 |
state = iworkflowable.current_workflow.initial |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
55 |
if state: |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
56 |
cnx.add_relation(entity.eid, 'in_state', state.eid) |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
57 |
_FireAutotransitionOp(cnx, entity=entity) |
3536
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
58 |
|
3589
a5432f99f2d9
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
59 |
class _FireAutotransitionOp(hook.Operation): |
3536
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
60 |
"""try to fire auto transition after state changes""" |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7294
diff
changeset
|
61 |
entity = None # make pylint happy |
3536
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
62 |
|
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
63 |
def precommit_event(self): |
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
64 |
entity = self.entity |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
65 |
iworkflowable = entity.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
66 |
autotrs = list(iworkflowable.possible_transitions('auto')) |
3536
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
67 |
if autotrs: |
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
68 |
assert len(autotrs) == 1 |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
69 |
iworkflowable.fire_transition(autotrs[0]) |
3536
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
70 |
|
f6c9a5df80fb
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3449
diff
changeset
|
71 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
72 |
class _WorkflowChangedOp(hook.Operation): |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
73 |
"""fix entity current state when changing its workflow""" |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7294
diff
changeset
|
74 |
eid = wfeid = None # make pylint happy |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
75 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
76 |
def precommit_event(self): |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
77 |
# notice that enforcement that new workflow apply to the entity's type is |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
78 |
# done by schema rule, no need to check it here |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
79 |
cnx = self.cnx |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
80 |
pendingeids = cnx.transaction_data.get('pendingeids', ()) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
81 |
if self.eid in pendingeids: |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
82 |
return |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
83 |
entity = cnx.entity_from_eid(self.eid) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
84 |
iworkflowable = entity.cw_adapt_to('IWorkflowable') |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
85 |
# check custom workflow has not been rechanged to another one in the same |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
86 |
# transaction |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
87 |
mainwf = iworkflowable.main_workflow |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
88 |
if mainwf.eid == self.wfeid: |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
89 |
deststate = mainwf.initial |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
90 |
if not deststate: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
91 |
msg = _('workflow has no initial state') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
92 |
raise validation_error(entity, {('custom_workflow', 'subject'): msg}) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
93 |
if mainwf.state_by_eid(iworkflowable.current_state.eid): |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
94 |
# nothing to do |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
95 |
return |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
96 |
# if there are no history, simply go to new workflow's initial state |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
97 |
if not iworkflowable.workflow_history: |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
98 |
if iworkflowable.current_state.eid != deststate.eid: |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
99 |
_change_state(cnx, entity.eid, |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
100 |
iworkflowable.current_state.eid, deststate.eid) |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
101 |
_FireAutotransitionOp(cnx, entity=entity) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
102 |
return |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
103 |
msg = cnx._('workflow changed to "%s"') |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
104 |
msg %= cnx._(mainwf.name) |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
105 |
cnx.transaction_data[(entity.eid, 'customwf')] = self.wfeid |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
106 |
iworkflowable.change_state(deststate, msg, u'text/plain') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
107 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
108 |
|
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
109 |
class _CheckTrExitPoint(hook.Operation): |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7294
diff
changeset
|
110 |
treid = None # make pylint happy |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
111 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
112 |
def precommit_event(self): |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
113 |
tr = self.cnx.entity_from_eid(self.treid) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
114 |
outputs = set() |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
115 |
for ep in tr.subworkflow_exit: |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
116 |
if ep.subwf_state.eid in outputs: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
117 |
msg = _("can't have multiple exits on the same state") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
118 |
raise validation_error(self.treid, {('subworkflow_exit', 'subject'): msg}) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
119 |
outputs.add(ep.subwf_state.eid) |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
120 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
121 |
|
3675 | 122 |
class _SubWorkflowExitOp(hook.Operation): |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7294
diff
changeset
|
123 |
forentity = trinfo = None # make pylint happy |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
124 |
|
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
125 |
def precommit_event(self): |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
126 |
cnx = self.cnx |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
127 |
forentity = self.forentity |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
128 |
iworkflowable = forentity.cw_adapt_to('IWorkflowable') |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
129 |
trinfo = self.trinfo |
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
130 |
# we're in a subworkflow, check if we've reached an exit point |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
131 |
wftr = iworkflowable.subworkflow_input_transition() |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
132 |
if wftr is None: |
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
133 |
# inconsistency detected |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
134 |
msg = _("state doesn't belong to entity's current workflow") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
135 |
raise validation_error(self.trinfo, {('to_state', 'subject'): msg}) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
136 |
tostate = wftr.get_exit_point(forentity, trinfo.cw_attr_cache['to_state']) |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
137 |
if tostate is not None: |
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
138 |
# reached an exit point |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
139 |
msg = _('exiting from subworkflow %s') |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
140 |
msg %= cnx._(iworkflowable.current_workflow.name) |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
141 |
cnx.transaction_data[(forentity.eid, 'subwfentrytr')] = True |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
142 |
iworkflowable.change_state(tostate, msg, u'text/plain', tr=wftr) |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
143 |
|
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
144 |
|
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
145 |
# hooks ######################################################################## |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
146 |
|
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
147 |
class WorkflowHook(hook.Hook): |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
148 |
__abstract__ = True |
7294
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
149 |
category = 'metadata' |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
|
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
151 |
|
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
152 |
class SetInitialStateHook(WorkflowHook): |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
153 |
__regid__ = 'wfsetinitial' |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
154 |
__select__ = WorkflowHook.__select__ & adaptable('IWorkflowable') |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
155 |
events = ('after_add_entity',) |
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
156 |
|
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
157 |
def __call__(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2841
diff
changeset
|
158 |
_SetInitialStateOp(self._cw, entity=self.entity) |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
159 |
|
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
160 |
|
7294
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
161 |
class FireTransitionHook(WorkflowHook): |
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
162 |
"""check the transition is allowed and add missing information into the |
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
163 |
TrInfo entity. |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
164 |
|
7294
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
165 |
Expect that: |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
166 |
* wf_info_for inlined relation is set |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
167 |
* by_transition or to_state (managers only) inlined relation is set |
7294
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
168 |
|
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
169 |
Check for automatic transition to be fired at the end |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
170 |
""" |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
171 |
__regid__ = 'wffiretransition' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5685
diff
changeset
|
172 |
__select__ = WorkflowHook.__select__ & is_instance('TrInfo') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
173 |
events = ('before_add_entity',) |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
174 |
|
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
175 |
def __call__(self): |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
176 |
cnx = self._cw |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
177 |
entity = self.entity |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
178 |
# first retreive entity to which the state change apply |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
179 |
try: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
180 |
foreid = entity.cw_attr_cache['wf_info_for'] |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
181 |
except KeyError: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
182 |
msg = _('mandatory relation') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
183 |
raise validation_error(entity, {('wf_info_for', 'subject'): msg}) |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
184 |
forentity = cnx.entity_from_eid(foreid) |
6757
bc878ec35794
#1382705 forbid with sql level locking the simultaneous fireing of a transition on a given entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6142
diff
changeset
|
185 |
# see comment in the TrInfo entity definition |
bc878ec35794
#1382705 forbid with sql level locking the simultaneous fireing of a transition on a given entity
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6142
diff
changeset
|
186 |
entity.cw_edited['tr_count']=len(forentity.reverse_wf_info_for) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
187 |
iworkflowable = forentity.cw_adapt_to('IWorkflowable') |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
188 |
# then check it has a workflow set, unless we're in the process of changing |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
189 |
# entity's workflow |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
190 |
if cnx.transaction_data.get((forentity.eid, 'customwf')): |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
191 |
wfeid = cnx.transaction_data[(forentity.eid, 'customwf')] |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
192 |
wf = cnx.entity_from_eid(wfeid) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
193 |
else: |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
194 |
wf = iworkflowable.current_workflow |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
195 |
if wf is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
196 |
msg = _('related entity has no workflow set') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
197 |
raise validation_error(entity, {None: msg}) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
198 |
# then check it has a state set |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
199 |
fromstate = iworkflowable.current_state |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
200 |
if fromstate is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
201 |
msg = _('related entity has no state') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
202 |
raise validation_error(entity, {None: msg}) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
203 |
# True if we are coming back from subworkflow |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
204 |
swtr = cnx.transaction_data.pop((forentity.eid, 'subwfentrytr'), None) |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
205 |
cowpowers = (cnx.user.is_in_group('managers') |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
206 |
or not cnx.write_security) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
207 |
# no investigate the requested state change... |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
208 |
try: |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
209 |
treid = entity.cw_attr_cache['by_transition'] |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
210 |
except KeyError: |
3894
27cbf98ad863
forgotten stuff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
211 |
# no transition set, check user is a manager and destination state |
27cbf98ad863
forgotten stuff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
212 |
# is specified (and valid) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
213 |
if not cowpowers: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
214 |
msg = _('mandatory relation') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
215 |
raise validation_error(entity, {('by_transition', 'subject'): msg}) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
216 |
deststateeid = entity.cw_attr_cache.get('to_state') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
217 |
if not deststateeid: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
218 |
msg = _('mandatory relation') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
219 |
raise validation_error(entity, {('by_transition', 'subject'): msg}) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
220 |
deststate = wf.state_by_eid(deststateeid) |
3777
3ef8cdb5fb1c
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3739
diff
changeset
|
221 |
if deststate is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
222 |
msg = _("state doesn't belong to entity's workflow") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
223 |
raise validation_error(entity, {('to_state', 'subject'): msg}) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
224 |
else: |
3894
27cbf98ad863
forgotten stuff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
225 |
# check transition is valid and allowed, unless we're coming back |
27cbf98ad863
forgotten stuff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
226 |
# from subworkflow |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
227 |
tr = cnx.entity_from_eid(treid) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
228 |
if swtr is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
229 |
qname = ('by_transition', 'subject') |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
230 |
if tr is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
231 |
msg = _("transition doesn't belong to entity's workflow") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
232 |
raise validation_error(entity, {qname: msg}) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
233 |
if not tr.has_input_state(fromstate): |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
234 |
msg = _("transition %(tr)s isn't allowed from %(st)s") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
235 |
raise validation_error(entity, {qname: msg}, { |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
236 |
'tr': tr.name, 'st': fromstate.name}, ['tr', 'st']) |
4003
b9436fe77c9e
fix bad merge
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
3894
diff
changeset
|
237 |
if not tr.may_be_fired(foreid): |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
238 |
msg = _("transition may not be fired") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
239 |
raise validation_error(entity, {qname: msg}) |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
240 |
deststateeid = entity.cw_attr_cache.get('to_state') |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
241 |
if deststateeid is not None: |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4307
diff
changeset
|
242 |
if not cowpowers and deststateeid != tr.destination(forentity).eid: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
243 |
msg = _("transition isn't allowed") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
244 |
raise validation_error(entity, {('by_transition', 'subject'): msg}) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
245 |
if swtr is None: |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
246 |
deststate = cnx.entity_from_eid(deststateeid) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
247 |
if not cowpowers and deststate is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
248 |
msg = _("state doesn't belong to entity's workflow") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
249 |
raise validation_error(entity, {('to_state', 'subject'): msg}) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
250 |
else: |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4307
diff
changeset
|
251 |
deststateeid = tr.destination(forentity).eid |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
252 |
# everything is ok, add missing information on the trinfo entity |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
253 |
entity.cw_edited['from_state'] = fromstate.eid |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
254 |
entity.cw_edited['to_state'] = deststateeid |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
255 |
nocheck = cnx.transaction_data.setdefault('skip-security', set()) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
256 |
nocheck.add((entity.eid, 'from_state', fromstate.eid)) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
257 |
nocheck.add((entity.eid, 'to_state', deststateeid)) |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
258 |
_FireAutotransitionOp(cnx, entity=forentity) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
259 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
260 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
261 |
class FiredTransitionHook(WorkflowHook): |
7294
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
262 |
"""change related entity state and handle exit of subworkflow""" |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
263 |
__regid__ = 'wffiretransition' |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5685
diff
changeset
|
264 |
__select__ = WorkflowHook.__select__ & is_instance('TrInfo') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
265 |
events = ('after_add_entity',) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
266 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
267 |
def __call__(self): |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
268 |
trinfo = self.entity |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
269 |
rcache = trinfo.cw_attr_cache |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
270 |
_change_state(self._cw, rcache['wf_info_for'], rcache['from_state'], |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
271 |
rcache['to_state']) |
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
272 |
forentity = self._cw.entity_from_eid(rcache['wf_info_for']) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
273 |
iworkflowable = forentity.cw_adapt_to('IWorkflowable') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
274 |
assert iworkflowable.current_state.eid == rcache['to_state'] |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
275 |
if iworkflowable.main_workflow.eid != iworkflowable.current_workflow.eid: |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3654
diff
changeset
|
276 |
_SubWorkflowExitOp(self._cw, forentity=forentity, trinfo=trinfo) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
277 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
278 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
279 |
class CheckInStateChangeAllowed(WorkflowHook): |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
280 |
"""check state apply, in case of direct in_state change using unsafe execute |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
281 |
""" |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
282 |
__regid__ = 'wfcheckinstate' |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
283 |
__select__ = WorkflowHook.__select__ & hook.match_rtype('in_state') |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
284 |
events = ('before_add_relation',) |
7294
2af1a4cecda5
[workflow hooks] reuse metadata/integrity categories instead of a new 'workflow' category and drop useless hook
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6757
diff
changeset
|
285 |
category = 'integrity' |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
286 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
287 |
def __call__(self): |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
288 |
cnx = self._cw |
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
289 |
nocheck = cnx.transaction_data.get('skip-security', ()) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
290 |
if (self.eidfrom, 'in_state', self.eidto) in nocheck: |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
291 |
# state changed through TrInfo insertion, so we already know it's ok |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
292 |
return |
9615
6ba726dbf4fd
[hooks/workflow] use a cnx not a session
Julien Cristau <julien.cristau@logilab.fr>
parents:
9469
diff
changeset
|
293 |
entity = cnx.entity_from_eid(self.eidfrom) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
294 |
iworkflowable = entity.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
295 |
mainwf = iworkflowable.main_workflow |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
296 |
if mainwf is None: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
297 |
msg = _('entity has no workflow set') |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
298 |
raise validation_error(entity, {None: msg}) |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
299 |
for wf in mainwf.iter_workflows(): |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
300 |
if wf.state_by_eid(self.eidto): |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
301 |
break |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
302 |
else: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
303 |
msg = _("state doesn't belong to entity's workflow. You may " |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
304 |
"want to set a custom workflow for this entity first.") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
305 |
raise validation_error(self.eidfrom, {('in_state', 'subject'): msg}) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
306 |
if iworkflowable.current_workflow and wf.eid != iworkflowable.current_workflow.eid: |
8556
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
307 |
msg = _("state doesn't belong to entity's current workflow") |
bbe0d6985e59
[validation error] refactor validation error handling so translation is done on the web side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
308 |
raise validation_error(self.eidfrom, {('in_state', 'subject'): msg}) |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
309 |
|
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
310 |
|
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
311 |
class SetModificationDateOnStateChange(WorkflowHook): |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
312 |
"""update entity's modification date after changing its state""" |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
313 |
__regid__ = 'wfsyncmdate' |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
314 |
__select__ = WorkflowHook.__select__ & hook.match_rtype('in_state') |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
315 |
events = ('after_add_relation',) |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
316 |
|
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
317 |
def __call__(self): |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2841
diff
changeset
|
318 |
if self._cw.added_in_transaction(self.eidfrom): |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
319 |
# new entity, not needed |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
320 |
return |
2847
c2ee28f4d4b1
use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2841
diff
changeset
|
321 |
entity = self._cw.entity_from_eid(self.eidfrom) |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
322 |
try: |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8190
diff
changeset
|
323 |
entity.cw_set(modification_date=datetime.now()) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8556
diff
changeset
|
324 |
except RepositoryError as ex: |
2841
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
325 |
# usually occurs if entity is coming from a read-only source |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
326 |
# (eg ldap user) |
107ba1c45227
rewrite hooks in sobjects as new Hook style into hooks sub-package
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2835
diff
changeset
|
327 |
self.warning('cant change modification date for %s: %s', entity, ex) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
328 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
329 |
|
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
330 |
class CheckWorkflowTransitionExitPoint(WorkflowHook): |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
331 |
"""check that there is no multiple exits from the same state""" |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
332 |
__regid__ = 'wfcheckwftrexit' |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
333 |
__select__ = WorkflowHook.__select__ & hook.match_rtype('subworkflow_exit') |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
334 |
events = ('after_add_relation',) |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
335 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
336 |
def __call__(self): |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
337 |
_CheckTrExitPoint(self._cw, treid=self.eidfrom) |
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
338 |
|
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
339 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
340 |
class SetCustomWorkflow(WorkflowHook): |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
341 |
__regid__ = 'wfsetcustom' |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
342 |
__select__ = WorkflowHook.__select__ & hook.match_rtype('custom_workflow') |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
343 |
events = ('after_add_relation',) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
344 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
345 |
def __call__(self): |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
346 |
_WorkflowChangedOp(self._cw, eid=self.eidfrom, wfeid=self.eidto) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
347 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
348 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
349 |
class DelCustomWorkflow(SetCustomWorkflow): |
3376
f5c69485381f
[appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3072
diff
changeset
|
350 |
__regid__ = 'wfdelcustom' |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
351 |
events = ('after_delete_relation',) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
352 |
|
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
353 |
def __call__(self): |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
354 |
entity = self._cw.entity_from_eid(self.eidfrom) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
355 |
typewf = entity.cw_adapt_to('IWorkflowable').cwetype_workflow() |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
356 |
if typewf is not None: |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
357 |
_WorkflowChangedOp(self._cw, eid=self.eidfrom, wfeid=typewf.eid) |
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2880
diff
changeset
|
358 |