0001-workflow-register-a-part-on-user-assignation-error-6.patch
tests/form_pages/test_all.py | ||
---|---|---|
30 | 30 |
from wcs.qommon.template import Template |
31 | 31 |
from wcs.roles import logged_users_role |
32 | 32 |
from wcs.tracking_code import TrackingCode |
33 |
from wcs.wf.create_formdata import Mapping |
|
33 |
from wcs.wf.create_formdata import JournalAssignationErrorPart, Mapping
|
|
34 | 34 |
from wcs.wf.form import WorkflowFormFieldsFormDef |
35 | 35 |
from wcs.wf.wscall import JournalWsCallErrorPart |
36 | 36 |
from wcs.workflows import ( |
... | ... | |
5684 | 5684 |
assert formdatas[0].data['0'] == 'foo@localhost' |
5685 | 5685 | |
5686 | 5686 | |
5687 |
def test_form_worklow_multiple_identical_status_with_wserror(pub):
|
|
5687 |
def test_form_worklow_multiple_identical_status_with_journal_error(pub):
|
|
5688 | 5688 |
user = create_user(pub) |
5689 | 5689 | |
5690 | 5690 |
formdef = create_formdef() |
... | ... | |
5724 | 5724 |
resp = app.post(formdata.get_url() + 'jump/trigger/XXX', status=302) |
5725 | 5725 |
formdata = formdef.data_class().get(formdata.id) |
5726 | 5726 |
formdata.evolution[-1].add_part(JournalWsCallErrorPart('bla', 'bla', {})) |
5727 |
formdata.evolution[-1].add_part(JournalAssignationErrorPart('foo', 'foo')) |
|
5727 | 5728 |
formdata.store() |
5728 | 5729 | |
5729 | 5730 |
# mark user as owner so it can check the UI |
... | ... | |
5735 | 5736 |
role.allows_backoffice_access = True |
5736 | 5737 |
role.store() |
5737 | 5738 |
resp = app.get(formdata.get_url(backoffice=True)) |
5738 |
assert resp.text.count('<li class="msg') == 3 |
|
5739 |
assert len(resp.pyquery('div.msg')) == 3 |
|
5740 |
assert len(resp.pyquery('div.msg div.ws-error')) == 3 |
|
5741 |
assert len(resp.pyquery('div.msg div.assignation-error')) == 3 |
|
5739 | 5742 | |
5740 | 5743 | |
5741 | 5744 |
def test_form_page_verified_prefill_error_page(pub): |
tests/test_formdata.py | ||
---|---|---|
26 | 26 |
from wcs.qommon.template import Template |
27 | 27 |
from wcs.qommon.upload_storage import PicklableUpload |
28 | 28 |
from wcs.variables import LazyFormData |
29 |
from wcs.wf.create_formdata import JournalAssignationErrorPart |
|
29 | 30 |
from wcs.wf.register_comment import JournalEvolutionPart |
30 | 31 |
from wcs.wf.wscall import JournalWsCallErrorPart |
31 | 32 |
from wcs.workflows import ( |
... | ... | |
493 | 494 |
d.store() |
494 | 495 |
evo.add_part(JournalEvolutionPart(d, "ok", None)) |
495 | 496 |
evo.add_part(JournalWsCallErrorPart("summary", "label", "data")) |
497 |
evo.add_part(JournalAssignationErrorPart("summary", "label")) |
|
496 | 498 |
evo = Evolution() |
497 | 499 |
evo.time = time.localtime() |
498 | 500 |
evo.status = 'wf-%s' % st_finished.id |
... | ... | |
509 | 511 |
assert export['evolution'][0]['who']['email'] == local_user.email |
510 | 512 |
assert export['evolution'][0]['who']['NameID'] == local_user.name_identifiers |
511 | 513 |
assert 'parts' in export['evolution'][0] |
512 |
assert len(export['evolution'][0]['parts']) == 2
|
|
514 |
assert len(export['evolution'][0]['parts']) == 3
|
|
513 | 515 |
assert export['evolution'][0]['parts'][0]['type'] == 'workflow-comment' |
514 | 516 |
assert export['evolution'][0]['parts'][0]['content'] == 'ok' |
515 | 517 |
assert export['evolution'][0]['parts'][1]['type'] == 'wscall-error' |
516 | 518 |
assert export['evolution'][0]['parts'][1]['summary'] == 'summary' |
517 | 519 |
assert export['evolution'][0]['parts'][1]['label'] == 'label' |
518 | 520 |
assert export['evolution'][0]['parts'][1]['data'] == 'data' |
521 |
assert export['evolution'][0]['parts'][2]['type'] == 'assignation-error' |
|
522 |
assert export['evolution'][0]['parts'][2]['summary'] == 'summary' |
|
523 |
assert export['evolution'][0]['parts'][2]['label'] == 'label' |
|
519 | 524 |
assert export['evolution'][1]['status'] == st_finished.id |
520 | 525 |
assert 'time' in export['evolution'][1] |
521 | 526 |
assert export['evolution'][1]['who']['id'] == local_user.id |
... | ... | |
530 | 535 |
assert 'time' in export['evolution'][0] |
531 | 536 |
assert 'who' not in export['evolution'][0] |
532 | 537 |
assert 'parts' in export['evolution'][0] |
533 |
assert len(export['evolution'][0]['parts']) == 2
|
|
538 |
assert len(export['evolution'][0]['parts']) == 3
|
|
534 | 539 |
assert len(export['evolution'][0]['parts'][0]) == 2 |
535 | 540 |
assert export['evolution'][0]['parts'][0]['type'] == 'workflow-comment' |
536 | 541 |
assert len(export['evolution'][0]['parts'][1]) == 1 |
537 | 542 |
assert export['evolution'][0]['parts'][1]['type'] == 'wscall-error' |
543 |
assert len(export['evolution'][0]['parts'][2]) == 1 |
|
544 |
assert export['evolution'][0]['parts'][2]['type'] == 'assignation-error' |
|
538 | 545 |
assert export['evolution'][1]['status'] == st_finished.id |
539 | 546 |
assert 'time' in export['evolution'][1] |
540 | 547 |
assert 'who' not in export['evolution'][0] |
tests/workflow/test_carddata.py | ||
---|---|---|
10 | 10 |
from wcs.formdef import FormDef |
11 | 11 |
from wcs.qommon.http_request import HTTPRequest |
12 | 12 |
from wcs.qommon.upload_storage import PicklableUpload |
13 |
from wcs.wf.create_formdata import Mapping |
|
13 |
from wcs.wf.create_formdata import JournalAssignationErrorPart, Mapping
|
|
14 | 14 |
from wcs.workflows import Workflow |
15 | 15 | |
16 | 16 |
from ..utilities import clean_temporary_pub, create_temporary_pub |
... | ... | |
505 | 505 | |
506 | 506 |
assert carddef.data_class().count() == 1 |
507 | 507 |
assert carddef.data_class().select()[0].user is None |
508 |
assert isinstance(formdata.evolution[1].parts[0], JournalAssignationErrorPart) |
|
509 |
assert formdata.evolution[1].parts[0].label == 'Create Card Data (My card)' |
|
510 |
assert ( |
|
511 |
formdata.evolution[1].parts[0].summary |
|
512 |
== 'Failed to attach user (not found: "%s")' % invalid_user[1] |
|
513 |
) |
|
508 | 514 |
if pub.loggederror_class: |
509 |
assert pub.loggederror_class.count() == 1 |
|
510 |
logged_error = pub.loggederror_class.select()[0] |
|
511 |
assert logged_error.summary == 'Failed to attach user (not found: "%s")' % invalid_user[1] |
|
512 |
assert logged_error.formdata_id == str(formdata.id) |
|
515 |
assert pub.loggederror_class.count() == 0 # no logged error |
|
513 | 516 | |
514 | 517 |
# user association on invalid template |
515 | 518 |
carddef.data_class().wipe() |
... | ... | |
1546 | 1549 |
formdata.perform_workflow() |
1547 | 1550 | |
1548 | 1551 |
assert carddef.data_class().select()[0].user is None |
1552 |
assert isinstance(formdata.evolution[1].parts[0], JournalAssignationErrorPart) |
|
1553 |
assert formdata.evolution[1].parts[0].label == 'Assign Card Data (Person)' |
|
1554 |
assert formdata.evolution[1].parts[0].summary == 'Failed to attach user (not found: "zzz")' |
|
1549 | 1555 |
if pub.loggederror_class: |
1550 |
assert pub.loggederror_class.count() == 1 |
|
1551 |
logged_error = pub.loggederror_class.select()[0] |
|
1552 |
assert logged_error.summary == 'Failed to attach user (not found: "zzz")' |
|
1553 |
assert logged_error.formdata_id == str(formdata.id) |
|
1556 |
assert pub.loggederror_class.count() == 0 # no logged error |
|
1554 | 1557 | |
1555 | 1558 |
# user association on invalid template |
1556 | 1559 |
carddata.user_id = user2.id |
wcs/wf/create_formdata.py | ||
---|---|---|
19 | 19 | |
20 | 20 |
from django.utils.functional import cached_property |
21 | 21 |
from quixote import get_publisher, get_request, get_session |
22 |
from quixote.html import htmltext |
|
22 |
from quixote.html import TemplateIO, htmltext
|
|
23 | 23 | |
24 | 24 |
from wcs.formdef import FormDef |
25 | 25 |
from wcs.qommon import _, ngettext |
... | ... | |
129 | 129 |
self.value.sort(key=lambda mapping: self.ranks.get(str(mapping.field_id), 9999)) |
130 | 130 | |
131 | 131 | |
132 |
class JournalAssignationErrorPart(EvolutionPart): |
|
133 |
summary = None |
|
134 |
label = None |
|
135 |
render_for_fts = None |
|
136 | ||
137 |
def __init__(self, summary, label=None): |
|
138 |
self.summary = summary |
|
139 |
self.label = label |
|
140 | ||
141 |
def is_hidden(self): |
|
142 |
return not (get_request() and get_request().get_path().startswith('/backoffice/')) |
|
143 | ||
144 |
def view(self): |
|
145 |
r = TemplateIO(html=True) |
|
146 |
r += htmltext('<div class="assignation-error">') |
|
147 |
r += htmltext('<h4 class="foldable folded">') |
|
148 |
r += str(_('Assignation error during action "%s"') % self.label) |
|
149 |
r += htmltext('</h4>') |
|
150 |
r += htmltext('<div>') |
|
151 |
r += htmltext('<p>%s</p>\n') % self.summary |
|
152 |
r += htmltext('</div>') |
|
153 |
r += htmltext('</div>') |
|
154 |
return r.getvalue() |
|
155 | ||
156 |
def get_json_export_dict(self, anonymise=False, include_files=True): |
|
157 |
d = { |
|
158 |
'type': 'assignation-error', |
|
159 |
} |
|
160 |
if not anonymise: |
|
161 |
d.update( |
|
162 |
{ |
|
163 |
'summary': self.summary, |
|
164 |
'label': self.label, |
|
165 |
} |
|
166 |
) |
|
167 |
return d |
|
168 | ||
169 | ||
132 | 170 |
class LinkedFormdataEvolutionPart(EvolutionPart): |
133 | 171 |
formdef_class = FormDef |
134 | 172 |
attach_to_history = False |
... | ... | |
539 | 577 |
else: |
540 | 578 |
dest.user = get_publisher().user_class.lookup_by_string(str(value)) |
541 | 579 |
if value and not dest.user: |
542 |
get_publisher().record_error( |
|
543 |
_('Failed to attach user (not found: "%s")') % value, |
|
544 |
formdata=src, |
|
545 |
status_item=self, |
|
580 |
src.evolution[-1].add_part( |
|
581 |
JournalAssignationErrorPart( |
|
582 |
_('Failed to attach user (not found: "%s")') % value, |
|
583 |
"%s (%s)" % (self.description, self.formdef.name), |
|
584 |
) |
|
546 | 585 |
) |
586 |
src.store() |
|
547 | 587 |
else: |
548 | 588 |
dest.user_id = None |
549 | 589 | |
550 |
- |