enterprise.api.v1 package

Submodules

enterprise.api.v1.decorators module

Decorators for Enterprise API views.

enterprise.api.v1.decorators.require_at_least_one_query_parameter(*query_parameter_names)

Ensure at least one of the specified query parameters are included in the request.

This decorator checks for the existence of at least one of the specified query parameters and passes the values as function parameters to the decorated view. If none of the specified query parameters are included in the request, a ValidationError is raised.

Usage:

@require_at_least_one_query_parameter('program_uuids', 'course_run_ids')
def my_view(request, program_uuids, course_run_ids):
    # Some functionality ...

enterprise.api.v1.fields module

Fields for Enterprise API serializers.

class enterprise.api.v1.fields.Base64EmailCSVField(*args, **kwargs)

Bases: rest_framework.fields.Field

Serializers a Base64 encoded CSV with emails into an array of emails

to_internal_value(data)

Transform the incoming primitive data into a native value.

to_representation(value)

Transform the outgoing native value into primitive data.

enterprise.api.v1.permissions module

Custom API permissions.

class enterprise.api.v1.permissions.IsInEnterpriseGroup

Bases: rest_framework.permissions.BasePermission

Find out if the requesting user belongs to a django group meant for granting access to an enterprise feature. This check applies to both staff and non-staff users.

ALLOWED_API_GROUPS = []
has_permission(request, view)

Return True if permission is granted, False otherwise.

message = 'User is not allowed to access the view.'

enterprise.api.v1.serializers module

Serializers for enterprise api version 1.

class enterprise.api.v1.serializers.AdminNotificationSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for AdminNotification model.

class Meta

Bases: object

fields = ('id', 'title', 'text')
model

alias of enterprise.models.AdminNotification

class enterprise.api.v1.serializers.BaseEnterpriseCustomerInviteKeySerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Base serializer for writing to the EnterpriseCustomerInviteKey model.

class Meta

Bases: object

fields = ('uuid', 'enterprise_customer_uuid', 'usage_limit', 'expiration_date', 'is_active', 'is_valid')
model

alias of enterprise.models.EnterpriseCustomerInviteKey

class enterprise.api.v1.serializers.CourseDetailSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.ImmutableStateSerializer

Serializer for course data retrieved from the discovery service course detail API endpoint.

This serializer updates the course and course run data with the EnterpriseCustomer-specific enrollment page URL for the given course and course runs.

to_representation(instance)

Return the updated course data dictionary.

Parameters

instance (dict) – The course data.

Returns

The updated course data.

Return type

dict

class enterprise.api.v1.serializers.CourseRunDetailSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.ImmutableStateSerializer

Serializer for course run data retrieved from the discovery service course_run detail API endpoint.

This serializer updates the course run data with the EnterpriseCustomer-specific enrollment page URL for the given course run.

to_representation(instance)

Return the updated course run data dictionary.

Parameters

instance (dict) – The course run data.

Returns

The updated course run data.

Return type

dict

class enterprise.api.v1.serializers.EnterpriseCourseEnrollmentReadOnlySerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCourseEnrollment model.

class Meta

Bases: object

fields = ('enterprise_customer_user', 'course_id')
model

alias of enterprise.models.EnterpriseCourseEnrollment

class enterprise.api.v1.serializers.EnterpriseCourseEnrollmentWriteSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for writing to the EnterpriseCourseEnrollment model.

class Meta

Bases: object

fields = ('username', 'course_id')
model

alias of enterprise.models.EnterpriseCourseEnrollment

enterprise_customer_user = None
save()

Save the model with the found EnterpriseCustomerUser.

validate_username(value)

Verify that the username has a matching user, and that the user has an associated EnterpriseCustomerUser.

class enterprise.api.v1.serializers.EnterpriseCustomerBasicSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCustomer model only for name and id fields.

class Meta

Bases: object

fields = ('id', 'name')
model

alias of enterprise.models.EnterpriseCustomer

class enterprise.api.v1.serializers.EnterpriseCustomerBrandingConfigurationSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCustomerBrandingConfiguration model.

class Meta

Bases: object

fields = ('enterprise_customer', 'enterprise_slug', 'logo', 'primary_color', 'secondary_color', 'tertiary_color')
model

alias of enterprise.models.EnterpriseCustomerBrandingConfiguration

get_enterprise_customer(obj)

Return a string representation of the associated enterprise customer’s UUID.

get_enterprise_slug(obj)

Return the slug of the associated enterprise customer.

