0001-api-split-full-param-69108.patch
tests/api/test_formdata.py | ||
---|---|---|
277 | 277 |
formdata.just_created() |
278 | 278 |
formdata.store() |
279 | 279 | |
280 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list', user=local_user)) |
|
281 |
assert 'user' not in resp.json[0] |
|
282 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list?full=on', user=local_user)) |
|
283 |
assert resp.json[0]['user'] == { |
|
284 |
'id': local_user.id, |
|
285 |
'NameID': ['0123456789'], |
|
286 |
'name': 'Jean Darmette', |
|
287 |
'email': 'jean.darmette@triffouilis.fr', |
|
288 |
} |
|
280 |
for params in [ |
|
281 |
'', |
|
282 |
'?include-evolution=on', |
|
283 |
'?include-roles=on', |
|
284 |
'?include-submission=on', |
|
285 |
'?include-workflow=on', |
|
286 |
]: |
|
287 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
288 |
assert 'user' not in resp.json[0] |
|
289 |
for params in ['?full=on', '?include-fields=on']: |
|
290 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
291 |
assert resp.json[0]['user'] == { |
|
292 |
'id': local_user.id, |
|
293 |
'NameID': ['0123456789'], |
|
294 |
'name': 'Jean Darmette', |
|
295 |
'email': 'jean.darmette@triffouilis.fr', |
|
296 |
} |
|
289 | 297 | |
290 | 298 | |
291 | 299 |
def test_formdata_submission_fields(pub, local_user): |
... | ... | |
322 | 330 |
formdata.just_created() |
323 | 331 |
formdata.store() |
324 | 332 | |
325 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list', user=local_user)) |
|
326 |
assert 'submission' not in resp.json[0] |
|
327 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list?full=on', user=local_user)) |
|
328 |
assert resp.json[0]['submission'] == { |
|
329 |
'backoffice': False, |
|
330 |
'channel': 'web', |
|
331 |
'agent': {'id': agent.id, 'name': 'agent'}, |
|
332 |
} |
|
333 |
for params in [ |
|
334 |
'', |
|
335 |
'?include-fields=on', |
|
336 |
'?include-evolution=on', |
|
337 |
'?include-roles=on', |
|
338 |
'?include-workflow=on', |
|
339 |
]: |
|
340 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
341 |
assert 'submission' not in resp.json[0] |
|
342 |
for params in ['?full=on', '?include-submission=on']: |
|
343 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
344 |
assert resp.json[0]['submission'] == { |
|
345 |
'backoffice': False, |
|
346 |
'channel': 'web', |
|
347 |
'agent': {'id': agent.id, 'name': 'agent'}, |
|
348 |
} |
|
333 | 349 |
resp = get_app(pub).get(sign_uri('/api/forms/test/%s/' % formdata.id, user=local_user)) |
334 | 350 |
assert resp.json['submission'] == { |
335 | 351 |
'backoffice': False, |
... | ... | |
547 | 563 |
assert resp.json['workflow']['data']['blah']['content_type'] == 'text/plain' |
548 | 564 |
assert base64.decodebytes(force_bytes(resp.json['workflow']['data']['blah']['content'])) == b'test' |
549 | 565 |
assert base64.decodebytes(force_bytes(resp.json['workflow']['data']['blah2']['content'])) == b'test' |
566 |
for params in [ |
|
567 |
'', |
|
568 |
'?include-fields=on', |
|
569 |
'?include-evolution=on', |
|
570 |
'?include-roles=on', |
|
571 |
'?include-submission=on', |
|
572 |
]: |
|
573 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
574 |
assert 'workflow' not in resp.json[0] |
|
575 |
for params in ['?full=on', '?include-workflow=on']: |
|
576 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
577 |
assert 'workflow' in resp.json[0] |
|
550 | 578 | |
551 | 579 | |
552 | 580 |
def test_formdata_with_evolution_part_attachment(pub, local_user): |
... | ... | |
595 | 623 |
assert len(resp.json['evolution']) == 1 |
596 | 624 |
assert 'parts' not in resp.json['evolution'][0] |
597 | 625 | |
598 |
# check this doesn't get into list of forms API |
|
599 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list?full=on', user=local_user)) |
|
600 |
assert 'hello.txt' not in resp.text |
|
626 |
for params in [ |
|
627 |
'', |
|
628 |
'?include-fields=on', |
|
629 |
'?include-roles=on', |
|
630 |
'?include-submission=on', |
|
631 |
'?include-workflow=on', |
|
632 |
]: |
|
633 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
634 |
assert 'evolution' not in resp.json[0] |
|
635 |
# check this doesn't get into list of forms API |
|
636 |
assert 'hello.txt' not in resp.text |
|
637 |
for params in ['?full=on', '?include-evolution=on']: |
|
638 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
639 |
assert 'evolution' in resp.json[0] |
|
640 |
# check this doesn't get into list of forms API |
|
641 |
assert 'hello.txt' not in resp.text |
|
601 | 642 | |
602 | 643 | |
603 | 644 |
def test_formdata_with_evolution_part_attachment_to(pub, local_user): |
... | ... | |
656 | 697 |
assert resp.json['evolution'][0]['parts'][0]['type'] == 'workflow-comment' |
657 | 698 | |
658 | 699 |
# check this doesn't get into list of forms API |
659 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list?full=on', user=local_user)) |
|
660 |
assert len(resp.json[0]['evolution']) == 1 |
|
661 |
assert len(resp.json[0]['evolution'][0]['parts']) == 1 |
|
662 |
assert resp.json[0]['evolution'][0]['parts'][0]['type'] == 'workflow-comment' |
|
700 |
for params in [ |
|
701 |
'', |
|
702 |
'?include-fields=on', |
|
703 |
'?include-roles=on', |
|
704 |
'?include-submission=on', |
|
705 |
'?include-workflow=on', |
|
706 |
]: |
|
707 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
708 |
assert 'evolution' not in resp.json[0] |
|
709 |
for params in ['?full=on', '?include-evolution=on']: |
|
710 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
711 |
assert len(resp.json[0]['evolution']) == 1 |
|
712 |
assert len(resp.json[0]['evolution'][0]['parts']) == 1 |
|
713 |
assert resp.json[0]['evolution'][0]['parts'][0]['type'] == 'workflow-comment' |
|
663 | 714 | |
664 | 715 | |
665 | 716 |
def test_formdata_with_evolution_part_comment(pub, local_user): |
... | ... | |
706 | 757 |
assert 'parts' not in resp.json['evolution'][0] |
707 | 758 | |
708 | 759 | |
760 |
def test_formdata_with_roles(pub, local_user): |
|
761 |
pub.role_class.wipe() |
|
762 |
role = pub.role_class(name='test') |
|
763 |
role.store() |
|
764 |
local_user.roles = [role.id] |
|
765 |
local_user.store() |
|
766 | ||
767 |
FormDef.wipe() |
|
768 |
formdef = FormDef() |
|
769 |
formdef.name = 'test' |
|
770 |
formdef.workflow_roles = {'_receiver': role.id} |
|
771 |
formdef.fields = [] |
|
772 |
formdef.store() |
|
773 | ||
774 |
data_class = formdef.data_class() |
|
775 |
data_class.wipe() |
|
776 |
formdata = data_class() |
|
777 |
formdata.just_created() |
|
778 |
formdata.status = 'wf-new' |
|
779 |
formdata.user_id = local_user.id |
|
780 |
formdata.store() |
|
781 | ||
782 |
for params in [ |
|
783 |
'', |
|
784 |
'?include-fields=on', |
|
785 |
'?include-evolution=on', |
|
786 |
'?include-submission=on', |
|
787 |
'?include-workflow=on', |
|
788 |
]: |
|
789 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
790 |
assert 'roles' not in resp.json[0] |
|
791 |
for params in ['?full=on', '?include-roles=on']: |
|
792 |
resp = get_app(pub).get(sign_uri('/api/forms/test/list%s' % params, user=local_user)) |
|
793 |
assert 'roles' in resp.json[0] |
|
794 | ||
795 | ||
709 | 796 |
def test_api_list_formdata(pub, local_user): |
710 | 797 |
pub.role_class.wipe() |
711 | 798 |
role = pub.role_class(name='test') |
wcs/backoffice/management.py | ||
---|---|---|
2461 | 2461 |
view_digest_key = 'custom-view:%s' % self.view.get_url_slug() |
2462 | 2462 |
if view_digest_key in (self.formdef.digest_templates or {}): |
2463 | 2463 |
digest_key = view_digest_key |
2464 |
if get_request().form.get('full') == 'on': |
|
2464 |
full = get_request().form.get('full') == 'on' |
|
2465 |
include_fields = get_request().form.get('include-fields') == 'on' or full |
|
2466 |
include_evolution = get_request().form.get('include-evolution') == 'on' or full |
|
2467 |
include_roles = get_request().form.get('include-roles') == 'on' or full |
|
2468 |
include_submission = get_request().form.get('include-submission') == 'on' or full |
|
2469 |
include_workflow = get_request().form.get('include-workflow') == 'on' or full |
|
2470 |
if include_fields or include_evolution or include_roles or include_submission or include_workflow: |
|
2465 | 2471 |
output = JsonFileExportAfterJob(self.formdef).create_json_export( |
2466 | 2472 |
items, |
2467 | 2473 |
user=user, |
2468 | 2474 |
anonymise=anonymise, |
2469 | 2475 |
digest_key=digest_key, |
2470 |
include_evolution=True,
|
|
2476 |
include_evolution=include_evolution,
|
|
2471 | 2477 |
include_files=False, |
2472 |
include_roles=True, |
|
2478 |
include_roles=include_roles, |
|
2479 |
include_submission=include_submission, |
|
2480 |
include_fields=include_fields, |
|
2473 | 2481 |
include_unnamed_fields=False, |
2482 |
include_workflow=include_workflow, |
|
2474 | 2483 |
) |
2475 | 2484 |
else: |
2476 | 2485 |
output = [ |
... | ... | |
4315 | 4324 |
include_evolution, |
4316 | 4325 |
include_files, |
4317 | 4326 |
include_roles, |
4327 |
include_submission, |
|
4328 |
include_fields, |
|
4318 | 4329 |
include_unnamed_fields, |
4330 |
include_workflow, |
|
4319 | 4331 |
): |
4332 |
# noqa pylint: disable=too-many-arguments |
|
4320 | 4333 |
formdef = self.kwargs['formdef_class'].get(self.kwargs['formdef_id']) |
4321 | 4334 |
prefetched_users = None |
4322 | 4335 |
prefetched_roles = None |
... | ... | |
4355 | 4368 |
include_evolution=include_evolution, |
4356 | 4369 |
include_files=include_files, |
4357 | 4370 |
include_roles=include_roles, |
4371 |
include_submission=include_submission, |
|
4372 |
include_fields=include_fields, |
|
4358 | 4373 |
include_unnamed_fields=include_unnamed_fields, |
4374 |
include_workflow=include_workflow, |
|
4359 | 4375 |
) |
4360 | 4376 |
data.pop('digests') |
4361 | 4377 |
if digest_key: |
... | ... | |
4375 | 4391 |
include_evolution=False, |
4376 | 4392 |
include_files=True, |
4377 | 4393 |
include_roles=False, |
4394 |
include_submission=True, |
|
4395 |
include_fields=True, |
|
4378 | 4396 |
include_unnamed_fields=True, |
4397 |
include_workflow=True, |
|
4379 | 4398 |
) |
4380 | 4399 |
}, |
4381 | 4400 |
indent=2, |
wcs/formdata.py | ||
---|---|---|
1357 | 1357 |
prefetched_roles=None, |
1358 | 1358 |
include_evolution=True, |
1359 | 1359 |
include_roles=True, |
1360 |
include_submission=True, |
|
1361 |
include_fields=True, |
|
1360 | 1362 |
include_unnamed_fields=False, |
1363 |
include_workflow=True, |
|
1361 | 1364 |
): |
1365 |
# noqa pylint: disable=too-many-arguments |
|
1362 | 1366 |
data = {} |
1363 | 1367 |
data['id'] = str(self.id) |
1364 |
data['digests'] = self.digests |
|
1365 | 1368 |
data['display_id'] = self.get_display_id() |
1366 | 1369 |
data['display_name'] = self.get_display_name() |
1370 |
data['digests'] = self.digests |
|
1367 | 1371 |
data['text'] = self.get_display_label(digest_key=digest_key) |
1372 |
data['url'] = self.get_url() |
|
1368 | 1373 |
data['receipt_time'] = datetime.datetime(*self.receipt_time[:6]) |
1369 | 1374 |
data['last_update_time'] = datetime.datetime(*self.last_update_time[:6]) |
1370 |
data['criticality_level'] = self.criticality_level |
|
1371 |
data['url'] = self.get_url() |
|
1372 |
data['api_url'] = self.get_api_url() |
|
1373 |
data['backoffice_url'] = self.get_backoffice_url() |
|
1374 | 1375 | |
1375 |
try: |
|
1376 |
if prefetched_users is not None: |
|
1377 |
user = prefetched_users.get(str(self.user_id)) |
|
1378 |
else: |
|
1379 |
user = get_publisher().user_class.get(self.user_id) |
|
1380 |
except KeyError: |
|
1381 |
user = None |
|
1382 |
if not anonymise and user: |
|
1383 |
from .carddef import CardDef |
|
1376 |
if include_fields: |
|
1377 |
data['criticality_level'] = self.criticality_level |
|
1378 |
data['api_url'] = self.get_api_url() |
|
1379 |
data['backoffice_url'] = self.get_backoffice_url() |
|
1384 | 1380 | |
1385 |
data['user'] = user.get_json_export_dict(full=isinstance(self.formdef, CardDef)) |
|
1381 |
try: |
|
1382 |
if prefetched_users is not None: |
|
1383 |
user = prefetched_users.get(str(self.user_id)) |
|
1384 |
else: |
|
1385 |
user = get_publisher().user_class.get(self.user_id) |
|
1386 |
except KeyError: |
|
1387 |
user = None |
|
1388 |
if not anonymise and user: |
|
1389 |
from .carddef import CardDef |
|
1386 | 1390 | |
1387 |
data['fields'] = self.get_json_dict( |
|
1388 |
self.formdef.fields, |
|
1389 |
include_files=include_files, |
|
1390 |
anonymise=anonymise, |
|
1391 |
include_unnamed_fields=include_unnamed_fields, |
|
1392 |
) |
|
1391 |
data['user'] = user.get_json_export_dict(full=isinstance(self.formdef, CardDef)) |
|
1393 | 1392 | |
1394 |
data['workflow'] = {} |
|
1395 |
wf_status = self.get_visible_status(user) |
|
1396 |
if wf_status: |
|
1397 |
data['workflow']['status'] = {'id': wf_status.id, 'name': wf_status.name} |
|
1398 |
wf_real_status = self.get_status() |
|
1399 |
if wf_real_status: |
|
1400 |
data['workflow']['real_status'] = {'id': wf_real_status.id, 'name': wf_real_status.name} |
|
1401 |
# Workflow data have unknown purpose, do not store them in anonymised export |
|
1402 |
if self.workflow_data and not anonymise: |
|
1403 |
data['workflow']['data'] = self.workflow_data |
|
1404 |
if self.formdef.workflow.get_backoffice_fields(): |
|
1405 |
data['workflow']['fields'] = self.get_json_dict( |
|
1406 |
self.formdef.workflow.get_backoffice_fields(), |
|
1393 |
data['fields'] = self.get_json_dict( |
|
1394 |
self.formdef.fields, |
|
1407 | 1395 |
include_files=include_files, |
1408 | 1396 |
anonymise=anonymise, |
1409 | 1397 |
include_unnamed_fields=include_unnamed_fields, |
1410 | 1398 |
) |
1411 | 1399 | |
1400 |
if include_workflow: |
|
1401 |
data['workflow'] = {} |
|
1402 |
wf_status = self.get_visible_status(user) |
|
1403 |
if wf_status: |
|
1404 |
data['workflow']['status'] = {'id': wf_status.id, 'name': wf_status.name} |
|
1405 |
wf_real_status = self.get_status() |
|
1406 |
if wf_real_status: |
|
1407 |
data['workflow']['real_status'] = {'id': wf_real_status.id, 'name': wf_real_status.name} |
|
1408 |
# Workflow data have unknown purpose, do not store them in anonymised export |
|
1409 |
if self.workflow_data and not anonymise: |
|
1410 |
data['workflow']['data'] = self.workflow_data |
|
1411 |
if self.formdef.workflow.get_backoffice_fields(): |
|
1412 |
data['workflow']['fields'] = self.get_json_dict( |
|
1413 |
self.formdef.workflow.get_backoffice_fields(), |
|
1414 |
include_files=include_files, |
|
1415 |
anonymise=anonymise, |
|
1416 |
include_unnamed_fields=include_unnamed_fields, |
|
1417 |
) |
|
1418 | ||
1412 | 1419 |
if include_roles: |
1413 | 1420 |
# add a roles dictionary, with workflow functions and two special |
1414 | 1421 |
# entries for concerned/actions roles. |
... | ... | |
1438 | 1445 |
role_list = [x.get_json_export_dict() for x in role_list if x is not None] |
1439 | 1446 |
data['roles'][role_key] = role_list |
1440 | 1447 | |
1441 |
data['submission'] = { |
|
1442 |
'backoffice': self.backoffice_submission, |
|
1443 |
'channel': self.submission_channel or 'web', |
|
1444 |
} |
|
1445 |
try: |
|
1446 |
if prefetched_users is not None: |
|
1447 |
agent = prefetched_users.get(str(self.submission_agent_id)) |
|
1448 |
else: |
|
1449 |
agent = get_publisher().user_class.get(self.submission_agent_id) |
|
1450 |
except KeyError: |
|
1451 |
agent = None |
|
1452 |
if agent: |
|
1453 |
data['submission']['agent'] = agent.get_json_export_dict() |
|
1454 |
parent = self.get_parent() |
|
1455 |
if parent: |
|
1456 |
data['submission']['parent'] = { |
|
1457 |
'url': parent.get_url(), |
|
1458 |
'backoffice_url': parent.get_backoffice_url(), |
|
1459 |
'api_url': parent.get_api_url(), |
|
1448 |
if include_submission: |
|
1449 |
data['submission'] = { |
|
1450 |
'backoffice': self.backoffice_submission, |
|
1451 |
'channel': self.submission_channel or 'web', |
|
1460 | 1452 |
} |
1453 |
try: |
|
1454 |
if prefetched_users is not None: |
|
1455 |
agent = prefetched_users.get(str(self.submission_agent_id)) |
|
1456 |
else: |
|
1457 |
agent = get_publisher().user_class.get(self.submission_agent_id) |
|
1458 |
except KeyError: |
|
1459 |
agent = None |
|
1460 |
if agent: |
|
1461 |
data['submission']['agent'] = agent.get_json_export_dict() |
|
1462 |
parent = self.get_parent() |
|
1463 |
if parent: |
|
1464 |
data['submission']['parent'] = { |
|
1465 |
'url': parent.get_url(), |
|
1466 |
'backoffice_url': parent.get_backoffice_url(), |
|
1467 |
'api_url': parent.get_api_url(), |
|
1468 |
} |
|
1461 | 1469 | |
1462 | 1470 |
if self.evolution and include_evolution: |
1463 | 1471 |
evolution = data['evolution'] = [] |
... | ... | |
1470 | 1478 |
) |
1471 | 1479 |
) |
1472 | 1480 | |
1473 |
if self.geolocations: |
|
1481 |
if include_fields and self.geolocations:
|
|
1474 | 1482 |
data['geolocations'] = {} |
1475 | 1483 |
for k, v in self.geolocations.items(): |
1476 | 1484 |
data['geolocations'][k] = v.copy() |
1477 |
- |