From 706d61901cf86b263b2da2fdcd8f0b9ffa15db23 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 12 Sep 2015 00:55:51 +0200 Subject: [PATCH] api: export Role.emails and .emails_to_members (#8254) To allow import-wcs-roles on authentic side to import them. --- tests/test_api.py | 8 ++++++++ wcs/api.py | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index f16b6ca..a34ff81 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -421,6 +421,8 @@ def test_api_list_formdata(local_user): def test_roles(local_user): Role.wipe() role = Role(name='Hello World') + role.emails = ['toto@example.com', 'zozo@example.com'] + role.details = 'kouign amann' role.store() resp = get_app(pub).get('/api/roles', status=403) @@ -428,8 +430,14 @@ def test_roles(local_user): resp = get_app(pub).get(sign_uri('/api/roles')) assert resp.json['data'][0]['text'] == 'Hello World' assert resp.json['data'][0]['slug'] == 'hello-world' + assert resp.json['data'][0]['emails'] == ['toto@example.com', 'zozo@example.com'] + assert resp.json['data'][0]['emails_to_members'] == False + assert resp.json['data'][0]['details'] == 'kouign amann' # also check old endpoint, for compatibility resp = get_app(pub).get(sign_uri('/roles'), headers={'Accept': 'application/json'}) assert resp.json['data'][0]['text'] == 'Hello World' assert resp.json['data'][0]['slug'] == 'hello-world' + assert resp.json['data'][0]['emails'] == ['toto@example.com', 'zozo@example.com'] + assert resp.json['data'][0]['emails_to_members'] == False + assert resp.json['data'][0]['details'] == 'kouign amann' diff --git a/wcs/api.py b/wcs/api.py index 1a9089a..64a66a9 100644 --- a/wcs/api.py +++ b/wcs/api.py @@ -186,7 +186,10 @@ class ApiDirectory(Directory): for role in Role.select(): list_roles.append({'text': unicode(role.name, charset), 'allows_backoffice_access': role.allows_backoffice_access, - 'slug': role.slug, + 'emails': [unicode(email, charset) for email in role.emails or []], + 'details': unicode(role.details, charset), + 'emails_to_members': role.emails_to_members, + 'slug': unicode(role.slug, charset), 'id': role.id}) get_response().set_content_type('application/json') return json.dumps({'data': list_roles}) -- 2.1.4