aboutsummaryrefslogtreecommitdiff
path: root/gn3/auth/authorisation/users/views.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-05-12 12:54:01 +0300
committerFrederick Muriuki Muriithi2023-05-12 12:54:01 +0300
commit2bdd136b18765fba47a8e313ebff3e65086ca1b1 (patch)
treef58034bf4903620d19910701dad8f32541f078b0 /gn3/auth/authorisation/users/views.py
parentfe7670fbad187d81e9c395d03d4b3c69a0a6a1f3 (diff)
downloadgenenetwork3-2bdd136b18765fba47a8e313ebff3e65086ca1b1.tar.gz
auth: Provide separate endpoint for anonymous collections.
Diffstat (limited to 'gn3/auth/authorisation/users/views.py')
-rw-r--r--gn3/auth/authorisation/users/views.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/gn3/auth/authorisation/users/views.py b/gn3/auth/authorisation/users/views.py
index 2b4230e..a0f00de 100644
--- a/gn3/auth/authorisation/users/views.py
+++ b/gn3/auth/authorisation/users/views.py
@@ -1,5 +1,6 @@
"""User authorisation endpoints."""
import traceback
+from uuid import UUID
from typing import Any
from functools import partial
@@ -22,8 +23,9 @@ from ..errors import (
NotFoundError, UsernameError, PasswordError, UserRegistrationError)
from ...authentication.oauth2.resource_server import require_oauth
-from ...authentication.users import User, save_user, set_user_password
from ...authentication.oauth2.models.oauth2token import token_by_access_token
+from ...authentication.users import (
+ User, save_user, user_by_id, set_user_password)
users = Blueprint("users", __name__)
@@ -181,3 +183,21 @@ def list_user_collections() -> Response:
Redis.from_url(current_app.config["REDIS_URI"],
decode_responses=True) as redisconn):
return jsonify(user_collections(redisconn, the_token.user))
+
+@users.route("<uuid:anon_id>/collections/list")
+def list_anonymous_collections(anon_id: UUID) -> Response:
+ """Fetch anonymous collections"""
+ with Redis.from_url(
+ current_app.config["REDIS_URI"], decode_responses=True) as redisconn:
+ def __list__(conn: db.DbConnection) -> tuple:
+ try:
+ _user = user_by_id(conn, anon_id)
+ current_app.logger.warning(
+ "Fetch collections for authenticated user using the "
+ "`list_user_collections()` endpoint.")
+ return tuple()
+ except NotFoundError as _nfe:
+ return user_collections(
+ redisconn, User(anon_id, "anon@ymous.user", "Anonymous User"))
+
+ return jsonify(with_db_connection(__list__))