diff options
| author | Frederick Muriuki Muriithi | 2026-02-10 11:21:55 -0600 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-02-10 11:27:38 -0600 |
| commit | 2fe5d90776edd1bc62a6eeaa492d3efb2974b158 (patch) | |
| tree | 7c4fc0ea5d7723167fdfa2948b60f4b0dad3dbf1 /gn_auth/auth/authorisation/data | |
| parent | 5d0c7b9f0a811e1b777285f4f7de59db8deeb14c (diff) | |
| download | gn-auth-2fe5d90776edd1bc62a6eeaa492d3efb2974b158.tar.gz | |
Use Auth function that checks for delete access.
Diffstat (limited to 'gn_auth/auth/authorisation/data')
| -rw-r--r-- | gn_auth/auth/authorisation/data/phenotypes.py | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/gn_auth/auth/authorisation/data/phenotypes.py b/gn_auth/auth/authorisation/data/phenotypes.py index 1f79e0e..788b9e7 100644 --- a/gn_auth/auth/authorisation/data/phenotypes.py +++ b/gn_auth/auth/authorisation/data/phenotypes.py @@ -12,8 +12,8 @@ from gn_auth.auth.authentication.oauth2.resource_server import require_oauth from gn_auth.auth.errors import AuthorisationError from gn_auth.auth.authorisation.checks import authorised_p +from gn_auth.auth.authorisation.resources.checks import can_delete from gn_auth.auth.authorisation.resources.system.models import system_resource -from gn_auth.auth.authorisation.resources.checks import authorised_for_spec from gn_auth.auth.authorisation.resources.groups.models import Group, group_resource @@ -251,12 +251,6 @@ def delete_linked_phenotypes_data( with (require_oauth.acquire("profile group resource") as _token, authdb.connection(db_uri) as auth_conn, authdb.cursor(auth_conn) as cursor): - # - Does user have DELETE privilege on system (i.e. is data curator)? - # YES: go ahead and delete data as below. - # - Does user have DELETE privilege on resource(s)? - # YES: Delete phenotypes by resource, checking privileges for each - # resource. - # - Neither: Raise `AuthorisationError` and bail! _deleted = 0 xref_ids = tuple(request.json.get("xref_ids", []))#type: ignore[union-attr] if len(xref_ids) > 0: @@ -264,19 +258,12 @@ def delete_linked_phenotypes_data( data_link_ids = fetch_data_link_ids( cursor, species_id, population_id, dataset_id, xref_ids) resource_id = fetch_resource_id(cursor, data_link_ids) - if not (authorised_for_spec( - auth_conn, - _token.user.user_id, - resource_id, - "(OR group:resource:delete-resource system:resource:delete)") - or - authorised_for_spec( - auth_conn, - _token.user.user_id, - system_resource(auth_conn).resource_id, - "(AND system:system-wide:data:delete)")): + # - Does user have DELETE privilege on the data + if not can_delete(auth_conn, _token.user.user_id, resource_id): + # - No: Raise `AuthorisationError` and bail! raise AuthorisationError( "You are not allowed to delete this resource's data.") + # - YES: go ahead and delete data as below. _resources_ids = unlink_from_resources(cursor, data_link_ids) delete_resources(cursor, _resources_ids) _deleted = delete_linked_data(cursor, data_link_ids) |
