about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi <frederick@fallion.localhost>2026-08-28 15:39:49 +0000
committerFrederick Muriuki Muriithi <fredmanglis@gmail.com>2026-08-28 10:42:19 -0500
commit23a02f751865ab706a6fefae668dfa67c4ad27d2 (patch)
tree144b56b05bb211d7efc52960a9b72bddffe95dcb
parentaa06a02876cc55306ca037e4653c6c100bb0bbea (diff)
downloadgenenetwork3-23a02f751865ab706a6fefae668dfa67c4ad27d2.tar.gz
fix(case-attr): replace required_access with can_apply_or_reject_edit
approve_case_attributes_diff and reject_case_attributes_diff were using the
old required_access helper which checked a single wrong privilege name
(system:inbredset:edit-case-attribute). Replace with __population_privileges__
+ resources.can_apply_or_reject_edit, consistent with the v1 endpoints.

Flat endpoints derive species_id from the DB since it is not in the URL.

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.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/gn3/api/case_attributes.py b/gn3/api/case_attributes.py
index 038beb7..3d836fc 100644
--- a/gn3/api/case_attributes.py
+++ b/gn3/api/case_attributes.py
@@ -250,9 +250,17 @@ def approve_case_attributes_diff(
 ) -> tuple[Response, int]:
     """Approve the changes to the case attributes in the diff."""
     try:
-        required_access(auth_token,
-                        inbredset_id,
-                        ("system:inbredset:edit-case-attribute",))
+        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_apply_or_reject_edit(resource_privs, system_privs):
+            raise AuthorisationError(
+                "You don't have the right privileges to approve this edit.")
         with (database_connection(current_app.config["SQL_URI"]) as conn,
               conn.cursor() as cursor):
             directory = (Path(current_app.config["LMDB_DATA_PATH"]) /
@@ -273,7 +281,7 @@ def approve_case_attributes_diff(
     except AuthorisationError as __auth_err:
         return jsonify({
             "diff-status": "queued",
-            "message": ("You don't have the right privileges to edit this resource.")
+            "message": "You don't have the right privileges to edit this resource."
         }), 401
 
 
@@ -284,10 +292,17 @@ def reject_case_attributes_diff(
 ) -> tuple[Response, int]:
     """Reject the changes to the case attributes in the diff."""
     try:
-        required_access(auth_token,
-                        inbredset_id,
-                        ("system:inbredset:edit-case-attribute",
-                         "system:inbredset:apply-case-attribute-edit"))
+        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_apply_or_reject_edit(resource_privs, system_privs):
+            raise AuthorisationError(
+                "You don't have the right privileges to reject this edit.")
         with database_connection(current_app.config["SQL_URI"]) as conn, \
                 conn.cursor() as cursor:
             directory = (Path(current_app.config["LMDB_DATA_PATH"]) /