Skip to content

Commit

Permalink
feat: add integration channel code to enterprise customer serializer (#…
Browse files Browse the repository at this point in the history
…2078)

* feat: add integration channel code to enterprise customer serializer

* fix: update test

* fix: linter
  • Loading branch information
katrinan029 authored Apr 23, 2024
1 parent aee4934 commit eafafa2
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.15.12]
---------
* feat: update enterprise customer serializer to include active integration codes

[4.15.11]
---------
* fix: support `force_enrollment` in serializers used by bulk enrollment (ENT-8788)
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.15.11"
__version__ = "4.15.12"
7 changes: 6 additions & 1 deletion enterprise/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from enterprise.utils import (
CourseEnrollmentDowngradeError,
CourseEnrollmentPermissionError,
get_integrations_for_customers,
get_last_course_run_end_date,
has_course_run_available_for_enrollment,
track_enrollment,
Expand Down Expand Up @@ -223,7 +224,7 @@ class Meta:
'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',
'enable_one_academy', 'active_integrations',
)

identity_providers = EnterpriseCustomerIdentityProviderSerializer(many=True, read_only=True)
Expand All @@ -232,6 +233,10 @@ class Meta:
enterprise_customer_catalogs = serializers.SerializerMethodField()
enterprise_notification_banner = serializers.SerializerMethodField()
admin_users = serializers.SerializerMethodField()
active_integrations = serializers.SerializerMethodField()

def get_active_integrations(self, obj):
return get_integrations_for_customers(obj.uuid)

def get_branding_configuration(self, obj):
"""
Expand Down
48 changes: 48 additions & 0 deletions enterprise/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import os
import re
from collections import OrderedDict
from urllib.parse import parse_qs, quote, urlencode, urljoin, urlparse, urlsplit, urlunsplit
from uuid import UUID, uuid4

Expand Down Expand Up @@ -2417,3 +2418,50 @@ def convert_to_snake(string):
Helper method to convert strings to snake case.
"""
return re.sub(r'(?<!^)(?=[A-Z])', '_', string).lower()


def get_integrated_channel_choices():
"""
Helper method to return channel code for each integrated channel.
"""
BlackboardEnterpriseCustomerConfiguration = apps.get_model(
'blackboard', 'BlackboardEnterpriseCustomerConfiguration')
CanvasEnterpriseCustomerConfiguration = apps.get_model(
'canvas', 'CanvasEnterpriseCustomerConfiguration')
CornerstoneEnterpriseCustomerConfiguration = apps.get_model(
'cornerstone', 'CornerstoneEnterpriseCustomerConfiguration')
Degreed2EnterpriseCustomerConfiguration = apps.get_model(
'degreed2', 'Degreed2EnterpriseCustomerConfiguration')
MoodleEnterpriseCustomerConfiguration = apps.get_model(
'moodle', 'MoodleEnterpriseCustomerConfiguration')
SAPSuccessFactorsEnterpriseCustomerConfiguration = apps.get_model(
'sap_success_factors', 'SAPSuccessFactorsEnterpriseCustomerConfiguration')

return OrderedDict([
(integrated_channel_class.channel_code(), integrated_channel_class)
for integrated_channel_class in (
BlackboardEnterpriseCustomerConfiguration,
CanvasEnterpriseCustomerConfiguration,
CornerstoneEnterpriseCustomerConfiguration,
Degreed2EnterpriseCustomerConfiguration,
MoodleEnterpriseCustomerConfiguration,
SAPSuccessFactorsEnterpriseCustomerConfiguration,
)
])


