aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-05-17 11:15:33 +0300
committerFrederick Muriuki Muriithi2023-05-17 11:15:33 +0300
commit0fb42e6f935c3a31196e5b529c1fcd355451188c (patch)
treeb0b5eedc94b2256caf1ec1d69354d87405f0fc1f
parentb1041332ef0437031839d4e6ad64f4c7b797d6f8 (diff)
downloadgenenetwork2-0fb42e6f935c3a31196e5b529c1fcd355451188c.tar.gz
auth: Integrate collections badge with auth
Show the total number of collections available in the active session in the collections badge at the top of the page. Also do some minor UI tweaks to differentiate the user and anonymous collections.
-rw-r--r--wqflask/wqflask/__init__.py4
-rw-r--r--wqflask/wqflask/oauth2/collections.py16
-rw-r--r--wqflask/wqflask/templates/base.html2
-rw-r--r--wqflask/wqflask/templates/collections/list.html8
4 files changed, 26 insertions, 4 deletions
diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py
index 38a69d33..13685324 100644
--- a/wqflask/wqflask/__init__.py
+++ b/wqflask/wqflask/__init__.py
@@ -32,6 +32,7 @@ from wqflask.api.markdown import news_blueprint
from wqflask.api.jobs import jobs as jobs_bp
from wqflask.oauth2.routes import oauth2
from wqflask.oauth2.checks import user_logged_in
+from wqflask.oauth2.collections import num_collections
from wqflask.oauth2.request_utils import user_details, authserver_authorise_uri
from wqflask.jupyter_notebooks import jupyter_notebooks
@@ -55,7 +56,8 @@ app.jinja_env.globals.update(
numify=formatting.numify,
logged_in=user_logged_in,
authserver_authorise_uri=authserver_authorise_uri,
- user_details=user_details)
+ user_details=user_details,
+ num_collections=num_collections)
app.config["SESSION_REDIS"] = redis.from_url(app.config["REDIS_URL"])
diff --git a/wqflask/wqflask/oauth2/collections.py b/wqflask/wqflask/oauth2/collections.py
new file mode 100644
index 00000000..e31b4ad2
--- /dev/null
+++ b/wqflask/wqflask/oauth2/collections.py
@@ -0,0 +1,16 @@
+"""Functions for collections."""
+from .session import session_info
+from .checks import user_logged_in
+from .client import oauth2_get, no_token_get
+
+def num_collections() -> int:
+ """Compute the number of collections available for tte current sussion."""
+ anon_id = session_info()["anon_id"]
+ all_collections = no_token_get(
+ f"oauth2/user/collections/{anon_id}/list").either(
+ lambda _err: [], lambda colls: colls)
+ if user_logged_in():
+ all_collections = all_collections + oauth2_get(
+ "oauth2/user/collections/list").either(
+ lambda _err: [], lambda colls: colls)
+ return len(all_collections)
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html
index 38819240..126e1b82 100644
--- a/wqflask/wqflask/templates/base.html
+++ b/wqflask/wqflask/templates/base.html
@@ -141,7 +141,7 @@
{% if g.user_session %}
<li class="">
<a href="/collections/list">Collections
- <span class="badge badge-info">{{ g.user_session.num_collections }}</span>
+ <span class="badge badge-info">{{num_collections()}}</span>
</a>
</li>
<li class="">
diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html
index 437b0cc3..fc524c73 100644
--- a/wqflask/wqflask/templates/collections/list.html
+++ b/wqflask/wqflask/templates/collections/list.html
@@ -34,7 +34,7 @@
{{display_error("Anonymous Collections", anon_collections_error)}}
{%endif%}
{%if anon_collections | length > 0%}
- <table class="table-hover table-striped cell-border" id='trait_table'
+ <table class="table-hover table-striped cell-border" id='anon_trait_table'
style="float: left;">
<caption>Anonymous Collections</caption>
<thead>
@@ -64,7 +64,10 @@
</tbody>
</table>
{%endif%}
- {% if collections|length > 0 %}
+ {% if collections|length > 0 %}
+ {% if (anon_collections | length > 0) and (collections | length > 0) %}
+ <hr />
+ {%endif%}
<table class="table-hover table-striped cell-border" id='trait_table' style="float: left;">
<caption>User Collections</caption>
<thead>
@@ -126,6 +129,7 @@
{ "type": "natural", "width": "15%", "targets": 5}
];
+ create_table("anon_trait_table", [], columnDefs)
create_table(tableId, [], columnDefs)
submit_special = function(url) {