aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-05-17 10:51:15 +0300
committerFrederick Muriuki Muriithi2023-05-17 10:51:15 +0300
commitb1041332ef0437031839d4e6ad64f4c7b797d6f8 (patch)
treed78d4113ee02e27e8dd9e9b6bf6050cc182f2944 /wqflask
parent8b99c746771692af9fa01037b5b03475bf77ba97 (diff)
downloadgenenetwork2-b1041332ef0437031839d4e6ad64f4c7b797d6f8.tar.gz
auth: Import/Delete Anonymous Collections
Integrate import/delete of anonymous collection when user is authenticated.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/collect.py23
-rw-r--r--wqflask/wqflask/oauth2/toplevel.py2
-rw-r--r--wqflask/wqflask/templates/collections/list.html3
-rwxr-xr-xwqflask/wqflask/templates/index_page.html37
-rw-r--r--wqflask/wqflask/views.py21
5 files changed, 75 insertions, 11 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index b64270e0..ad0820c2 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -27,7 +27,8 @@ from wqflask.oauth2 import session
from wqflask.oauth2.session import session_info
from wqflask.oauth2.checks import user_logged_in
from wqflask.oauth2.request_utils import process_error
-from wqflask.oauth2.client import oauth2_get, no_token_get, no_token_post
+from wqflask.oauth2.client import (
+ oauth2_get, oauth2_post, no_token_get, no_token_post)
Redis = get_redis_conn()
@@ -188,6 +189,26 @@ def list_collections():
**user_collections,
**anon_collections)
+@app.route("/collections/handle_anonymous", methods=["POST"])
+def handle_anonymous_collections():
+ """Handle any anonymous collection on logging in."""
+ choice = request.form.get("anon_choice")
+ if choice not in ("import", "delete"):
+ flash("Invalid choice!", "alert-danger")
+ return redirect("/")
+ def __impdel_error__(err):
+ error = process_error(err)
+ flash(f"{error['error']}: {error['error_description']}",
+ "alert-danger")
+ return redirect("/")
+ def __impdel_success__(msg):
+ flash(f"Success: {msg['message']}", "alert-success")
+ return redirect("/")
+ return oauth2_post(
+ f"oauth2/user/collections/anonymous/{choice}",
+ json={
+ "anon_id": str(session_info()["anon_id"])
+ }).either(__impdel_error__, __impdel_success__)
@app.route("/collections/remove", methods=('POST',))
def remove_traits():
diff --git a/wqflask/wqflask/oauth2/toplevel.py b/wqflask/wqflask/oauth2/toplevel.py
index ef9ce3db..04a08870 100644
--- a/wqflask/wqflask/oauth2/toplevel.py
+++ b/wqflask/wqflask/oauth2/toplevel.py
@@ -35,7 +35,7 @@ def authorisation_code():
"token": session.user_token(),
"logged_in": True
})
- return redirect(url_for("oauth2.user.user_profile"))
+ return redirect("/")
code = request.args.get("code", "")
if bool(code):
diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html
index 7e5c5330..437b0cc3 100644
--- a/wqflask/wqflask/templates/collections/list.html
+++ b/wqflask/wqflask/templates/collections/list.html
@@ -65,7 +65,8 @@
</table>
{%endif%}
{% if collections|length > 0 %}
- <table class="table-hover table-striped cell-border" id='trait_table' style="float: left;">
+ <table class="table-hover table-striped cell-border" id='trait_table' style="float: left;">
+ <caption>User Collections</caption>
<thead>
<tr>
<th></th>
diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html
index aad5d109..12503326 100755
--- a/wqflask/wqflask/templates/index_page.html
+++ b/wqflask/wqflask/templates/index_page.html
@@ -54,7 +54,42 @@
<!-- Start of body -->
<div class="container-fluid" style="min-width: 1210px;">
- {{ flash_me() }}
+ {{ flash_me() }}
+
+ {%if anon_collections | length > 0%}
+ <div class="panel panel-warning">
+ <div class="panel-heading">
+ <h3 class="panel-title">Import Anonymous Collections</h3>
+ </div>
+ <div class="panel-body">
+ <p>
+ There {%if anon_collections | length > 1%}are{%else%}is{%endif%}
+ {{anon_collections | length}} anonymous
+ collection{%if anon_collections | length > 1%}s{%endif%}
+ associated with your current session. What do you wish to do?
+ </p>
+ <p class="text-danger" style="font-weight: bold;">
+ <small>
+ If you choose to ignore this, the anonymous collections will be
+ eventually deleted and lost.
+ </small>
+ </p>
+ <form action="{{url_for('handle_anonymous_collections')}}"
+ method="POST">
+ <div class="form-group">
+ <input type="radio" id="rdo-import" value="import"
+ name="anon_choice" />
+ <label for="rdo-import">Import</label>
+ <input type="radio" id="rdo-delete" value="delete"
+ name="anon_choice" />
+ <label for="rdo-delete">Delete</label>
+ </div>
+
+ <input type="submit" class="btn btn-warning" value="Submit" />
+ </form>
+ </div>
+ </div>
+ {%endif%}
<div class="row" style="width: 100%;">
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index f14ccdd0..164cf9ce 100644
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -101,6 +101,8 @@ from wqflask.database import database_connection
import jobs.jobs as jobs
+from wqflask.oauth2.session import session_info
+from wqflask.oauth2.checks import user_logged_in
Redis = get_redis_conn()
@@ -147,13 +149,18 @@ def no_access_page():
@app.route("/")
def index_page():
- params = request.args
- if 'import_collections' in params:
- import_collections = params['import_collections']
- if import_collections == "true":
- g.user_session.import_traits_to_user(params['anon_id'])
- return render_template(
- "index_page.html", version=GN_VERSION, gn_server_url=GN_SERVER_URL)
+ anon_id = session_info()["anon_id"]
+ def __render__(colls):
+ return render_template("index_page.html", version=GN_VERSION,
+ gn_server_url=GN_SERVER_URL,
+ anon_collections=(
+ colls if user_logged_in() else []),
+ anon_id=anon_id)
+
+ return no_token_get(
+ f"oauth2/user/collections/{anon_id}/list").either(
+ lambda err: __render__([]),
+ __render__)
@app.route("/tmp/<img_path>")