def get_integrations_for_customers(customer_uuid):
"""
Helper method to return channel code for each enterprise customer with active integrations.
Arguments:
customer_uuid (UUI): uuid of an enterprise customer
Returns:
list: a list of integration channel codes.
"""
unique_integrations = []
integrated_channel_choices = get_integrated_channel_choices()
for code, choice in integrated_channel_choices.items():
if choice.objects.filter(enterprise_customer__uuid=customer_uuid, active=True):
unique_integrations.append(code)
return unique_integrations
80 changes: 80 additions & 0 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ class TestEnterpriseCustomerViewSet(BaseTestEnterpriseAPIViews):
'enable_demo_data_for_analytics_and_lpr': False,
'enable_academies': False,
'enable_one_academy': False,
'active_integrations': [],
}],
),
(
Expand Down Expand Up @@ -1289,6 +1290,7 @@ class TestEnterpriseCustomerViewSet(BaseTestEnterpriseAPIViews):
'enable_demo_data_for_analytics_and_lpr': False,
'enable_academies': False,
'enable_one_academy': False,
'active_integrations': [],
},
'enterprise_group': [],
'active': True, 'user_id': 0, 'user': None,
Expand Down Expand Up @@ -1387,6 +1389,7 @@ class TestEnterpriseCustomerViewSet(BaseTestEnterpriseAPIViews):
'enable_demo_data_for_analytics_and_lpr': False,
'enable_academies': False,
'enable_one_academy': False,
'active_integrations': [],
}],
),
(
Expand Down Expand Up @@ -1455,6 +1458,7 @@ class TestEnterpriseCustomerViewSet(BaseTestEnterpriseAPIViews):
'enable_demo_data_for_analytics_and_lpr': False,
'enable_academies': False,
'enable_one_academy': False,
'active_integrations': [],
}],
),
(
Expand All @@ -1478,6 +1482,81 @@ class TestEnterpriseCustomerViewSet(BaseTestEnterpriseAPIViews):
'tertiary_color': '#888888',
}],
),
(
factories.BlackboardEnterpriseCustomerConfigurationFactory,
ENTERPRISE_CUSTOMER_LIST_ENDPOINT,
itemgetter('uuid'),
[{
'id': 1,
'enterprise_customer_id': FAKE_UUIDS[0],
'enterprise_customer__uuid': FAKE_UUIDS[0],
'blackboard_base_url': 'foobar',
'client_id': 'client_id',
'client_secret': 'client_secret',
'refresh_token': 'token',
'active': True,
'enterprise_customer__name': 'Test Enterprise Customer',
'enterprise_customer__slug': TEST_SLUG,
'enterprise_customer__active': True,
'enterprise_customer__enable_data_sharing_consent': True,
'enterprise_customer__enforce_data_sharing_consent': 'at_enrollment',
'enterprise_customer__site__domain': 'example.com',
'enterprise_customer__site__name': 'example.com',
'enterprise_customer__contact_email': 'fake@example.com',
'enterprise_customer__sender_alias': 'Test Sender Alias',
'enterprise_customer__reply_to': 'fake_reply@example.com',
'enterprise_customer__hide_labor_market_data': False,
'enterprise_customer__modified': '2021-10-20T19:01:31Z',
'enterprise_customer__auth_org_id': 'asdf3e2wdas',
}],
[{
'uuid': FAKE_UUIDS[0], 'name': 'Test Enterprise Customer',
'slug': TEST_SLUG, 'active': True,
'auth_org_id': 'asdf3e2wdas',
'site': {
'domain': 'example.com', 'name': 'example.com'
},
'enable_data_sharing_consent': True,
'enforce_data_sharing_consent': 'at_enrollment',
'branding_configuration': get_default_branding_object(FAKE_UUIDS[0], TEST_SLUG),
'identity_provider': None,
'enable_audit_enrollment': False,
'replace_sensitive_sso_username': False, 'enable_portal_code_management_screen': False,
'sync_learner_profile_data': False,
'enable_audit_data_reporting': False,
'enable_learner_portal': True,
'enable_learner_portal_offers': False,
'enable_portal_learner_credit_management_screen': False,
'enable_executive_education_2U_fulfillment': False,
'enable_portal_reporting_config_screen': False,
'enable_portal_saml_configuration_screen': False,
'contact_email': 'fake@example.com',
'enable_portal_subscription_management_screen': False,
'hide_course_original_price': False,
'enable_analytics_screen': True,
'enable_integrated_customer_learner_portal_search': True,
'enable_career_engagement_network_on_learner_portal': False,
'enable_portal_lms_configurations_screen': False,
'sender_alias': 'Test Sender Alias',
'identity_providers': [],
'enterprise_customer_catalogs': [],
'reply_to': 'fake_reply@example.com',
'enterprise_notification_banner': {'title': '', 'text': ''},
'hide_labor_market_data': False,
'modified': '2021-10-20T19:01:31Z',
'enable_universal_link': False,
'enable_browse_and_request': False,
'admin_users': [],
'enable_generation_of_api_credentials': False,
'career_engagement_network_message': 'Test message',
'enable_pathways': True,
'enable_programs': True,
'enable_demo_data_for_analytics_and_lpr': False,
'enable_academies': False,
'enable_one_academy': False,
'active_integrations': ['BLACKBOARD']
}],
),
)
@ddt.unpack
@mock.patch('enterprise.utils.get_logo_url')
Expand Down Expand Up @@ -1716,6 +1795,7 @@ def test_enterprise_customer_with_access_to(
'enable_demo_data_for_analytics_and_lpr': False,
'enable_academies': False,
'enable_one_academy': False,
'active_integrations': [],
}
else:
mock_empty_200_success_response = {
Expand Down

0 comments on commit eafafa2

Please sign in to comment.