Use EnterpriseCustomerBrandingConfiguration.safe_logo_url to return an absolute URL for either the saved customer logo or the platform logo by default

get_primary_color(obj)

Return the primary color of the branding config OR the default primary color code

get_secondary_color(obj)

Return the secondary color of the branding config OR the default secondary color code

get_tertiary_color(obj)

Return the tertiary color of the branding config OR the default tertiary color code

class enterprise.api.v1.serializers.EnterpriseCustomerBulkEnrollmentsSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Serializes a email_csv or email field for bulk enrollment requests.

create(validated_data)
validate(data)
class enterprise.api.v1.serializers.EnterpriseCustomerBulkSubscriptionEnrollmentsSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Serializes a licenses info field for bulk enrollment requests.

create(validated_data)
validate(data)
class enterprise.api.v1.serializers.EnterpriseCustomerCatalogDetailSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.EnterpriseCustomerCatalogSerializer

Serializer for the EnterpriseCustomerCatalog model which includes the catalog’s discovery service search query results.

to_representation(instance)

Serialize the EnterpriseCustomerCatalog object.

Parameters

instance (EnterpriseCustomerCatalog) – The EnterpriseCustomerCatalog to serialize.

Returns

The EnterpriseCustomerCatalog converted to a dict.

Return type

dict

class enterprise.api.v1.serializers.EnterpriseCustomerCatalogSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for the EnterpriseCustomerCatalog model.

class Meta

Bases: object

fields = ('uuid', 'title', 'enterprise_customer')
model

alias of enterprise.models.EnterpriseCustomerCatalog

class enterprise.api.v1.serializers.EnterpriseCustomerCourseEnrollmentsListSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ListSerializer

Serializes a list of enrollment requests.

Meant to be used in conjunction with EnterpriseCustomerCourseEnrollmentsSerializer.

create(validated_data)

This selectively calls the child create method based on whether or not validation failed for each payload.

to_internal_value(data)

This implements the same relevant logic as ListSerializer except that if one or more items fail validation, processing for other items that did not fail will continue.

to_representation(data)

This selectively calls to_representation on each result that was processed by create.

class enterprise.api.v1.serializers.EnterpriseCustomerCourseEnrollmentsSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Serializes enrollment information for a collection of students/emails.

This is mainly useful for implementing validation when performing enrollment operations.

class Meta

Bases: object

list_serializer_class

alias of enterprise.api.v1.serializers.EnterpriseCustomerCourseEnrollmentsListSerializer

create(validated_data)

Perform the enrollment for existing enterprise customer users, or create the pending objects for new users.

validate(data)

Validate that at least one of the user identifier fields has been passed in.

validate_course_run_id(value)

Validates that the course run id is part of the Enterprise Customer’s catalog.

validate_lms_user_id(value)

Validates the lms_user_id, if is given, to see if there is an existing EnterpriseCustomerUser for it.

validate_tpa_user_id(value)

Validates the tpa_user_id, if is given, to see if there is an existing EnterpriseCustomerUser for it.

It first uses the third party auth api to find the associated username to do the lookup.

validate_user_email(value)

Validates the user_email, if given, to see if an existing EnterpriseCustomerUser exists for it.

If it does not, it does not fail validation, unlike for the other field validation methods above.

class enterprise.api.v1.serializers.EnterpriseCustomerIdentityProviderSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCustomerIdentityProvider model.

class Meta

Bases: object

fields = ('provider_id', 'default_provider')
model

alias of enterprise.models.EnterpriseCustomerIdentityProvider

class enterprise.api.v1.serializers.EnterpriseCustomerInviteKeyPartialUpdateSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for updating the EnterpriseCustomerInviteKey model.

class Meta

Bases: object

fields = ('expiration_date', 'is_active')
model

alias of enterprise.models.EnterpriseCustomerInviteKey

class enterprise.api.v1.serializers.EnterpriseCustomerInviteKeyReadOnlySerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.BaseEnterpriseCustomerInviteKeySerializer

Serializer for reading the EnterpriseCustomerInviteKey model.

class Meta

Bases: enterprise.api.v1.serializers.BaseEnterpriseCustomerInviteKeySerializer.Meta

additional_fields = ('enterprise_customer_name', 'usage_count', 'created')
fields = ('uuid', 'enterprise_customer_uuid', 'usage_limit', 'expiration_date', 'is_active', 'is_valid', 'enterprise_customer_name', 'usage_count', 'created')
get_enterprise_customer_name(obj)
get_enterprise_customer_uuid(obj)
class enterprise.api.v1.serializers.EnterpriseCustomerInviteKeyWriteSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.BaseEnterpriseCustomerInviteKeySerializer

