aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBonfaceKilz2022-05-24 11:46:31 +0300
committerBonfaceKilz2022-05-27 15:17:52 +0300
commitab5d06c96dda489d5d1e28f4a68d6c2aed26476b (patch)
tree60181bde42690d3d2578bf8e4d1a80cad84acc34
parent592910c4d98e279ea3167f97300573a02fdc6914 (diff)
downloadgenenetwork2-ab5d06c96dda489d5d1e28f4a68d6c2aed26476b.tar.gz
Add new endpoint for "approving" case-attributes modifications
* wqflask/wqflask/metadata_edits.py (approve_case_attribute_data): New end-point.
-rw-r--r--wqflask/wqflask/metadata_edits.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index 101e6949..1a4d6f8d 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -806,3 +806,70 @@ def reject_case_attribute_data():
conn.commit()
return redirect(url_for("metadata_edit.show_case_attribute_columns"))
+
+
+@metadata_edit.route("/case-attributes/approve", methods=["POST", ])
+@case_attributes_edit_access
+def approve_case_attribute_data():
+ case_attr_id = request.form.to_dict().get("id")
+ with database_connection() as conn:
+ with conn.cursor() as cursor:
+ cursor.execute(
+ "SELECT json_diff_data FROM caseattributes_audit "
+ "WHERE id = %s", (case_attr_id,)
+ )
+ diff_data = cursor.fetchone()
+ if diff_data:
+ diff_data = json.loads(diff_data[0])
+ try:
+ # Insert (Most Important)
+ if diff_data.get("Insert"):
+ data = diff_data.get("Insert")
+ cursor.execute(
+ "INSERT INTO CaseAttribute "
+ "(Name, Description) VALUES "
+ "(%s, %s)",
+ (data.get("name"), data.get("description"),))
+ cursor.execute(
+ "UPDATE caseattributes_audit SET "
+ "status = 'approved' WHERE id = %s",
+ (case_attr_id,))
+ # Delete
+ elif diff_data.get("Deletion"):
+ data = diff_data.get("Deletion")
+ cursor.execute(
+ "DELETE FROM CaseAttribute "
+ "WHERE Id = %s",
+ (data.get("id"),))
+ cursor.execute(
+ "UPDATE caseattributes_audit SET "
+ "status = 'approved' WHERE id = %s",
+ (case_attr_id,))
+ # Modification
+ elif diff_data.get("Modification"):
+ data = diff_data.get("Modification")
+ if (desc_ := data.get("description")):
+ cursor.execute(
+ "UPDATE CaseAttribute SET "
+ "Description = %s WHERE Id = %s",
+ (desc_.get("Current"), diff_data.get("id"),)
+ )
+ if (name_ := data.get("name")):
+ cursor.execute(
+ "UPDATE CaseAttribute SET "
+ "Name = %s WHERE Id = %s",
+ (name_.get("Current"), diff_data.get("id"),)
+ )
+ if cursor.rowcount:
+ cursor.execute(
+ "UPDATE caseattributes_audit SET "
+ "status = 'approved' WHERE id = %s",
+ (case_attr_id,))
+ except Exception as _e:
+ import MySQLdb
+ conn.rollback()
+ raise MySQLdb.Error(_e) from _e
+ conn.commit()
+ return redirect(url_for("metadata_edit.show_case_attribute_columns"))
+
+