def create(request):
user = osmutils.get_user(request)
client = Client()
- role_data ={
+ role_data = {
'name': request.POST['name'],
}
try:
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,
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') != '':
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,
else:
return __response_handler(request, {}, url=None, status=200)
+
@login_required
def get(request, role_id=None):
user = osmutils.get_user(request)
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)