User
The User module provides functionality for working with users.
- class User(api, user_id, data={})[source]
Bases:
Base- Parameters:
api (GeoboxClient)
user_id (int)
data (dict)
- BASE_ENDPOINT: str = 'users/'
- __init__(api, user_id, data={})[source]
Initialize a User instance.
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
user_id (int) – the id of the user
data (Dict) – The data of the user.
- Return type:
None
- __repr__()[source]
Return a string representation of the User instance.
- Returns:
A string representation of the User instance.
- Return type:
str
- property status: UserStatus
User status Property
- Returns:
the user status
- Return type:
- classmethod get_users(api, **kwargs)[source]
Retrieves a list of users (Permission Required)
- Parameters:
api (GeoboxClient) – The API instance.
- Keyword Arguments:
status (UserStatus) – the status of the users filter.
q (str) – query filter based on OGC CQL standard. e.g. “field1 LIKE ‘%GIS%’ AND created_at > ‘2021-01-01’”
search (str) – search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
search_fields (str) – comma separated list of fields for searching.
order_by (str) – comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: “A” denotes ascending order and “D” denotes descending order.
return_count (bool) – Whether to return total count. default is False.
skip (int) – Number of items to skip. default is 0.
limit (int) – Number of items to return. default is 10.
user_id (int) – Specific user. privileges required.
shared (bool) – Whether to return shared maps. default is False.
- Returns:
list of users or the count number.
- Return type:
List[User] | int
Example
>>> from geobox import Geoboxclient >>> from geobox.user import User >>> client = GeoboxClient() >>> users = User.get_users(client) or >>> users = client.get_users()
- classmethod create_user(api, username, email, password, role, first_name, last_name, mobile, status)[source]
Create a User (Permission Required)
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
username (str) – the username of the user.
email (str) – the email of the user.
password (str) – the password of the user.
role (UserRole) – the role of the user.
first_name (str) – the firstname of the user.
last_name (str) – the lastname of the user.
mobile (str) – the mobile number of the user. e.g. “+98 9120123456”.
status (UserStatus) – the status of the user.
- Returns:
the user object.
- Return type:
Example
>>> from geobox import GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = User.create_user(client, ... username="user1", ... email="user1@example.com", ... password="P@ssw0rd", ... role=UserRole.ACCOUNT_ADMIN, ... first_name="user 1", ... last_name="user 1", ... mobile="+98 9120123456", ... status=UserStatus.ACTIVE) or >>> user = client.create_user(username="user1", ... email="user1@example.com", ... password="P@ssw0rd", ... role=UserRole.ACCOUNT_ADMIN, ... first_name="user 1", ... last_name="user 1", ... mobile="+98 9120123456", ... status=UserStatus.ACTIVE)
- classmethod search_users(api, search=None, skip=0, limit=10)[source]
Get list of users based on the search term.
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
search (str, optional) – The Search Term.
skip (int, optional) – Number of items to skip. default is 0.
limit (int, optional) – Number of items to return. default is 10.
- Returns:
A list of User instances.
- Return type:
List[User]
Example
>>> from geobox import GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> users = User.get_users(client, search="John") or >>> users = client.get_users(search="John")
- classmethod get_user(api, user_id='me')[source]
Get a user by its id (Permission Required)
- Parameters:
api (GeoboxClient) – The GeoboxClient instance for making requests.
user_id (int, optional) – Specific user. don’t specify a user_id to get the current user.
- Returns:
the user object.
- Return type:
- Raises:
NotFoundError – If the user with the specified id is not found.
Example
>>> from geobox import GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = User.get_user(client, user_id=1) or >>> user = client.get_user(user_id=1)
get the current user >>> user = User.get_user(client) or >>> user = client.get_user()
- update(**kwargs)[source]
Update the user (Permission Required)
- Keyword Arguments:
username (str)
email (str)
first_name (str)
last_name (str)
mobile (str) – e.g. “+98 9120123456”
status (UserStatus)
role (UserRole)
plan (Plan)
expiration_date (str)
- Returns:
updated data
- Return type:
Dict
Example
>>> from geobox imoprt GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = User.get_user(client, user_id=1) >>> user.update(status=UserStatus.PENDING)
- delete()[source]
Delete the user (Permission Required)
- Returns:
None
- Return type:
None
Example
>>> from geobox import GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = User.get_user(client, user_id=1) >>> user.delete()
- get_sessions(user_id='me')[source]
Get a list of user available sessions (Permission Required)
- Parameters:
user_id (int, optional) – Specific user. don’t specify user_id to get the current user.
- Returns:
list of user sessions.
- Return type:
List[Session]
Example
>>> from geobox import GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = User.get_user(client, user_id=1) or >>> user = client.get_user(user_id=1)
>>> user.get_sessions() or >>> client.get_sessions()
- change_password(new_password)[source]
Change the user password (privileges required)
- Parameters:
new_password (str) – new password for the user.
- Returns:
None
- Return type:
None
Example
>>> from geobox import GeoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = client.get_user(user_id=1) >>> user.change_password(new_password='user_new_password')
- class Session(uuid, data, user)[source]
Bases:
Base- Parameters:
uuid (str)
data (Dict)
user (User)
- __init__(uuid, data, user)[source]
Initialize a user session instance.
- Parameters:
uuid (str) – The unique identifier for the user session.
data (Dict) – The data of the session.
user (User) – the user instance.
- __repr__()[source]
Return a string representation of the resource.
- Returns:
A string representation of the Session object.
- Return type:
str
- close()[source]
Close the user session
- Returns:
None
- Return type:
None
Example
>>> from geobox import geoboxClient >>> from geobox.user import User >>> client = GeoboxClient() >>> user = User.get_user(client) # without user_id parameter, it gets the current user or >>> user = client.get_user() # without user_id parameter, it gets the current user >>> session = user.get_sessions()[0] >>> session.close()