aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/oauth2/collections.py
blob: 63bf206eaa35573dbc47463d47bf36ddb17ac293 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 the current session."""
    anon_id = session_info()["anon_id"]
    all_collections = no_token_get(
        f"auth/user/collections/{anon_id}/list").either(
            lambda _err: [], lambda colls: colls)
    if user_logged_in():
        all_collections = all_collections + oauth2_get(
            "auth/user/collections/list").either(
                lambda _err: [], lambda colls: colls)
    return len(all_collections)