Users¶
-
class
py42.clients.users.
UserClient
(session)¶ Bases:
py42.clients.BaseClient
A client for interacting with Code42 user APIs. Use the UserClient to create and retrieve users. You can also use it to block and deactivate users.
-
block
(user_id)¶ Blocks the user with the given ID. A blocked user is not allowed to log in or restore files. Backups will continue if the user is still active. REST Documentation
- Parameters
user_id (int) – An ID for a user.
- Returns
-
change_org_assignment
(user_id, org_id)¶ Assigns a user to a different organization. REST Documentation
- Parameters
user_id (int) – An ID for a user.
org_id (int) – An ID for the organization to move the user to.
- Returns
-
create_user
(org_uid, username, email=None, password=None, first_name=None, last_name=None, notes=None)¶ Creates a new user. WARNING: If the provided username already exists for a user, it will be updated in the database instead. REST Documentation
- Parameters
org_uid (str) – The org UID for the organization the new user belongs to.
username (str) – The username for the new user.
email (str, optional) – The email for the new user. Defaults to None.
password (str, optional) – The password for the new user. Defaults to None.
first_name (str, optional) – The first name for the new user. Defaults to None.
last_name (str, optional) – The last name for the new user. Defaults to None.
notes (str, optional) – Descriptive information about the user. Defaults to None.
- Returns
-
deactivate
(user_id, block_user=None)¶ Deactivates the user with the given user ID. Backups discontinue for a deactivated user, and their archives go to cold storage. REST Documentation
- Parameters
user_id (int) – An ID for a user.
block_user (bool, optional) – Blocks the user upon deactivation. Defaults to None.
- Returns
-
get_all
(active=None, email=None, org_uid=None, role_id=None, q=None, **kwargs)¶ Gets all users. REST Documentation
- Parameters
active (bool, optional) – True gets active users only, and false gets deactivated users only. Defaults to None.
email (str, optional) – Limits users to only those with this email. Defaults to None.
org_uid (str, optional) – Limits users to only those in the organization with this org UID. Defaults to None.
role_id (int, optional) – Limits users to only those with a given role ID. Defaults to None.
q (str, optional) – A generic query filter that searches across name, username, and email. Defaults to None.
- Returns
An object that iterates over
py42.response.Py42Response
objects that each contain a page of users.- Return type
generator
-
get_by_id
(user_id, **kwargs)¶ Gets the user with the given ID. REST Documentation
- Parameters
user_id (int) – An ID for a user.
- Returns
A response containing the user.
- Return type
-
get_by_uid
(user_uid, **kwargs)¶ Gets the user with the given UID. REST Documentation
- Parameters
user_uid (str) – A UID for a user.
- Returns
A response containing the user.
- Return type
-
get_by_username
(username, **kwargs)¶ Gets the user with the given username. REST Documentation
- Parameters
username (str) – A username for a user.
- Returns
A response containing the user.
- Return type
-
get_current
(**kwargs)¶ Gets the currently signed in user. REST Documentation
- Returns
A response containing the user.
- Return type
-
reactivate
(user_id, unblock_user=None)¶ Reactivates the user with the given ID. REST Documentation
- Parameters
user_id (int) – An ID for a user.
unblock_user (bool, optional) – Whether or not to unblock the user. Defaults to None.
- Returns
-
unblock
(user_id)¶ Removes a block, if one exists, on the user with the given user ID. Unblocked users are allowed to log in and restore. REST Documentation
- Parameters
user_id (int) – An ID for a user.
- Returns
-