diff --git a/enterprise_access/apps/api/v1/tests/test_bff_views.py b/enterprise_access/apps/api/v1/tests/test_bff_views.py index e0bbd917..9402ecca 100644 --- a/enterprise_access/apps/api/v1/tests/test_bff_views.py +++ b/enterprise_access/apps/api/v1/tests/test_bff_views.py @@ -183,7 +183,7 @@ def setUp(self): ) @ddt.unpack @mock_dashboard_dependencies - def test_dashboard_empty_state( + def test_dashboard_empty_state_with_permissions( self, mock_get_enterprise_customers_for_user, mock_get_subscription_licenses_for_learner, diff --git a/enterprise_access/apps/bffs/api.py b/enterprise_access/apps/bffs/api.py index d9a68ed5..5445b33f 100644 --- a/enterprise_access/apps/bffs/api.py +++ b/enterprise_access/apps/bffs/api.py @@ -25,16 +25,20 @@ def enterprise_customer_cache_key(enterprise_customer_slug, enterprise_customer_ return versioned_cache_key('enterprise_customer', enterprise_customer_slug, enterprise_customer_uuid) -def subscription_licenses_cache_key(enterprise_customer_uuid): - return versioned_cache_key('get_subscription_licenses_for_learner', enterprise_customer_uuid) +def subscription_licenses_cache_key(enterprise_customer_uuid, lms_user_id): + return versioned_cache_key('get_subscription_licenses_for_learner', enterprise_customer_uuid, lms_user_id) -def default_enterprise_enrollment_intentions_cache_key(enterprise_customer_uuid): - return versioned_cache_key('get_default_enterprise_enrollment_intentions', enterprise_customer_uuid) +def default_enterprise_enrollment_intentions_learner_status_cache_key(enterprise_customer_uuid, lms_user_id): + return versioned_cache_key( + 'get_default_enterprise_enrollment_intentions_learner_status', + enterprise_customer_uuid, + lms_user_id + ) -def enterprise_course_enrollments_cache_key(enterprise_customer_uuid): - return versioned_cache_key('get_enterprise_course_enrollments', enterprise_customer_uuid) +def enterprise_course_enrollments_cache_key(enterprise_customer_uuid, lms_user_id): + return versioned_cache_key('get_enterprise_course_enrollments', enterprise_customer_uuid, lms_user_id) def get_and_cache_enterprise_customer_users(request, timeout=settings.ENTERPRISE_USER_RECORD_CACHE_TIMEOUT, **kwargs): @@ -97,7 +101,7 @@ def get_and_cache_subscription_licenses_for_learner( """ Retrieves and caches subscription licenses for a learner. """ - cache_key = subscription_licenses_cache_key(enterprise_customer_uuid) + cache_key = subscription_licenses_cache_key(enterprise_customer_uuid, request.user.id) cached_response = TieredCache.get_cached_response(cache_key) if cached_response.is_found: logger.info( @@ -114,7 +118,7 @@ def get_and_cache_subscription_licenses_for_learner( return response_payload -def get_and_cache_default_enterprise_enrollment_intentions( +def get_and_cache_default_enterprise_enrollment_intentions_learner_status( request, enterprise_customer_uuid, timeout=settings.DEFAULT_ENTERPRISE_ENROLLMENT_INTENTIONS_CACHE_TIMEOUT, @@ -122,7 +126,10 @@ def get_and_cache_default_enterprise_enrollment_intentions( """ Retrieves and caches default enterprise enrollment intentions for a learner. """ - cache_key = default_enterprise_enrollment_intentions_cache_key(enterprise_customer_uuid) + cache_key = default_enterprise_enrollment_intentions_learner_status_cache_key( + enterprise_customer_uuid, + request.user.id, + ) cached_response = TieredCache.get_cached_response(cache_key) if cached_response.is_found: logger.info( @@ -148,7 +155,7 @@ def get_and_cache_enterprise_course_enrollments( """ Retrieves and caches enterprise course enrollments for a learner. """ - cache_key = enterprise_course_enrollments_cache_key(enterprise_customer_uuid) + cache_key = enterprise_course_enrollments_cache_key(enterprise_customer_uuid, request.user.id) cached_response = TieredCache.get_cached_response(cache_key) if cached_response.is_found: logger.info( @@ -165,27 +172,30 @@ def get_and_cache_enterprise_course_enrollments( return response_payload -def invalidate_default_enterprise_enrollment_intentions_cache(enterprise_customer_uuid): +def invalidate_default_enterprise_enrollment_intentions_learner_status_cache(enterprise_customer_uuid, lms_user_id): """ Invalidates the default enterprise enrollment intentions cache for a learner. """ - cache_key = default_enterprise_enrollment_intentions_cache_key(enterprise_customer_uuid) + cache_key = default_enterprise_enrollment_intentions_learner_status_cache_key( + enterprise_customer_uuid, + lms_user_id, + ) TieredCache.delete_all_tiers(cache_key) -def invalidate_enterprise_course_enrollments_cache(enterprise_customer_uuid): +def invalidate_enterprise_course_enrollments_cache(enterprise_customer_uuid, lms_user_id): """ Invalidates the enterprise course enrollments cache for a learner. """ - cache_key = enterprise_course_enrollments_cache_key(enterprise_customer_uuid) + cache_key = enterprise_course_enrollments_cache_key(enterprise_customer_uuid, lms_user_id) TieredCache.delete_all_tiers(cache_key) -def invalidate_subscription_licenses_cache(enterprise_customer_uuid): +def invalidate_subscription_licenses_cache(enterprise_customer_uuid, lms_user_id): """ Invalidates the subscription licenses cache for a learner. """ - cache_key = subscription_licenses_cache_key(enterprise_customer_uuid) + cache_key = subscription_licenses_cache_key(enterprise_customer_uuid, lms_user_id) TieredCache.delete_all_tiers(cache_key) diff --git a/enterprise_access/apps/bffs/handlers.py b/enterprise_access/apps/bffs/handlers.py index 2d9ff6fe..478aa453 100644 --- a/enterprise_access/apps/bffs/handlers.py +++ b/enterprise_access/apps/bffs/handlers.py @@ -6,10 +6,10 @@ from enterprise_access.apps.api_client.license_manager_client import LicenseManagerUserApiClient from enterprise_access.apps.bffs.api import ( - get_and_cache_default_enterprise_enrollment_intentions, + get_and_cache_default_enterprise_enrollment_intentions_learner_status, get_and_cache_enterprise_course_enrollments, get_and_cache_subscription_licenses_for_learner, - invalidate_default_enterprise_enrollment_intentions_cache, + invalidate_default_enterprise_enrollment_intentions_learner_status_cache, invalidate_enterprise_course_enrollments_cache, invalidate_subscription_licenses_cache ) @@ -300,7 +300,8 @@ def check_and_activate_assigned_license(self): # Invalidate the subscription licenses cache as the cached data changed # with the now-activated license. invalidate_subscription_licenses_cache( - enterprise_customer_uuid=self.context.enterprise_customer_uuid + enterprise_customer_uuid=self.context.enterprise_customer_uuid, + lms_user_id=self.context.lms_user_id, ) except Exception as e: # pylint: disable=broad-exception-caught logger.exception(f"Error activating license {subscription_license.get('uuid')}") @@ -388,7 +389,8 @@ def check_and_auto_apply_license(self): ) # Invalidate the subscription licenses cache as the cached data changed with the auto-applied license. invalidate_subscription_licenses_cache( - enterprise_customer_uuid=self.context.enterprise_customer_uuid + enterprise_customer_uuid=self.context.enterprise_customer_uuid, + lms_user_id=self.context.lms_user_id, ) # Update the context with the auto-applied license data transformed_auto_applied_licenses = self.transform_subscription_licenses([auto_applied_license]) @@ -410,10 +412,11 @@ def load_default_enterprise_enrollment_intentions(self): Load default enterprise course enrollments (stubbed) """ try: - default_enterprise_enrollment_intentions = get_and_cache_default_enterprise_enrollment_intentions( - request=self.context.request, - enterprise_customer_uuid=self.context.enterprise_customer_uuid, - ) + default_enterprise_enrollment_intentions =\ + get_and_cache_default_enterprise_enrollment_intentions_learner_status( + request=self.context.request, + enterprise_customer_uuid=self.context.enterprise_customer_uuid, + ) self.context.data['default_enterprise_enrollment_intentions'] = default_enterprise_enrollment_intentions except Exception as e: # pylint: disable=broad-exception-caught logger.exception("Error loading default enterprise courses") @@ -462,11 +465,13 @@ def enroll_in_redeemable_default_enterprise_enrollment_intentions(self): # Invalidate the default enterprise enrollment intentions and enterprise course enrollments cache # as the previously redeemable enrollment intentions have been processed/enrolled. - invalidate_default_enterprise_enrollment_intentions_cache( - enterprise_customer_uuid=self.context.enterprise_customer_uuid + invalidate_default_enterprise_enrollment_intentions_learner_status_cache( + enterprise_customer_uuid=self.context.enterprise_customer_uuid, + lms_user_id=self.context.lms_user_id, ) invalidate_enterprise_course_enrollments_cache( - enterprise_customer_uuid=self.context.enterprise_customer_uuid + enterprise_customer_uuid=self.context.enterprise_customer_uuid, + lms_user_id=self.context.lms_user_id, )