diff options
| author | Frederick Muriuki Muriithi <frederick@fallion.localhost> | 2026-08-28 15:15:32 +0000 |
|---|---|---|
| committer | Frederick Muriuki Muriithi <fredmanglis@gmail.com> | 2026-08-28 10:17:31 -0500 |
| commit | aa06a02876cc55306ca037e4653c6c100bb0bbea (patch) | |
| tree | d3bf097c8b55abee4eca5372721cbc1f81ea47b5 | |
| parent | d103f87d3cb152ceca4afc90967f289662043a7d (diff) | |
| download | genenetwork3-aa06a02876cc55306ca037e4653c6c100bb0bbea.tar.gz | |
fix(case-attr): add can_edit privilege check to edit endpoints
Both the flat and v1 edit endpoints had @require_token but no privilege check, so any valid token could queue an edit. - edit_case_attributes (flat): fetch species_id from DB, call __population_privileges__, raise AuthorisationError if not can_edit. - v1_edit_case_attributes: same pattern; species_id comes from the URL. Case-attribute names remain publicly accessible (no token required). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
| -rw-r--r-- | gn3/api/case_attributes.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gn3/api/case_attributes.py b/gn3/api/case_attributes.py index 640e17b..038beb7 100644 --- a/gn3/api/case_attributes.py +++ b/gn3/api/case_attributes.py @@ -195,6 +195,17 @@ def edit_case_attributes(inbredset_id: int, auth_token=None) -> tuple[Response, :inbredset_id: Identifier for the population that the case attribute belongs :auth_token: A validated JWT from the auth server """ + with database_connection(current_app.config["SQL_URI"]) as conn: + with conn.cursor() as cursor: + cursor.execute( + "SELECT SpeciesId FROM InbredSet WHERE InbredSetId=%s", + (inbredset_id,)) + species_id = cursor.fetchone()[0] + resource_privs, system_privs = __population_privileges__( + auth_token, species_id, inbredset_id) + if not resources.can_edit(resource_privs, system_privs): + raise AuthorisationError( + "You don't have the right privileges to edit this resource.") with database_connection(current_app.config["SQL_URI"]) as conn, conn.cursor() as cursor: data = request.json["edit-data"] # type: ignore edit = CaseAttributeEdit( @@ -385,6 +396,11 @@ def v1_case_attribute_details(species_id: int, pop_id: int, ca_id: int) -> Respo def v1_edit_case_attributes( species_id: int, pop_id: int, auth_token=None) -> tuple[Response, int]: """Queue an edit to the case attributes for the given population.""" + resource_privs, system_privs = __population_privileges__( + auth_token, species_id, pop_id) + if not resources.can_edit(resource_privs, system_privs): + raise AuthorisationError( + "You don't have the right privileges to edit this resource.") with database_connection(current_app.config["SQL_URI"]) as conn, conn.cursor() as cursor: data = request.json["edit-data"] # type: ignore edit = CaseAttributeEdit( |
