aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/collect.py27
-rw-r--r--wqflask/wqflask/oauth2/client.py1
-rw-r--r--wqflask/wqflask/templates/collections/list.html35
3 files changed, 52 insertions, 11 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index 2149dd20..5ff114b2 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -10,6 +10,7 @@ from flask import url_for
from flask import request
from flask import redirect
from flask import flash
+from flask import current_app
from wqflask import app
from utility import hmac
@@ -22,8 +23,10 @@ from base.trait import retrieve_trait_info
from base.trait import jsonable
from base.data_set import create_dataset
-from wqflask.oauth2.client import oauth2_get
+from wqflask.oauth2 import session
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
Redis = get_redis_conn()
@@ -142,20 +145,22 @@ def create_new(collection_name):
@app.route("/collections/list")
def list_collections():
params = request.args
+ anon_id = session.session_info()["anon_id"]
+ anon_collections = no_token_get(
+ f"oauth2/user/{anon_id}/collections/list").either(
+ lambda err: {"anon_collections_error": process_error(err)},
+ lambda colls: {"anon_collections": colls})
+ user_collections = {"collections": []}
if user_logged_in():
- return oauth2_get("oauth2/user/collections").either(
- lambda err: __error__(process_error(err)),
- lambda colls: render_template(
- "collections/list.html", params=params, collections=colls))
-
- # TODO: Provide GN3 endpoint to fetch collections for anonymous users
- # Maybe /oauth2/user/<uuid:anon_user_id>/collections/list
- user_collections = list(g.user_session.user_collections)
+ user_collections = oauth2_get("oauth2/user/collections/list").either(
+ lambda err: {"user_collections_error": process_error(err)},
+ lambda colls: {"collections": colls})
+
return render_template("collections/list.html",
params=params,
- collections=user_collections,
- )
+ **user_collections,
+ **anon_collections)
@app.route("/collections/remove", methods=('POST',))
diff --git a/wqflask/wqflask/oauth2/client.py b/wqflask/wqflask/oauth2/client.py
index 249d158d..b070e0bc 100644
--- a/wqflask/wqflask/oauth2/client.py
+++ b/wqflask/wqflask/oauth2/client.py
@@ -1,4 +1,5 @@
"""Common oauth2 client utilities."""
+import json
import requests
from typing import Any, Optional
from urllib.parse import urljoin
diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html
index 1a125dbb..7e5c5330 100644
--- a/wqflask/wqflask/templates/collections/list.html
+++ b/wqflask/wqflask/templates/collections/list.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{%from "oauth2/display_error.html" import display_error%}
{% block title %}Your Collections{% endblock %}
{% block css %}
<link rel="stylesheet" type="text/css" href="{{ url_for('css', filename='DataTables/css/jquery.dataTables.css') }}" />
@@ -29,6 +30,40 @@
</div>
<br>
<div id="collections_list" style="width:50%; margin-top: 10px; margin-bottom: 10px;">
+ {%if anon_collections_error is defined%}
+ {{display_error("Anonymous Collections", anon_collections_error)}}
+ {%endif%}
+ {%if anon_collections | length > 0%}
+ <table class="table-hover table-striped cell-border" id='trait_table'
+ style="float: left;">
+ <caption>Anonymous Collections</caption>
+ <thead>
+ <tr>
+ <th></th>
+ <th>Index</th>
+ <th>Name</th>
+ <th>Created</th>
+ <th>Last Changed</th>
+ <th># Records</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {% for uc in anon_collections %}
+ {% if uc.num_members > 0 %}
+ <tr class="collection_line">
+ <td align="center" style="padding: 0px;"><INPUT TYPE="checkbox" NAME="collection" class="checkbox trait_checkbox" VALUE="{{ uc.id }}"></td>
+ <td align="right">{{ loop.index }}
+ <td><a class="collection_name" href="{{ url_for('view_collection', uc_id=uc.id) }}">{{ uc.name }}</a></td>
+ <td>{{ uc.created_timestamp }}</td>
+ <td>{{ uc.changed_timestamp }}</td>
+ <td align="right">{{ uc.num_members }}</td>
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </tbody>
+ </table>
+ {%endif%}
{% if collections|length > 0 %}
<table class="table-hover table-striped cell-border" id='trait_table' style="float: left;">
<thead>