about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-05-17 12:14:57 +0300
committerFrederick Muriuki Muriithi2023-05-17 12:14:57 +0300
commit7c2fe1c7500ef616fb2f72777b63b8f26ae419bb (patch)
tree022047aa6e6008c45e5f7ea3f71a9549c2b0f872
parent0fb42e6f935c3a31196e5b529c1fcd355451188c (diff)
downloadgenenetwork2-7c2fe1c7500ef616fb2f72777b63b8f26ae419bb.tar.gz
auth: Integrate deleting selected collections with auth
Enable the deletion of selected collections via the GN3 api.
-rw-r--r--wqflask/wqflask/collect.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index ad0820c2..29bdb1fc 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -226,25 +226,28 @@ def remove_traits():
 
 @app.route("/collections/delete", methods=('POST',))
 def delete_collection():
-    params = request.form
-    uc_id = ""
-
-    uc_id = params['uc_id']
-    if len(uc_id.split(":")) > 1:
-        for this_uc_id in uc_id.split(":"):
-            collection_name = g.user_session.delete_collection(this_uc_id)
-    else:
-        collection_name = g.user_session.delete_collection(uc_id)
-
-    if uc_id != "":
-        if len(uc_id.split(":")) > 1:
-            flash("We've deleted the selected collections.", "alert-info")
-        else:
-            flash("We've deleted the selected collection.", "alert-info")
-    else:
-        flash("We've deleted the collection: {}.".format(
-            collection_name), "alert-info")
+    def __error__(err):
+        error = process_error(err)
+        flash(f"{error['error']}: {error['error_description']}",
+              "alert-danger")
+        return redirect(url_for('list_collections'))
+
+    def __success__(msg):
+        flash(msg["message"], "alert-success")
+        return redirect(url_for('list_collections'))
+
+    uc_ids = [item for item in request.form.get("uc_id", "").split(":")
+              if bool(item)]
+    if len(uc_ids) > 0:
+        return (oauth2_post if user_logged_in() else no_token_post)(
+            "oauth2/user/collections/delete",
+            json = {
+                "anon_id": str(session_info()["anon_id"]),
+                "collection_ids": uc_ids
+            }).either(
+                __error__, __success__)
 
+    flash("Nothing to delete.", "alert-info")
     return redirect(url_for('list_collections'))