Serializer for writing to the EnterpriseCustomerInviteKey model.

save()
validate_enterprise_customer_uuid(value)

Validates an EnterpriseCustomer with the given enterprise_customer_uuid exists.

class enterprise.api.v1.serializers.EnterpriseCustomerReportingConfigurationSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCustomerReportingConfiguration model.

class Meta

Bases: object

fields = ('enterprise_customer', 'enterprise_customer_id', 'active', 'delivery_method', 'email', 'frequency', 'day_of_month', 'day_of_week', 'hour_of_day', 'include_date', 'encrypted_password', 'sftp_hostname', 'sftp_port', 'sftp_username', 'encrypted_sftp_password', 'sftp_file_path', 'data_type', 'report_type', 'pgp_encryption_key', 'enterprise_customer_catalogs', 'uuid', 'enterprise_customer_catalog_uuids', 'enable_compression')
model

alias of enterprise.models.EnterpriseCustomerReportingConfiguration

create(validated_data)

Perform the creation of model instance and link the enterprise customer catalogs.

Parameters

validated_data (dict) – A dictionary containing serializer’s validated data.

Returns

Instance of the newly created enterprise customer

reporting configuration.

Return type

(EnterpriseCustomerReportingConfiguration)

update(instance, validated_data)

Update the instance of enterprise customer reporting configuration and link the enterprise customer catalogs.

Parameters
Returns

Instance of the newly created enterprise customer

reporting configuration.

Return type

(EnterpriseCustomerReportingConfiguration)

validate(data)
class enterprise.api.v1.serializers.EnterpriseCustomerSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCustomer model.

class Meta

Bases: object

fields = ('uuid', 'name', 'slug', 'active', 'site', 'enable_data_sharing_consent', 'enforce_data_sharing_consent', 'branding_configuration', 'identity_provider', 'enable_audit_enrollment', 'replace_sensitive_sso_username', 'enable_portal_code_management_screen', 'sync_learner_profile_data', 'enable_audit_data_reporting', 'enable_learner_portal', 'enable_learner_portal_offers', 'enable_portal_learner_credit_management_screen', 'enable_executive_education_2U_fulfillment', 'enable_portal_reporting_config_screen', 'enable_portal_saml_configuration_screen', 'contact_email', 'enable_portal_subscription_management_screen', 'hide_course_original_price', 'enable_analytics_screen', 'enable_integrated_customer_learner_portal_search', 'enable_portal_lms_configurations_screen', 'sender_alias', 'identity_providers', 'enterprise_customer_catalogs', 'reply_to', 'enterprise_notification_banner', 'hide_labor_market_data', 'modified', 'enable_universal_link', 'enable_browse_and_request', 'admin_users')
model

alias of enterprise.models.EnterpriseCustomer

get_admin_users(obj)
get_branding_configuration(obj)

Return the serialized branding configuration object OR default object if null

get_enterprise_customer_catalogs(obj)

Return list of catalog uuids associated with the enterprise customer.

get_enterprise_notification_banner(obj)

Return the notification text if exist OR None

class enterprise.api.v1.serializers.EnterpriseCustomerToggleUniversalLinkSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Serializer for toggling an EnterpriseCustomer enable_universal_link field.

class enterprise.api.v1.serializers.EnterpriseCustomerUnlinkUsersSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Serializer for the EnterpriseCustomerViewSet unlink_users action.

class enterprise.api.v1.serializers.EnterpriseCustomerUserReadOnlySerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for EnterpriseCustomerUser model.

class Meta

Bases: object

fields = ('id', 'enterprise_customer', 'active', 'user_id', 'user', 'data_sharing_consent_records', 'groups', 'created', 'invite_key', 'role_assignments')
model

alias of enterprise.models.EnterpriseCustomerUser

Return serialization of EnterpriseCustomerUser.data_sharing_consent_records property.

Parameters

EnterpriseCustomerUser – The EnterpriseCustomerUser.

Returns

The serialized DataSharingConsent records associated with the EnterpriseCustomerUser.

Return type

list of dict

get_groups(obj)

Return the enterprise related django groups that this user is a part of.

get_role_assignments(obj)

Return the enterprise role assignments for this enterprise customer user.

class enterprise.api.v1.serializers.EnterpriseCustomerUserWriteSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for writing to the EnterpriseCustomerUser model.

