Skip to content

Commit

Permalink
Merge pull request #807 from LukeTapekhin/heavy_refactor
Browse files Browse the repository at this point in the history
delete roles fixes
  • Loading branch information
LukeTapekhin authored Sep 5, 2017
2 parents 07213dc + e67eea1 commit 97d67e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
20 changes: 10 additions & 10 deletions lingvodoc/views/v2/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,6 @@ def edit_dictionary_roles(request): # tested & in docs
client_id = request.matchdict.get('client_id')
object_id = request.matchdict.get('object_id')




url = request.route_url('dictionary_roles',
client_id=client_id,
object_id=object_id)
Expand All @@ -608,7 +605,6 @@ def edit_dictionary_roles(request): # tested & in docs
subreq.headers = headers
previous = request.invoke_subrequest(subreq).json_body


if type(request.json_body) == str:
req = json.loads(request.json_body)
else:
Expand Down Expand Up @@ -649,7 +645,10 @@ def edit_dictionary_roles(request): # tested & in docs
subreq.method = 'PATCH'
headers = {'Cookie': request.headers['Cookie']}
subreq.headers = headers
request.invoke_subrequest(subreq)
response = request.invoke_subrequest(subreq)
# if response.status_code != 200:
# request.response = response
# return response.json_body
roles_users = None
if 'roles_users' in req:
roles_users = req['roles_users']
Expand Down Expand Up @@ -757,7 +756,6 @@ def delete_dictionary_roles(request): # & in docs
req = json.loads(request.json_body)
else:
req = request.json_body
print(req)

roles_users = None
if 'roles_users' in req:
Expand Down Expand Up @@ -808,8 +806,9 @@ def delete_dictionary_roles(request): # & in docs
if user in group.users:
group.users.remove(user)
else:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}
if roles_users[role_name]:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}

if roles_organizations:
for role_name in roles_organizations:
Expand Down Expand Up @@ -848,8 +847,9 @@ def delete_dictionary_roles(request): # & in docs
if org in group.organizations:
group.organizations.remove(org)
else:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}
if roles_organizations[role_name]:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}

request.response.status = HTTPOk.code
return response
Expand Down
15 changes: 6 additions & 9 deletions lingvodoc/views/v2/perspective/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,6 @@ def edit_perspective_roles(request):
parent_client_id = request.matchdict.get('client_id')
parent_object_id = request.matchdict.get('object_id')



url = request.route_url('perspective_roles',
client_id=parent_client_id,
object_id=parent_object_id,
Expand All @@ -1028,13 +1026,11 @@ def edit_perspective_roles(request):
subreq.headers = headers
previous = request.invoke_subrequest(subreq).json_body


if type(request.json_body) == str:
req = json.loads(request.json_body)
else:
req = request.json_body


for role_name in req['roles_users']:
remove_list = list()
for user in req['roles_users'][role_name]:
Expand All @@ -1053,7 +1049,6 @@ def edit_perspective_roles(request):
for user in remove_list:
req['roles_users'][role_name].remove(user)


delete_flag = False

for role_name in previous['roles_users']:
Expand Down Expand Up @@ -1240,8 +1235,9 @@ def delete_perspective_roles(request): # TODO: test
if user in group.users:
group.users.remove(user)
else:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}
if roles_users[role_name]:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}

if roles_organizations:
for role_name in roles_organizations:
Expand Down Expand Up @@ -1279,8 +1275,9 @@ def delete_perspective_roles(request): # TODO: test
if org in group.organizations:
group.organizations.remove(org)
else:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}
if roles_organizations[role_name]:
request.response.status = HTTPForbidden.code
return {'error': str("Not enough permission")}

request.response.status = HTTPOk.code
return response
Expand Down

0 comments on commit 97d67e9

Please sign in to comment.