enterprise.api package

Subpackages

Submodules

enterprise.api.filters module

Filters for enterprise API.

class enterprise.api.filters.EnterpriseCustomerInviteKeyFilterBackend

Bases: rest_framework.filters.BaseFilterBackend

Filter backend to return invite keys under the user’s enterprise(s) only. Supports filtering by enterprise_customer_uuid.

  • Staff users will bypass this filter.

filter_queryset(request, queryset, view)

Return a filtered queryset.

class enterprise.api.filters.EnterpriseCustomerUserFilterBackend

Bases: rest_framework.filters.BaseFilterBackend

Allow filtering on the enterprise customer user api endpoint.

filter_queryset(request, queryset, view)

Apply incoming filters only if user is staff. If not, only filter by user’s ID.

class enterprise.api.filters.EnterpriseLinkedUserFilterBackend

Bases: rest_framework.filters.BaseFilterBackend

Filter backend to return user’s linked enterprises only

  • Staff users will bypass this filter.

  • Non-staff users will receive only their linked enterprises.

filter_queryset(request, queryset, view)

Filter out enterprise customer if learner is not linked

class enterprise.api.filters.UserFilterBackend

Bases: rest_framework.filters.BaseFilterBackend

Filter backend for any view that needs to filter against the requesting user’s ID.

  • Staff users will bypass this filter.

  • Non-staff users will receive only those objects that match their own user ID.

This requires that USER_ID_FILTER be set in the view as a class variable, to identify the object’s relationship to a user ID.

filter_queryset(request, queryset, view)

Filter only for the user’s ID if non-staff.

enterprise.api.pagination module

Pagination helpers for enterprise api.

enterprise.api.pagination.get_paginated_response(data, request)

Update pagination links in course catalog data and return DRF Response.

Parameters
  • data (dict) – Dictionary containing catalog courses.

  • request (HttpRequest) – Current request object.

Returns

DRF response object containing pagination links.

Return type

(Response)

enterprise.api.throttles module

Throttle classes for enterprise API.

class enterprise.api.throttles.ServiceUserThrottle

Bases: rest_framework.throttling.UserRateThrottle

A throttle allowing the service user to override rate limiting.

allow_request(request, view)

Modify throttling for service users.

Updates throttling rate if the request is coming from the service user, and defaults to UserRateThrottle’s configured setting otherwise.

Updated throttling rate comes from DEFAULT_THROTTLE_RATES key in REST_FRAMEWORK setting. service user throttling is specified in DEFAULT_THROTTLE_RATES by service_user key

Example Setting:

REST_FRAMEWORK = {
    ...
    'DEFAULT_THROTTLE_RATES': {
        ...
        'service_user': '50/day'
    }
}
update_throttle_scope()

Update throttle scope so that service user throttle rates are applied.

enterprise.api.urls module

URL definitions for enterprise API endpoint.

enterprise.api.utils module

Utility functions for the Enterprise API.

enterprise.api.utils.create_message_body(email, enterprise_name, number_of_codes=None, notes=None)

Return the message body with extra information added by user.

enterprise.api.utils.get_ent_cust_from_enterprise_customer_key(enterprise_customer_key)

Get the enterprise customer id given an enterprise customer key.

enterprise.api.utils.get_ent_cust_from_report_config_uuid(uuid)

Get the enterprise customer id given an enterprise report configuration UUID.

enterprise.api.utils.get_enterprise_customer_from_catalog_id(catalog_id)

Get the enterprise customer id given an enterprise customer catalog id.

enterprise.api.utils.get_enterprise_customer_from_user_id(user_id)

Get the enterprise customer id given an user id

enterprise.api.utils.get_service_usernames()

Return the set of service usernames that are given extended permissions in the API.

Module contents

Python API for various enterprise functionality.

enterprise.api.activate_admin_permissions(enterprise_customer_user)

Activates admin permissions for an existing PendingEnterpriseCustomerAdminUser.

Specifically, the “enterprise_admin” system-wide role is assigned to the user and the PendingEnterpriseCustomerAdminUser record is removed.

Requires an EnterpriseCustomerUser record to exist which ensures the user already has the “enterprise_learner” role as a prerequisite.

Parameters

enterprise_customer_user – an EnterpriseCustomerUser instance