From 7c2fe1c7500ef616fb2f72777b63b8f26ae419bb Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 17 May 2023 12:14:57 +0300 Subject: auth: Integrate deleting selected collections with auth Enable the deletion of selected collections via the GN3 api. --- wqflask/wqflask/collect.py | 39 +++++++++++++++++++++------------------ 1 file 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')) -- cgit v1.2.3