From 1a5f40b2621781799c2e07e58903948d72bf98cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= fields
.
+Concernant les rôles et fonctions de workflow, les différents intervenants sont
+listés dans l'attribut roles
, en différentes séries qui vont
+dépendre de fonctions attachées au workflow. Deux séries sont particulières,
+la série concerned
reprend les rôles concernés par la demande et
+la série actions
reprend les rôles disposant d'une capacité
+d'action sur la demande.
+
Il est bien sûr nécessaire de disposer des autorisations nécessaires pour diff --git a/tests/test_api.py b/tests/test_api.py index b69048d..3d681e4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -17,6 +17,7 @@ from wcs.roles import Role from wcs.formdef import FormDef from wcs.categories import Category from wcs.data_sources import NamedDataSource +from wcs.workflows import Workflow from wcs import fields from wcs.api import sign_url @@ -410,6 +411,8 @@ def test_formdata(pub, local_user): Role.wipe() role = Role(name='test') role.store() + another_role = Role(name='another') + another_role.store() FormDef.wipe() formdef = FormDef() formdef.name = 'test' @@ -421,7 +424,13 @@ def test_formdata(pub, local_user): fields.ItemField(id='4', label='foobar5', varname='item', data_source={'type': 'foobar'}), ] - formdef.workflow_roles = {'_receiver': role.id} + workflow = Workflow.get_default_workflow() + workflow.roles['_foobar'] = 'Foobar' + workflow.id = '2' + workflow.store() + formdef.workflow_id = workflow.id + formdef.workflow_roles = {'_receiver': role.id, + '_foobar': another_role.id} formdef.store() item_field = formdef.fields[4] @@ -442,6 +451,8 @@ def test_formdata(pub, local_user): formdata.data, item_field.id) formdata.user_id = local_user.id formdata.just_created() + formdata.status = 'wf-new' + formdata.evolution[-1].status = 'wf-new' formdata.store() resp = get_app(pub).get( @@ -469,6 +480,12 @@ def test_formdata(pub, local_user): assert resp.json['fields']['item'] == 'foo' assert resp.json['fields']['item_raw'] == '1' assert resp.json['fields']['item_structured'] == {'id': '1', 'text': 'foo', 'more': 'XXX'} + assert resp.json['workflow']['status']['name'] == 'New' + + assert [x.get('id') for x in resp.json['roles']['_receiver']] == [str(role.id)] + assert [x.get('id') for x in resp.json['roles']['_foobar']] == [str(another_role.id)] + assert [x.get('id') for x in resp.json['roles']['concerned']] == [str(role.id), str(another_role.id)] + assert [x.get('id') for x in resp.json['roles']['actions']] == [str(role.id)] def test_user_forms(pub, local_user): FormDef.wipe() @@ -478,6 +495,7 @@ def test_user_forms(pub, local_user): fields.StringField(id='0', label='foobar', varname='foobar'), fields.StringField(id='1', label='foobar2'),] formdef.store() + formdef.data_class().wipe() resp = get_app(pub).get(sign_uri('/api/user/forms', user=local_user)) assert len(resp.json) == 0 diff --git a/wcs/formdata.py b/wcs/formdata.py index b10ae03..26892bc 100644 --- a/wcs/formdata.py +++ b/wcs/formdata.py @@ -601,6 +601,28 @@ class FormData(StorableObject): if self.workflow_data: data['workflow']['data'] = self.workflow_data + # add a roles dictionary, with workflow functions and two special + # entries for concerned/actions roles. + data['roles'] = {} + workflow_roles = {} + if self.formdef.workflow_roles: + workflow_roles.update(self.formdef.workflow_roles) + if self.workflow_roles: + workflow_roles.update(self.workflow_roles) + for workflow_role in workflow_roles: + data['roles'][workflow_role] = workflow_roles.get(workflow_role) + data['roles']['concerned'] = self.get_concerned_roles() + data['roles']['actions'] = self.get_actions_roles() + + for role_key in data['roles']: + # exclude special _submitter value + role_list = [x for x in data['roles'][role_key] if x != '_submitter'] + # get role objects + role_list = [Role.get(x, ignore_errors=True) for x in role_list] + # export as json dicts + role_list = [x.get_json_export_dict() for x in role_list if x is not None] + data['roles'][role_key] = role_list + return data def export_to_json(self, include_files=True): -- 2.6.2