aboutsummaryrefslogtreecommitdiff
path: root/gn3/case_attributes.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-10-23 08:24:06 +0300
committerFrederick Muriuki Muriithi2023-10-23 08:24:06 +0300
commit7a63d1da114a51b35f6db46bef4f2b856285264f (patch)
treed8b27daceaec81e726ad251f5438dfb6e4e0759b /gn3/case_attributes.py
parentea0b092395033c68f7c4edcc6805342e89034ce7 (diff)
downloadgenenetwork3-7a63d1da114a51b35f6db46bef4f2b856285264f.tar.gz
case-attribute: View case attribute diff
Diffstat (limited to 'gn3/case_attributes.py')
-rw-r--r--gn3/case_attributes.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/gn3/case_attributes.py b/gn3/case_attributes.py
index 2115fc9..661a399 100644
--- a/gn3/case_attributes.py
+++ b/gn3/case_attributes.py
@@ -470,3 +470,41 @@ def reject_case_attributes_diff(filename: str) -> Response:
"message": f"Rejected diff successfully",
"diff_filename": diff_filename.name
})
+
+@caseattr.route("/<int:inbredset_id>/diff/<int:diff_id>/view", methods=["GET"])
+def view_diff(inbredset_id: int, diff_id: int) -> Response:
+ """View a diff."""
+ with (require_oauth.acquire("profile resource") as the_token,
+ database_connection(current_app.config["SQL_URI"]) as conn,
+ conn.cursor(cursorclass=DictCursor) as cursor):
+ required_access(inbredset_id, ("system:inbredset:view-case-attribute",))
+ cursor.execute(
+ "SELECT * FROM caseattributes_audit WHERE id=%s",
+ (diff_id,))
+ diff = cursor.fetchone()
+ if diff:
+ json_diff_data = __parse_diff_json__(diff["json_diff_data"])
+ if json_diff_data["inbredset_id"] != inbredset_id:
+ return jsonify({
+ "error": "Not Found",
+ "error_description": (
+ "Could not find diff with the given ID for the "
+ "InbredSet chosen.")
+ })
+ return jsonify({
+ **diff,
+ "json_diff_data": {
+ **json_diff_data,
+ "db_id": diff["id"],
+ "created": diff["time_stamp"],
+ "user_id": uuid.UUID(diff["editor"])
+ }
+ })
+ return jsonify({
+ "error": "Not Found",
+ "error_description": "Could not find diff with the given ID."
+ })
+ return jsonify({
+ "error": "Code Error",
+ "error_description": "The code should never run this."
+ }), 500