class Meta

Bases: object

fields = ('enterprise_customer', 'username', 'active')
model

alias of enterprise.models.EnterpriseCustomerUser

USER_DOES_NOT_EXIST = 'User does not exist'
save()

Save the EnterpriseCustomerUser.

user = None
validate_username(value)

Verify that the username has a matching user.

class enterprise.api.v1.serializers.ImmutableStateSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Base serializer for any serializer that inhibits state changing requests.

create(validated_data)

Do not perform any operations for state changing requests.

update(instance, validated_data)

Do not perform any operations for state changing requests.

class enterprise.api.v1.serializers.LicensedEnterpriseCourseEnrollmentReadOnlySerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for LicensedEnterpriseCourseEnrollment model.

class Meta

Bases: object

fields = ('enterprise_course_enrollment', 'license_uuid')
model

alias of enterprise.models.LicensedEnterpriseCourseEnrollment

class enterprise.api.v1.serializers.LicensesInfoSerializer(*args, **kwargs)

Bases: rest_framework.serializers.Serializer

Nested serializer class to allow for many license info dictionaries.

create(validated_data)
validate(data)
class enterprise.api.v1.serializers.LinkLearnersSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.PendingEnterpriseCustomerUserSerializer

Extends the PendingEnterpriseCustomerSerializer to validate that the enterprise customer uuid matches the uuid the user has permissions to update

NOT_AUTHORIZED_ERROR = 'Not authorized for this enterprise'
validate_enterprise_customer(value)

Check that the enterprise customer is the same as the one the user has permissions for The value recieved is an EnterpriseCustomer object

class enterprise.api.v1.serializers.PendingEnterpriseCustomerUserSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for writing to the PendingEnterpriseCustomerUser model.

class Meta

Bases: object

fields = ('enterprise_customer', 'user_email')
model

alias of enterprise.models.PendingEnterpriseCustomerUser

create(attrs)

Create the PendingEnterpriseCustomerUser, or EnterpriseCustomerUser if a user with the validated_email already exists.

to_representation(instance)

Because we are returning whether or not the instance was created from the create method, we must use the instance for to_representation and ignore the “created” half of the tuple

class enterprise.api.v1.serializers.ProgramDetailSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.ImmutableStateSerializer

Serializer for program data retrieved from the discovery service program detail API endpoint.

This serializer updates the program data and child course run data with EnterpriseCustomer-specific enrollment page URLs for the given content types.

to_representation(instance)

Return the updated program data dictionary.

Parameters

instance (dict) – The program data.

Returns

The updated program data.

Return type

dict

class enterprise.api.v1.serializers.ResponsePaginationSerializer(*args, **kwargs)

Bases: enterprise.api.v1.serializers.ImmutableStateSerializer

Serializer for responses that require pagination.

class enterprise.api.v1.serializers.SiteSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for Site model.

class Meta

Bases: object

fields = ('domain', 'name')
model

alias of django.contrib.sites.models.Site

class enterprise.api.v1.serializers.UserSerializer(*args, **kwargs)

Bases: rest_framework.serializers.ModelSerializer

Serializer for User model.

class Meta

Bases: object

fields = ('id', 'username', 'first_name', 'last_name', 'email', 'is_staff', 'is_active', 'date_joined')
model

alias of django.contrib.auth.models.User

enterprise.api.v1.urls module

URL definitions for enterprise api version 1 endpoint.

enterprise.api.v1.views module

Views for enterprise api version 1 endpoint.

class enterprise.api.v1.views.CatalogQueryView(**kwargs)

Bases: rest_framework.views.APIView

View for enterprise catalog query. This will be called from django admin tool to populate content_filter field of EnterpriseCustomerCatalog model.

authentication_classes = [<class 'rest_framework.authentication.SessionAuthentication'>]
get(request, catalog_query_id)

API endpoint for fetching an enterprise catalog query.

http_method_names = ['get']
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>, <class 'rest_framework.permissions.IsAdminUser'>]
class enterprise.api.v1.views.CouponCodesView(**kwargs)

Bases: rest_framework.views.APIView

API to request coupon codes.

MISSING_REQUIRED_PARAMS_MSG = 'Some required parameter(s) missing: {}'
OPTIONAL_PARAM_NOTES = 'notes'
OPTIONAL_PARAM_NUMBER_OF_CODES = 'number_of_codes'
REQUIRED_PARAM_EMAIL = 'email'
REQUIRED_PARAM_ENTERPRISE_NAME = 'enterprise_name'
authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>)
get_missing_params_message(parameter_state)

