openedx.features.enterprise_support package

Contents

openedx.features.enterprise_support package#

Subpackages#

Submodules#

openedx.features.enterprise_support.api module#

APIs providing support for enterprise functionality.

class openedx.features.enterprise_support.api.ConsentApiClient(user)#

Bases: object

Class for producing an Enterprise Consent service API client

consent_required(enrollment_exists=False, **kwargs)#

Determine if consent is required at the given scope.

This endpoint takes any given kwargs, which are understood as filtering the conceptual scope of the consent involved in the request.

Provide consent at the given scope.

This endpoint takes any given kwargs, which are understood as filtering the conceptual scope of the consent involved in the request.

Revoke consent from any existing records that have it at the given scope.

This endpoint takes any given kwargs, which are understood as filtering the conceptual scope of the consent involved in the request.

class openedx.features.enterprise_support.api.ConsentApiServiceClient#

Bases: EnterpriseServiceClientMixin, ConsentApiClient

Class for producing an Enterprise Consent API client with service user.

class openedx.features.enterprise_support.api.EnterpriseApiClient(user)#

Bases: object

Class for producing an Enterprise service API client.

fetch_enterprise_learner_data(user)#

Fetch information related to enterprise from the Enterprise Service.

Example

fetch_enterprise_learner_data(user)

Argument:

user: (User) django auth user

Returns:

{

“count”: 1, “num_pages”: 1, “current_page”: 1, “next”: null, “start”: 0, “previous”: null “results”: [

{
“enterprise_customer”: {

“uuid”: “cf246b88-d5f6-4908-a522-fc307e0b0c59”, “name”: “TestShib”, “active”: true, “site”: {

”domain”: “example.com”, “name”: “example.com”

}, “enable_data_sharing_consent”: true, “enforce_data_sharing_consent”: “at_login”, “branding_configuration”: {

”enterprise_customer”: “cf246b88-d5f6-4908-a522-fc307e0b0c59”, “logo”: “https://open.edx.org/sites/all/themes/edx_open/logo.png

}, “enterprise_customer_entitlements”: [

{

“enterprise_customer”: “cf246b88-d5f6-4908-a522-fc307e0b0c59”, “entitlement_id”: 69

}

], “replace_sensitive_sso_username”: False,

}, “user_id”: 5, “user”: {

”username”: “staff”, “first_name”: “”, “last_name”: “”, “email”: “staff@example.com”, “is_staff”: true, “is_active”: true, “date_joined”: “2016-09-01T19:18:26.026495Z”

}, “data_sharing_consent_records”: [

{

“username”: “staff”, “enterprise_customer_uuid”: “cf246b88-d5f6-4908-a522-fc307e0b0c59”, “exists”: true, “course_id”: “course-v1:edX DemoX Demo_Course”, “consent_provided”: true, “consent_required”: false

}

]

}

],

}

Return type:

dict

get_enterprise_customer(uuid)#
post_enterprise_course_enrollment(username, course_id)#

Create an EnterpriseCourseEnrollment by using the corresponding serializer (for validation).

exception openedx.features.enterprise_support.api.EnterpriseApiException#

Bases: Exception

Exception for errors while communicating with the Enterprise service API.

class openedx.features.enterprise_support.api.EnterpriseApiServiceClient#

Bases: EnterpriseServiceClientMixin, EnterpriseApiClient

Class for producing an Enterprise service API client with service user.

get_enterprise_customer(uuid)#

