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.

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.

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.

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.

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.

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.

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.

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.

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.

Parameters

username (str or unicode) – 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.

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.

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.

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.

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.

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.

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.

Parameters

user_id (int) – An ID for a user.

Returns

py42.response.Py42Response

update_user(user_uid, username=None, email=None, password=None, first_name=None, last_name=None, notes=None, archive_size_quota_bytes=None)

Updates an existing user.

Parameters
  • user_uid (str or int) – A Code42 user UID.

  • username (str, optional) – The username to which the user’s username will be changed. Defaults to None.

  • email (str, optional) – The email to which the user’s email will be changed. Defaults to None.

  • password (str, optional) – The password to which the user’s password will be changed. Defaults to None.

  • first_name (str, optional) – The first name to which the user’s first name will be changed. Defaults to None.

  • last_name (str, optional) – The last name to which the user’s last name will be changed. Defaults to None.

  • notes (str, optional) – Descriptive information about the user. Defaults to None.

  • archive_size_quota_bytes (int, optional) – The quota in bytes that limits the user’s archive size. Defaults to None.

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.