Get a user-friendly message indicating a missing parameter for the API endpoint.

get_required_query_params(request)

Gets email, enterprise_name, number_of_codes, and notes, which are the relevant parameters for this API endpoint.

Parameters

request – The request to this endpoint.

Returns

The email, enterprise_name, number_of_codes and notes from the request.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
post(request)

POST /enterprise/api/v1/request_codes

Requires a JSON object of the following format:

{
    "email": "bob@alice.com",
    "enterprise_name": "IBM",
    "number_of_codes": "50",
    "notes": "Help notes for codes request",
}
Keys
  • email – Email of the customer who has requested more codes.

  • enterprise_name – The name of the enterprise requesting more codes.

  • number_of_codes – The number of codes requested.

  • notes – Help notes related to codes request.

throttle_classes = (<class 'enterprise.api.throttles.ServiceUserThrottle'>,)
exception enterprise.api.v1.views.EnrollmentModificationException

Bases: Exception

An exception that represents an error when modifying the state of an enrollment via the EnrollmentApiClient.

class enterprise.api.v1.views.EnterpriseCourseEnrollmentViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API views for the enterprise-course-enrollment API endpoint.

FIELDS = ('enterprise_customer_user', 'course_id')
USER_ID_FILTER = 'enterprise_customer_user__user_id'
basename = None
description = None
detail = None
filterset_fields = ('enterprise_customer_user', 'course_id')
get_serializer_class()

Use a special serializer for any requests that aren’t read-only.

name = None
ordering_fields = ('enterprise_customer_user', 'course_id')
queryset
suffix = None
class enterprise.api.v1.views.EnterpriseCustomerBrandingConfigurationViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API views for the enterprise-customer-branding API endpoint.

FIELDS = ('enterprise_customer__slug',)
USER_ID_FILTER = 'enterprise_customer__enterprise_customer_users__user_id'
basename = None
description = None
detail = None
filterset_fields = ('enterprise_customer__slug',)
lookup_field = 'enterprise_customer__slug'
name = None
ordering_fields = ('enterprise_customer__slug',)
parser_classes = [<class 'rest_framework.parsers.MultiPartParser'>, <class 'rest_framework.parsers.FormParser'>]
queryset
serializer_class

alias of enterprise.api.v1.serializers.EnterpriseCustomerBrandingConfigurationSerializer

suffix = None
update_branding(request, enterprise_uuid)

PATCH /enterprise/api/v1/enterprise-customer-branding/update_branding/uuid

Requires enterprise customer uuid path parameter

class enterprise.api.v1.views.EnterpriseCustomerCatalogViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadOnlyModelViewSet

API Views for performing search through course discovery at the enterprise_catalogs API endpoint.

FIELDS = ('uuid', 'enterprise_customer')
USER_ID_FILTER = 'enterprise_customer__enterprise_customer_users__user_id'
basename = None
contains_content_items(request, pk, course_run_ids, program_uuids)

Return whether or not the EnterpriseCustomerCatalog contains the specified content.

Multiple course_run_ids and/or program_uuids query parameters can be sent to this view to check for their existence in the EnterpriseCustomerCatalog. At least one course run key or program UUID value must be included in the request.

course_detail(request, pk, course_key)

Return the metadata for the specified course.

The course needs to be included in the specified EnterpriseCustomerCatalog in order for metadata to be returned from this endpoint.

course_run_detail(request, pk, course_id)

Return the metadata for the specified course run.

The course run needs to be included in the specified EnterpriseCustomerCatalog in order for metadata to be returned from this endpoint.

description = None
detail = None
filterset_fields = ('uuid', 'enterprise_customer')
get_serializer_class()

Return the class to use for the serializer. Defaults to using self.serializer_class.

You may want to override this if you need to provide different serializations depending on the incoming request.

(Eg. admins get full serialization, others get basic serialization)

list(request, *args, **kwargs)
name = None
ordering_fields = ('uuid', 'enterprise_customer')
program_detail(request, pk, program_uuid)

Return the metadata for the specified program.

The program needs to be included in the specified EnterpriseCustomerCatalog in order for metadata to be returned from this endpoint.

queryset
renderer_classes = (<class 'rest_framework.renderers.JSONRenderer'>, <class 'rest_framework_xml.renderers.XMLRenderer'>)
retrieve(request, *args, **kwargs)
suffix = None
class enterprise.api.v1.views.EnterpriseCustomerInviteKeyViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API for accessing enterprise customer keys.

authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>)
basename = None
basic_list(request, *args, **kwargs)

Unpaginated list of all invite keys matching the filters.

create(request, *args, **kwargs)
description = None
destroy(request, *args, **kwargs)
detail = None
filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'enterprise.api.filters.EnterpriseCustomerInviteKeyFilterBackend'>)
get_serializer_class()

Use a special serializer for any requests that aren’t read-only.

http_method_names = ['get', 'post', 'patch']

Post Links user using enterprise_customer_key /enterprise/api/enterprise-customer-invite-key/{enterprise_customer_key}/link-user

Given a enterprise_customer_key, link user to the appropriate enterprise.

If the key is not found, returns 404 If the key is not valid, returns 422 If we create an EnterpriseCustomerUser returns 201 If an EnterpriseCustomerUser if found returns 200

list(request, *args, **kwargs)
name = None
partial_update(request, *args, **kwargs)
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
queryset
retrieve(request, *args, **kwargs)
suffix = None
class enterprise.api.v1.views.EnterpriseCustomerReportTypesView(**kwargs)

Bases: rest_framework.views.APIView

API for getting the report types associated with an enterprise customer

authentication_classes = [<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>]
get(request, enterprise_uuid)

Get the dropdown choices for EnterpriseCustomerReportingConfiguration

http_method_names = ['get']
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
class enterprise.api.v1.views.EnterpriseCustomerReportingConfigurationViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API views for the enterprise-customer-reporting API endpoint.

FIELDS = ('enterprise_customer',)
USER_ID_FILTER = 'enterprise_customer__enterprise_customer_users__user_id'
basename = None
create(request, *args, **kwargs)
description = None
destroy(request, *args, **kwargs)
detail = None
filterset_fields = ('enterprise_customer',)
list(request, *args, **kwargs)
lookup_field = 'uuid'
name = None
ordering_fields = ('enterprise_customer',)
partial_update(request, *args, **kwargs)
permission_classes = [<class 'rest_framework.permissions.IsAuthenticated'>]
queryset
retrieve(request, *args, **kwargs)
serializer_class

alias of enterprise.api.v1.serializers.EnterpriseCustomerReportingConfigurationSerializer

suffix = None
update(request, *args, **kwargs)
class enterprise.api.v1.views.EnterpriseCustomerUserViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API views for the enterprise-learner API endpoint.

FIELDS = ('enterprise_customer', 'user_id', 'active')
basename = None
description = None
detail = None
filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'enterprise.api.filters.EnterpriseCustomerUserFilterBackend'>)
filterset_fields = ('enterprise_customer', 'user_id', 'active')
get_serializer_class()

Use a flat serializer for any requests that aren’t read-only.

name = None
ordering_fields = ('enterprise_customer', 'user_id', 'active')
queryset
suffix = None
class enterprise.api.v1.views.EnterpriseCustomerViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API views for the enterprise-customer API endpoint.

FIELDS = ('uuid', 'slug', 'name', 'active', 'site', 'enable_data_sharing_consent', 'enforce_data_sharing_consent')
USER_ID_FILTER = 'enterprise_customer_users__user_id'
basename = None
basic_list(request, *arg, **kwargs)

Enterprise Customer’s Basic data list without pagination

contains_content_items(request, pk, course_run_ids, program_uuids)

Return whether or not the specified content is available to the EnterpriseCustomer.

Multiple course_run_ids and/or program_uuids query parameters can be sent to this view to check for their existence in the EnterpriseCustomerCatalogs associated with this EnterpriseCustomer. At least one course run key or program UUID value must be included in the request.

course_enrollments(request, pk)

Creates a course enrollment for an EnterpriseCustomerUser.

dashboard_list(request, *args, **kwargs)

Supports listing dashboard enterprises for frontend-app-admin-portal.

description = None
detail = None
enroll_learners_in_courses(request, pk)

Creates a set of licensed enterprise_learners by bulk enrolling them in all specified courses. This endpoint is not transactional, in that any one or more failures will not affect other successful enrollments made within the same request.

Parameters
  • licenses_info (list of dicts) –

    an array of dictionaries, each containing the necessary information to create a licenced enrollment for a user in a specified course. Each dictionary must contain a user email, a course run key, and a UUID of the license that the learner is using to enroll with.

    Example:

    licenses_info: [
        {
            'email': 'newuser@test.com',
            'course_run_key': 'course-v1:edX+DemoX+Demo_Course',
            'license_uuid': '5b77bdbade7b4fcb838f8111b68e18ae',
        },
        ...
    ]
    

  • discount (int) – the percent discount to be applied to all enrollments. Defaults to 100.

