enterprise.api.v1 package#

Subpackages#

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: 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: 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: ModelSerializer

Serializer for AdminNotification model.

class Meta#

Bases: object

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

alias of AdminNotification

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

Bases: Serializer

Serializer for the payload data of analytics summary endpoint.

class LearnerEngagementSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for the summary related data in the analytics summary endpoint.

class LearnerProgressSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for the learner progress data in the analytics summary endpoint.

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

Bases: 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 EnterpriseCustomerInviteKey

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

Bases: 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: 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.EnrollmentsInfoSerializer(*args, **kwargs)#

Bases: Serializer

Nested serializer class to allow for many license info dictionaries.

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

Bases: ModelSerializer

Serializer for the EnterpriseCatalogQuery model.

class Meta#

Bases: object

fields = '__all__'#
model#

alias of EnterpriseCatalogQuery

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

Bases: ModelSerializer

Serializer for EnterpriseCourseEnrollment model.

class Meta#

Bases: object

fields = ('enterprise_customer_user', 'course_id', 'unenrolled_at', 'created')#
model#

alias of EnterpriseCourseEnrollment

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

Bases: EnterpriseCourseEnrollmentReadOnlySerializer

Serializer for EnterpriseCourseEnrollment model with additional fields.

class Meta#

Bases: object

fields = ('enterprise_customer_user', 'course_id', 'created', 'unenrolled_at', 'enrollment_date', 'enrollment_track', 'user_email', 'course_start', 'course_end')#
model#

alias of EnterpriseCourseEnrollment

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

Bases: ModelSerializer

Serializer for writing to the EnterpriseCourseEnrollment model.

class Meta#

Bases: object

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

alias of 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.EnterpriseCustomerApiCredentialRegeneratePatchSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for the EnterpriseCustomerApiCredential

class Meta#

Bases: object

lookup_field = 'user'#
class enterprise.api.v1.serializers.EnterpriseCustomerApiCredentialSerializer(*args, **kwargs)#

Bases: Serializer

Serializer for the EnterpriseCustomerApiCredential

class Meta#

Bases: object

lookup_field = 'user'#
update(instance, validated_data)#
class enterprise.api.v1.serializers.EnterpriseCustomerBasicSerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializer for EnterpriseCustomer model only for name and id fields.

class Meta#

Bases: object

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

alias of EnterpriseCustomer

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

Bases: ModelSerializer

Serializer for EnterpriseCustomerBrandingConfiguration model.

class Meta#

Bases: object

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

alias of 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: 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: Serializer

Serializes a licenses info field for bulk enrollment requests.

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

Bases: 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: ModelSerializer

Serializer for the EnterpriseCustomerCatalog model.

class Meta#

Bases: object

fields = ('uuid', 'title', 'enterprise_customer', 'enterprise_catalog_query', 'created', 'modified')#
model#

alias of EnterpriseCustomerCatalog

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

Bases: EnterpriseCustomerCatalogSerializer

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

class Meta#

Bases: object

extra_kwargs = {'enterprise_catalog_query': {'required': False}, 'enterprise_customer': {'required': True}, 'title': {'required': True}, 'uuid': {'required': False}}#
fields = ('uuid', 'title', 'enterprise_customer', 'enterprise_catalog_query')#
model#

alias of EnterpriseCustomerCatalog

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

Bases: 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: 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 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: ModelSerializer

Serializer for EnterpriseCustomerIdentityProvider model.

class Meta#

Bases: object

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

alias of EnterpriseCustomerIdentityProvider

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

Bases: ModelSerializer

Serializer for updating the EnterpriseCustomerInviteKey model.

class Meta#

Bases: object

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

alias of EnterpriseCustomerInviteKey

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

Bases: BaseEnterpriseCustomerInviteKeySerializer

Serializer for reading the EnterpriseCustomerInviteKey model.

class Meta#

Bases: 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: 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: 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 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)#
validate_pgp_encryption_key(value)#

Validate that pgp_encryption_key is correctly set or left empty.

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

