From: lombardofr Date: Sun, 24 Nov 2019 20:45:41 +0000 (+0100) Subject: fix bug 895 X-Git-Tag: v7.0.0rc1~5 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=158d873b8cf0756452695874935eb660996a148f;p=osm%2FLW-UI.git fix bug 895 Change-Id: Ib1054143428867d2281830c37bd0ded846a6626a Signed-off-by: lombardofr --- diff --git a/rolehandler/views.py b/rolehandler/views.py index 2537175..dba444d 100644 --- a/rolehandler/views.py +++ b/rolehandler/views.py @@ -42,7 +42,7 @@ def role_list(request): def create(request): user = osmutils.get_user(request) client = Client() - role_data ={ + role_data = { 'name': request.POST['name'], } try: @@ -50,13 +50,13 @@ def create(request): role_permissions = yaml.load(request.POST.get('permissions')) if not isinstance(role_permissions, dict): - raise ValueError('Role permissions should be provided in a key-value fashion') + raise ValueError('Role permissions should be provided in a key-value fashion') for key, value in role_permissions.items(): if not isinstance(value, bool): raise ValueError("Value of '{}' in a role permissionss should be boolean".format(key)) role_data[key] = value except Exception as e: - return __response_handler(request, {'status': 400, 'code': 'BAD_REQUEST', 'detail': e.message} , url=None, status=400) + return __response_handler(request, {'status': 400, 'code': 'BAD_REQUEST', 'detail': e.message}, url=None, status=400) result = client.role_create(user.get_token(), role_data) if result['error']: return __response_handler(request, result['data'], url=None, @@ -80,12 +80,14 @@ def delete(request, role_id=None): else: return __response_handler(request, {}, url=None, status=200) + @login_required def update(request, role_id=None): user = osmutils.get_user(request) client = Client() payload = { 'name': request.POST['name'], + 'permissions': {} } try: if 'permissions' in request.POST and request.POST.get('permissions') != '': @@ -96,9 +98,9 @@ def update(request, role_id=None): for key, value in role_permissions.items(): if not isinstance(value, bool): raise ValueError('Value in a role permissions should be boolean') - payload[key] = value + payload['permissions'][key] = value except Exception as e: - return __response_handler(request, {'status': 400, 'code': 'BAD_REQUEST', 'detail': e.message} , url=None, status=400) + return __response_handler(request, {'status': 400, 'code': 'BAD_REQUEST', 'detail': e.message}, url=None, status=400) result = client.role_update(user.get_token(), role_id, payload) if result['error']: return __response_handler(request, result['data'], url=None, @@ -106,6 +108,7 @@ def update(request, role_id=None): else: return __response_handler(request, {}, url=None, status=200) + @login_required def get(request, role_id=None): user = osmutils.get_user(request) @@ -123,7 +126,7 @@ def get(request, role_id=None): result = { '_id': role['_id'], 'name': role['name'], - 'permissions': { key:value for key, value in role['permissions'].items() if key not in ['_id', 'name', 'root', '_admin'] } + 'permissions': {key: value for key, value in role['permissions'].items() if key not in ['_id', 'name', 'root', '_admin'] } } return __response_handler(request, result, url=None, status=200)