caterva2.listusers#

caterva2.listusers(username=None, urlbase=None, auth_cookie=None)#

List the users in the subscriber.

Parameters:
  • username (str) – The username of the user to list (optional).

  • urlbase (str) – The base of URLs of the subscriber to query. Default is caterva2.sub_urlbase_default.

  • auth_cookie (str) – A HTTP cookie for authorizing access. This must be specified unless it was already specified inside a :py_obj:`caterva2.c2context`. The auth_cookie used must be from a superuser.

Returns:

The list of users in the subscriber.

Return type:

list of dict

Examples

>>> import caterva2 as cat2
>>> import numpy as np
>>> # To list the users you need to be a superuser
>>> # This example is intended to work when the subscriber is running locally
>>> super_user = {'username': 'superuser@example.com', 'password': 'foo'}
>>> super_auth = cat2.get_auth_cookie(cat2.sub_urlbase_default, user_auth=super_user)
>>> users = cat2.listusers(auth_cookie=super_auth)
>>> sorted(users[0].keys())
['email', 'hashed_password', 'id', 'is_active', 'is_superuser', 'is_verified']
>>> username = f'user{np.random.randint(0, 100)}@example.com'
>>> _ = cat2.adduser(username, 'foo', auth_cookie=super_auth)
>>> updated_users = cat2.listusers(auth_cookie=super_auth)
>>> len(users) + 1 == len(updated_users)
True
>>> user_info = cat2.listusers(username, auth_cookie=super_auth)
>>> user_info[0]['is_superuser']
False
>>> superuser_info = cat2.listusers('superuser@example.com', auth_cookie=super_auth)
>>> superuser_info[0]['is_superuser']
True