Bases: ModelSerializer

Serializer for EnterpriseCustomer model.

class Meta#

Bases: object

fields = ('uuid', 'name', 'slug', 'active', 'auth_org_id', '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_generation_of_api_credentials', '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', 'enable_career_engagement_network_on_learner_portal', 'career_engagement_network_message', 'enable_pathways', 'enable_programs', 'enable_demo_data_for_analytics_and_lpr', 'enable_academies', 'enable_one_academy', 'active_integrations')#
model#

alias of EnterpriseCustomer

get_active_integrations(obj)#
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.EnterpriseCustomerSsoConfiguration(*args, **kwargs)#

Bases: ModelSerializer

Serializer for the EnterpriseCustomerSsoConfiguration model.

class Meta#

Bases: object

fields = '__all__'#
model#

alias of EnterpriseCustomerSsoConfiguration

get_enterprise_customer(obj)#

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

get_is_pending_configuration(obj)#

Return whether the SSO configuration is pending configuration.

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

Bases: Serializer

Serializer for toggling an EnterpriseCustomer enable_universal_link field.

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

Bases: Serializer

Serializer for the EnterpriseCustomerViewSet unlink_users action.

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

Bases: 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', 'enterprise_group')#
model#

alias of 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_enterprise_group(obj)#

Return the enterprise group membership for this enterprise customer user.

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: ModelSerializer

Serializer for writing to the EnterpriseCustomerUser model.

class Meta#

Bases: object

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

alias of 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.EnterpriseGroupLearnersRequestQuerySerializer(*args, **kwargs)#

Bases: Serializer

Serializer for the Enterprise Group Learners endpoint query filter

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

Bases: ModelSerializer

Serializer for EnterpriseGroupMembership model.

class Meta#

Bases: object

fields = ('learner_id', 'pending_learner_id', 'enterprise_group_membership_uuid', 'member_details', 'recent_action', 'status')#
model#

alias of EnterpriseGroupMembership

get_member_details(obj)#

Return either the member’s name and email if it’s the case that the member is realized, otherwise just email

get_recent_action(obj)#

Return the timestamp and name of the most recent action associated with the membership.

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

Bases: Serializer

Serializer for the Enterprise Group Assign Learners endpoint query params

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

Bases: ModelSerializer

Serializer for EnterpriseGroup model.

class Meta#

Bases: object

fields = ('enterprise_customer', 'name', 'uuid', 'applies_to_all_contexts')#
model#

alias of EnterpriseGroup

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

Bases: 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.LearnerCreditEnterpriseCourseEnrollmentReadOnlySerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializer for LearnerCreditEnterpriseCourseEnrollment model.

class Meta#

Bases: object

fields = ('enterprise_course_enrollment', 'transaction_id', 'uuid')#
model#

alias of LearnerCreditEnterpriseCourseEnrollment

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

Bases: ModelSerializer

Serializer for LicensedEnterpriseCourseEnrollment model.

class Meta#

Bases: object

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

alias of LicensedEnterpriseCourseEnrollment

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

Bases: 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: ModelSerializer

Serializer for writing to the PendingEnterpriseCustomerUser model.

class Meta#

Bases: object

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

alias of 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: 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: ImmutableStateSerializer

Serializer for responses that require pagination.

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

Bases: Field

Custom Site field to facilitate with creation of parent objects, while also keeping output pretty.

When used in a ModelSerializer, the site field can be provided to the create() REST API endpoint as follows, which performs a lookup for a site with the domain “example.com”:

"site": {"domain": "example.com"}

Output serializations render sites with all Site fields.

to_internal_value(data)#

Transform the incoming primitive data into a native value.

to_representation(value)#

Transform the outgoing native value into primitive data.

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

Bases: ModelSerializer

Serializer for Site model.

class Meta#

Bases: object

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

alias of Site

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

Bases: 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 User

enterprise.api.v1.urls module#

URL definitions for enterprise api version 1 endpoint.

Module contents#

API endpoint for enterprise app.