From 7a63d1da114a51b35f6db46bef4f2b856285264f Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 23 Oct 2023 08:24:06 +0300 Subject: case-attribute: View case attribute diff --- gn3/case_attributes.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'gn3/case_attributes.py') 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("//diff//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 -- cgit v1.2.3