diff --git a/src/caosdb/common/administration.py b/src/caosdb/common/administration.py index 157518f82294257d7267b881e96d225ecce4304f..1f39bead8d8f0933119d87a240e39e2a65a71fb0 100644 --- a/src/caosdb/common/administration.py +++ b/src/caosdb/common/administration.py @@ -28,8 +28,9 @@ from lxml import etree from caosdb.common.utils import xml2str from caosdb.connection.connection import get_connection -from caosdb.exceptions import (AuthorizationException, ClientErrorException, - EntityDoesNotExistError) +from caosdb.exceptions import (ClientErrorException, + HTTPAuthorizationException, + ResourceNotFoundException) def set_server_property(key, value): @@ -104,10 +105,10 @@ def _retrieve_user(name, realm=None, **kwargs): con = get_connection() try: return con._http_request(method="GET", path="User/" + (realm + "/" + name if realm is not None else name), **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to retrieve this user." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "User does not exist." raise @@ -116,10 +117,10 @@ def _delete_user(name, **kwargs): con = get_connection() try: return con._http_request(method="DELETE", path="User/" + name, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to delete this user." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "User does not exist." raise @@ -142,10 +143,10 @@ def _update_user(name, realm=None, password=None, status=None, params["entity"] = str(entity) try: return con.put_form_data(entity_uri_segment="User/" + (realm + "/" + name if realm is not None else name), params=params, **kwargs).read() - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "User does not exist." raise - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to update this user." raise except ClientErrorException as e: @@ -171,7 +172,7 @@ def _insert_user(name, password=None, status=None, email=None, entity=None, **kw params["entity"] = entity try: return con.post_form_data(entity_uri_segment="User", params=params, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to insert a new user." raise e except ClientErrorException as e: @@ -187,7 +188,7 @@ def _insert_role(name, description, **kwargs): con = get_connection() try: return con.post_form_data(entity_uri_segment="Role", params={"role_name": name, "role_description": description}, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to insert a new role." raise except ClientErrorException as e: @@ -200,10 +201,10 @@ def _update_role(name, description, **kwargs): con = get_connection() try: return con.put_form_data(entity_uri_segment="Role/" + name, params={"role_description": description}, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to update this role." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "Role does not exist." raise @@ -212,10 +213,10 @@ def _retrieve_role(name, **kwargs): con = get_connection() try: return con._http_request(method="GET", path="Role/" + name, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to retrieve this role." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "Role does not exist." raise @@ -224,10 +225,10 @@ def _delete_role(name, **kwargs): con = get_connection() try: return con._http_request(method="DELETE", path="Role/" + name, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to delete this role." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "Role does not exist." raise @@ -241,11 +242,12 @@ def _set_roles(username, roles, realm=None, **kwargs): body = xml2str(xml) con = get_connection() try: - body = con._http_request(method="PUT", path="UserRoles/" + (realm + "/" + username if realm is not None else username), body=body, **kwargs).read() - except AuthorizationException as e: + body = con._http_request(method="PUT", path="UserRoles/" + (realm + "/" + + username if realm is not None else username), body=body, **kwargs).read() + except HTTPAuthorizationException as e: e.msg = "You are not permitted to set this user's roles." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "User does not exist." raise except ClientErrorException as e: @@ -264,11 +266,12 @@ def _set_roles(username, roles, realm=None, **kwargs): def _get_roles(username, realm=None, **kwargs): con = get_connection() try: - body = con._http_request(method="GET", path="UserRoles/" + (realm + "/" + username if realm is not None else username), **kwargs).read() - except AuthorizationException as e: + body = con._http_request(method="GET", path="UserRoles/" + ( + realm + "/" + username if realm is not None else username), **kwargs).read() + except HTTPAuthorizationException as e: e.msg = "You are not permitted to retrieve this user's roles." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "User does not exist." raise ret = set() @@ -308,10 +311,10 @@ Returns con = get_connection() try: return con._http_request(method="PUT", path="PermissionRules/" + role, body=body, **kwargs).read() - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to set this role's permissions." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "Role does not exist." raise @@ -320,10 +323,10 @@ def _get_permissions(role, **kwargs): con = get_connection() try: return PermissionRule._parse_body(con._http_request(method="GET", path="PermissionRules/" + role, **kwargs).read()) - except AuthorizationException as e: + except HTTPAuthorizationException as e: e.msg = "You are not permitted to retrieve this role's permissions." raise - except EntityDoesNotExistError as e: + except ResourceNotFoundException as e: e.msg = "Role does not exist." raise