Users

class py42.services.users.UserService(connection)

Bases: py42.services.BaseService

A service for interacting with Code42 user APIs. Use the UserService to create and retrieve users. You can also use it to block and deactivate users.

add_role(user_id, role_name)

Adds a role to a user. REST Documentation

Parameters:
  • user_id (int) – An ID for a user.
  • role_name (str) – The name of the role to assign to the user.
Returns:

py42.response.Py42Response

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:py42.response.Py42Response
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:

py42.response.Py42Response

create_user(org_uid, username, email, 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) – The email for the new user.
  • 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:

py42.response.Py42Response

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:

py42.response.Py42Response

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_available_roles()

Report the list of roles that are available for the authenticated user to assign to other users. V4 REST Documentation

Returns:py42.response.Py42Response
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:py42.response.Py42Response
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:py42.response.Py42Response
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:py42.response.Py42Response
get_current(**kwargs)

Gets the currently signed in user. REST Documentation

Returns:A response containing the user.
Return type:py42.response.Py42Response
get_page(page_num, active=None, email=None, org_uid=None, role_id=None, page_size=None, q=None, **kwargs)

Gets an individual page of users. REST Documentation

Parameters:
  • page_num (int) – The page number to request.
  • 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.
  • page_size (int, optional) – The number of items on the page. Defaults to py42.settings.items_per_page.
  • q (str, optional) – A generic query filter that searches across name, username, and email. Defaults to None.
Returns:

py42.response.Py42Response

get_roles(user_id)

Return the list of roles that are currently assigned to the given user. REST Documentation

Parameters:user_id (int) – An ID for a user.
Returns:py42.response.Py42Response
get_scim_data_by_uid(user_uid)

Returns SCIM data such as division, department, and title for a given user. REST Documentation

Parameters:user_uid (str) – A Code42 user uid.
Returns:py42.response.Py42Response
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:

py42.response.Py42Response

remove_role(user_id, role_name)

Removes a role from a user. REST Documentation <https://console.us.code42.com/apidocviewer/#UserRole-delete>`__

Parameters:
  • user_id (int) – An ID for a user.
  • role_name (str) – The name of the role to unassign from the user.
Returns:

py42.response.Py42Response

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:py42.response.Py42Response
class py42.usercontext.UserContext(administration_client)

Bases: object

An object representing the currently logged in user.

get_current_tenant_id()

Gets the currently signed in user’s tenant ID.