Fetch enterprise customer with enterprise service user and cache the API response`.

class openedx.features.enterprise_support.api.EnterpriseServiceClientMixin#

Bases: object

Class for initializing an Enterprise API clients with service user.

openedx.features.enterprise_support.api.activate_learner_enterprise(request, user, enterprise_customer)#

Allow an enterprise learner to activate one of learner’s linked enterprises.

openedx.features.enterprise_support.api.add_enterprise_customer_to_session(request, enterprise_customer)#

Add the given enterprise_customer data to the request’s session if user is authenticated.

openedx.features.enterprise_support.api.cache_enterprise(enterprise_customer)#

Add this customer’s data to the Django cache.

openedx.features.enterprise_support.api.consent_needed_for_course(*args, **kwargs)#

Decorator which makes a view method redirect to the Data Sharing Consent form if:

  • The wrapped method is passed request, course_id as the first two arguments.

  • Enterprise integration is enabled

  • Data sharing consent is required before accessing this course view.

  • The request.user has not yet given data sharing consent for this course.

After granting consent, the user will be redirected back to the original request.path.

openedx.features.enterprise_support.api.enterprise_customer_for_request(*args, **kwargs)#
openedx.features.enterprise_support.api.enterprise_customer_from_api(*args, **kwargs)#
openedx.features.enterprise_support.api.enterprise_customer_from_cache(uuid)#

Retrieve enterprise customer data associated with the given uuid from the Django cache, returning a __CACHE_MISS__ if absent.

openedx.features.enterprise_support.api.enterprise_customer_from_session(request)#

Retrieve enterprise_customer data from the request’s session, returning a __CACHE_MISS__ if absent.

Now checks for session existence before attempting to access it.

openedx.features.enterprise_support.api.enterprise_customer_from_session_or_learner_data(*args, **kwargs)#
openedx.features.enterprise_support.api.enterprise_customer_uuid_for_request(*args, **kwargs)#

Returns an enterprise customer UUID from the given request’s cookies, or __CACHE_MISS__ if not present.

openedx.features.enterprise_support.api.enterprise_customer_uuid_from_query_param(request)#

Returns an enterprise customer UUID from the given request’s GET data, or __CACHE_MISS__ if not present.

openedx.features.enterprise_support.api.enterprise_customer_uuid_from_session(request)#

Retrieve an enterprise customer UUID from the request’s session, returning a __CACHE_MISS__ if absent. Note that this may return None, which indicates that we’ve previously looked for an associated customer for this request’s user, and none was present.

openedx.features.enterprise_support.api.enterprise_enabled()#

Determines whether the Enterprise app is installed

openedx.features.enterprise_support.api.enterprise_is_enabled(otherwise=None)#

Decorator which requires that the Enterprise feature be enabled before the function can run.

openedx.features.enterprise_support.api.get_active_enterprise_customer_user(*args, **kwargs)#
openedx.features.enterprise_support.api.get_data_sharing_consents(*args, **kwargs)#
openedx.features.enterprise_support.api.get_enterprise_course_enrollments(*args, **kwargs)#
openedx.features.enterprise_support.api.get_enterprise_customer_cache_key(uuid, username='enterprise_worker')#

The cache key used to get cached Enterprise Customer data.

openedx.features.enterprise_support.api.get_enterprise_learner_data_from_api(*args, **kwargs)#
openedx.features.enterprise_support.api.get_enterprise_learner_data_from_db(*args, **kwargs)#
openedx.features.enterprise_support.api.get_enterprise_learner_portal_context(*args, **kwargs)#
openedx.features.enterprise_support.api.get_enterprise_learner_portal_enabled_message(*args, **kwargs)#

openedx.features.enterprise_support.apps module#

Configuration for enterprise_support

class openedx.features.enterprise_support.apps.EnterpriseSupportConfig(app_name, app_module)#

Bases: AppConfig

Configuration class for enterprise_support

name = 'openedx.features.enterprise_support'#
ready()#

Override this method in subclasses to run code when Django starts.

openedx.features.enterprise_support.context module#

APIs providing enterprise context for events.

openedx.features.enterprise_support.context.get_enterprise_event_context(user_id, course_id)#

Creates an enterprise context from a course_id anf user_id. Example Returned Context:

{
    'enterprise_uuid': '1a0fbcbe-49e5-42f1-8e83-4cddfa592f22'
}
Parameters:
  • user_id – id of user object.

  • course_id – id of course object.

Returns:

A dictionary representing the enterprise uuid.

Return type:

dict

openedx.features.enterprise_support.serializers module#

Defines serializers for enterprise_support.

class openedx.features.enterprise_support.serializers.EnterpriseCourseEnrollmentSerializer(*args, **kwargs)#

Bases: EnterpriseCourseEnrollmentReadOnlySerializer

Serializer for EnterpriseCourseEnrollment model.

class Meta#

Bases: object

fields = ('course_id', 'enterprise_customer_name', 'enterprise_customer_user_id', 'license', 'saved_for_later')#
model#

alias of EnterpriseCourseEnrollment

get_enterprise_customer_name(obj)#
get_license(obj)#

openedx.features.enterprise_support.signals module#

This module contains signals related to enterprise.

openedx.features.enterprise_support.signals.handle_enterprise_learner_passing_grade(sender, user, course_id, **kwargs)#

Listen for a learner passing a course, transmit data to relevant integrated channel

openedx.features.enterprise_support.signals.handle_enterprise_learner_subsection(sender, user, course_id, subsection_id, subsection_grade, **kwargs)#

Listen for an enterprise learner completing a subsection, transmit data to relevant integrated channel.

openedx.features.enterprise_support.signals.refund_order_voucher(sender, course_enrollment, skip_refund=False, **kwargs)#

Call the /api/v2/enterprise/coupons/create_refunded_voucher/ API to create new voucher and assign it to user.

openedx.features.enterprise_support.signals.update_dsc_cache_on_course_enrollment(sender, instance, **kwargs)#

clears data_sharing_consent_needed cache after Enterprise Course Enrollment

openedx.features.enterprise_support.signals.update_dsc_cache_on_enterprise_customer_update(sender, instance, **kwargs)#

clears data_sharing_consent_needed cache after enable_data_sharing_consent flag is changed.

openedx.features.enterprise_support.tasks module#

Tasks for Enterprise.

openedx.features.enterprise_support.utils module#

Utility methods for Enterprise

clears data_sharing_consent_needed cache

openedx.features.enterprise_support.utils.enterprise_branding_configuration(enterprise_customer_obj)#

Given an instance of EnterpriseCustomer, returns a related branding_configuration serialized dictionary if it exists, otherwise the serialized default EnterpriseCustomerBrandingConfiguration object.

EnterpriseCustomerBrandingConfigurationSerializer will use default values for any empty branding config fields.

openedx.features.enterprise_support.utils.enterprise_fields_only(fields)#

Take the received field definition, and exclude those fields that we don’t want to require if the user is going to be a member of an Enterprise Customer.

openedx.features.enterprise_support.utils.fetch_enterprise_customer_by_id(enterprise_uuid)#

Returns cache key for data sharing consent needed against user_id, course_id and enterprise_customer_uuid

openedx.features.enterprise_support.utils.get_enterprise_learner_generic_name(request)#

Get a generic name concatenating the Enterprise Customer name and ‘Learner’.

ENT-924: Temporary solution for hiding potentially sensitive SSO names. When a more complete solution is put in place, delete this function and all of its uses.

openedx.features.enterprise_support.utils.get_enterprise_learner_portal(request)#

Gets the formatted portal name and slug that can be used to generate a link for an enabled enterprise Learner Portal.

Caches and returns result in/from the user’s request session if provided.

openedx.features.enterprise_support.utils.get_enterprise_readonly_account_fields(user)#

Returns a set of account fields that are read-only for enterprise users.

openedx.features.enterprise_support.utils.get_enterprise_sidebar_context(enterprise_customer, is_proxy_login)#

Get context information for enterprise sidebar for the given enterprise customer.

Parameters:
  • enterprise_customer (dict) – customer data from enterprise-customer endpoint, cached

  • is_proxy_login (bool) – If True, use proxy login welcome template

Returns: Enterprise Sidebar Context with the following key-value pairs. {

‘enterprise_name’: ‘Enterprise Name’, ‘enterprise_logo_url’: ‘URL of the enterprise logo image’, ‘enterprise_branded_welcome_string’: ‘Human readable welcome message customized for the enterprise’, ‘platform_welcome_string’: ‘Human readable welcome message for an enterprise learner’,

}

openedx.features.enterprise_support.utils.get_enterprise_slug_login_url()#

Return the enterprise slug login’s URL (enterprise/login) if it exists otherwise None

openedx.features.enterprise_support.utils.get_is_enterprise_cache_key(user_id)#

Returns cache key for the enterprise learner validation method needed against user_id.

openedx.features.enterprise_support.utils.get_provider_login_url(request, provider_id, redirect_url=None)#

Return the given provider’s login URL.

This method is here to avoid the importing of pipeline and student app in enterprise.

openedx.features.enterprise_support.utils.handle_enterprise_cookies_for_logistration(request, response, context)#

Helper method for setting or deleting enterprise cookies on logistration response.

Parameters:
  • request (HttpRequest) – The request for the logistration page.

  • response (HttpResponse) – The response for the logistration page.

  • context (dict) – Context for logistration page.

openedx.features.enterprise_support.utils.is_course_accessed(user, course_id)#

Check if the learner accessed the course.

Parameters:
  • user (User) – Django User object.

  • course_id (String) – The course identifier

Returns:

True if course has been accessed by the enterprise learner.

Return type:

(bool)

openedx.features.enterprise_support.utils.is_enterprise_learner(user)#

Check if the given user belongs to an enterprise. Cache the value if an enterprise learner is found.

Parameters:

user (User) – Django User object or Django User object id.

Returns:

True if given user is an enterprise learner.

Return type:

(bool)

openedx.features.enterprise_support.utils.update_account_settings_context_for_enterprise(context, enterprise_customer, user)#

Take processed context for account settings page and update it taking enterprise customer into account.

Arguments:

context (dict): Context for account settings page. enterprise_customer (dict): data for enterprise customer user (User): request user

openedx.features.enterprise_support.utils.update_logistration_context_for_enterprise(request, context, enterprise_customer)#

Take the processed context produced by the view, determine if it’s relevant to a particular Enterprise Customer, and update it to include that customer’s enterprise metadata.

Arguments:

request (HttpRequest): The request for the logistration page. context (dict): Context for logistration page. enterprise_customer (dict): data for enterprise customer

openedx.features.enterprise_support.utils.update_third_party_auth_context_for_enterprise(request, context, enterprise_customer=None)#

Return updated context of third party auth with modified data for the given enterprise customer.

Parameters:
  • request (HttpRequest) – The request for the logistration page.

  • context (dict) – Context for third party auth providers and auth pipeline.

  • enterprise_customer (dict) – data for enterprise customer

Returns:

Updated context of third party auth with modified errorMessage.

Return type:

context (dict)

Module contents#