Returns

  • All users exist and are enrolled -

    {‘successes’: [], ‘pending’: [], ‘failures’: []}, 201

  • Some or none of the users exist but are enrolled -

    {‘successes’: [], ‘pending’: [], ‘failures’: []}, 202

Failure cases:
  • Some or all of the users can’t be enrolled, no users were enrolled -

    {‘successes’: [], ‘pending’: [], ‘failures’: []}, 409

  • Some or all of the provided emails are invalid

    {‘successes’: [], ‘pending’: [], ‘failures’: [] ‘invalid_email_addresses’: []}, 409

Return type

Success cases

filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'enterprise.api.filters.UserFilterBackend'>, <class 'enterprise.api.filters.EnterpriseLinkedUserFilterBackend'>)
filterset_fields = ('uuid', 'slug', 'name', 'active', 'site', 'enable_data_sharing_consent', 'enforce_data_sharing_consent')
get_permissions()

Instantiates and returns the list of permissions that this view requires.

get_serializer_class()

Return the class to use for the serializer. Defaults to using self.serializer_class.

You may want to override this if you need to provide different serializations depending on the incoming request.

(Eg. admins get full serialization, others get basic serialization)

name = None
ordering_fields = ('uuid', 'slug', 'name', 'active', 'site', 'enable_data_sharing_consent', 'enforce_data_sharing_consent')
partial_update(request, *args, **kwargs)
queryset
serializer_class

alias of enterprise.api.v1.serializers.EnterpriseCustomerSerializer

suffix = None

Enables/Disables universal link config.

Unlinks users with the given emails from the enterprise.

with_access_to(request, *args, **kwargs)

Returns the list of enterprise customers the user has a specified group permission access to.

class enterprise.api.v1.views.EnterpriseModelViewSet

Bases: enterprise.api.v1.views.EnterpriseViewSet

Base class for attribute and method definitions common to all view sets.

USER_ID_FILTER = 'id'
filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>, <class 'enterprise.api.filters.UserFilterBackend'>)
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'rest_framework.permissions.DjangoModelPermissions'>)
class enterprise.api.v1.views.EnterpriseReadOnlyModelViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseModelViewSet, rest_framework.viewsets.ReadOnlyModelViewSet

Base class for all read only Enterprise model view sets.

class enterprise.api.v1.views.EnterpriseReadWriteModelViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseModelViewSet, rest_framework.viewsets.ModelViewSet

Base class for all read/write Enterprise model view sets.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'rest_framework.permissions.DjangoModelPermissions'>)
class enterprise.api.v1.views.EnterpriseViewSet

Bases: object

Base class for all Enterprise view sets.

authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>)
ensure_data_exists(request, data, error_message=None)

Ensure that the wrapped API client’s response brings us valid data. If not, raise an error and log it.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
throttle_classes = (<class 'enterprise.api.throttles.ServiceUserThrottle'>,)
class enterprise.api.v1.views.EnterpriseWrapperApiViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseViewSet, rest_framework.viewsets.ViewSet

Base class for attribute and method definitions common to all view sets which wrap external APIs.

class enterprise.api.v1.views.LicensedEnterpriseCourseEnrollmentViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseWrapperApiViewSet

API views for the licensed-enterprise-course-enrollment API endpoint.

class EnrollmentTerminationStatus

Bases: object

Defines statuses related to enrollment states during the course unenrollment process.

COURSE_COMPLETED = 'course already completed'
MOVED_TO_AUDIT = 'moved to audit'
UNENROLLED = 'unenrolled'
UNENROLL_FAILED = 'unenroll_user_from_course returned false.'
OPT_IGNORE_ENROLLMENTS_MODIFIED_AFTER_PARAM = 'ignore_enrollments_modified_after'
REQ_EXP_LICENSE_UUIDS_PARAM = 'expired_license_uuids'
basename = None
bulk_licensed_enrollments_expiration(request)

Changes the mode for licensed enterprise course enrollments to the “audit” course mode, or unenroll the user if no audit mode exists for each expired license uuid

Parameters
  • expired_license_uuids – The expired license uuids.

  • ignore_enrollments_modified_after – All course enrollments modified past this given date will be ignored, i.e. the enterprise subscription plan expiration date.

description = None
detail = None
license_revoke(request, *args, **kwargs)

Changes the mode for a user’s licensed enterprise course enrollments to the “audit” course mode, or unenroll the user if no audit mode exists for a given course.

Will return a response with status 200 if no errors were encountered while modifying the course enrollment, or a 422 if any errors were encountered. The content of the response is of the form:

{
    'course-v1:puppies': {'success': true, 'message': 'unenrolled'},
    'course-v1:birds': {'success': true, 'message': 'moved to audit'},
    'course-v1:kittens': {'success': true, 'message': 'course already completed'},
    'course-v1:snakes': {'success': false, 'message': 'unenroll_user_from_course returned false'},
    'course-v1:lizards': {'success': false, 'message': 'Some other exception'},
}

The first four messages are the values of constants that a client may expect to receive and parse accordingly.

name = None
queryset
serializer_class

alias of enterprise.api.v1.serializers.LicensedEnterpriseCourseEnrollmentReadOnlySerializer

suffix = None
class enterprise.api.v1.views.NotificationReadView(**kwargs)

Bases: rest_framework.views.APIView

API to mark notifications as read.

MISSING_REQUIRED_PARAMS_MSG = 'Some required parameter(s) missing: {}'
REQUIRED_PARAM_ENTERPRISE_SLUG = 'enterprise_slug'
REQUIRED_PARAM_NOTIFICATION_ID = 'notification_id'
authentication_classes = (<class 'edx_rest_framework_extensions.auth.jwt.authentication.JwtAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>)
get_missing_params_message(parameter_state)

Get a user-friendly message indicating a missing parameter for the API endpoint.

get_required_query_params(request)

Gets notification_id and enterprise_slug. which are the relevant parameters for this API endpoint.

Parameters

request – The request to this endpoint.

Returns

The notification_id and enterprise_slug from the request.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
post(request)

POST /enterprise/api/v1/read_notification

Requires a JSON object of the following format:

{
    'notification_id': 1,
    'enterprise_slug': 'enterprise_slug',
}
Keys
  • notification_id – Notification ID which is read by Current User.

  • enterprise_slug – The slug of the enterprise.

throttle_classes = (<class 'enterprise.api.throttles.ServiceUserThrottle'>,)
class enterprise.api.v1.views.PendingEnterpriseCustomerUserEnterpriseAdminViewSet(**kwargs)

Bases: enterprise.api.v1.views.PendingEnterpriseCustomerUserViewSet

Viewset for allowing enterpise admins to create linked learners Endpoint url: link_pending_enterprise_users/(?P<enterprise_uuid>[A-Za-z0-9-]+)/?$ Admin must be an administrator for the enterprise in question

basename = None
description = None
detail = None

Creates a PendingEnterpriseCustomerUser if no EnterpriseCustomerUser for the given (customer, email) combination(s) exists. Can accept one user or a list of users.

Returns 201 if any users were created, 204 if no users were created.

name = None
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)
serializer_class

alias of enterprise.api.v1.serializers.LinkLearnersSerializer

suffix = None
class enterprise.api.v1.views.PendingEnterpriseCustomerUserViewSet(**kwargs)

Bases: enterprise.api.v1.views.EnterpriseReadWriteModelViewSet

API views for the pending-enterprise-learner API endpoint. Requires staff permissions

FIELDS = ('enterprise_customer', 'user_email')
UNIQUE = 'unique'
USER_EXISTS_ERROR = 'EnterpriseCustomerUser record already exists'
basename = None
create(request, *args, **kwargs)

Creates a PendingEnterpriseCustomerUser if no EnterpriseCustomerUser for the given (customer, email) combination(s) exists. Can accept one user or a list of users.

Returns 201 if any users were created, 204 if no users were created.

description = None
detail = None
filter_backends = (<class 'rest_framework.filters.OrderingFilter'>, <class 'django_filters.rest_framework.backends.DjangoFilterBackend'>)
filterset_fields = ('enterprise_customer', 'user_email')
name = None
ordering_fields = ('enterprise_customer', 'user_email')
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'rest_framework.permissions.IsAdminUser'>)
queryset
serializer_class

alias of enterprise.api.v1.serializers.PendingEnterpriseCustomerUserSerializer

suffix = None
class enterprise.api.v1.views.TableauAuthView(**kwargs)

Bases: rest_framework.generics.GenericAPIView

API to authenticate user with Tableau.

get(request, enterprise_uuid)

Get the auth token against logged in user from tableau

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)

Module contents

API endpoint for enterprise app.