From 9ef8ce61e6c1012ceef8d1c77002c90a85d669b0 Mon Sep 17 00:00:00 2001 From: Troy Sankey Date: Mon, 18 Dec 2023 18:13:03 -0800 Subject: [PATCH] feat: wrap new course_not_started_enterprise_learner in a SettingToggle ENT-8078 --- lms/djangoapps/courseware/access_utils.py | 8 +++++--- lms/djangoapps/courseware/tests/test_access.py | 1 + lms/djangoapps/courseware/tests/test_views.py | 1 + lms/envs/common.py | 13 +++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/courseware/access_utils.py b/lms/djangoapps/courseware/access_utils.py index d001b48c8b..dd2f8d8f6d 100644 --- a/lms/djangoapps/courseware/access_utils.py +++ b/lms/djangoapps/courseware/access_utils.py @@ -9,6 +9,7 @@ from logging import getLogger from crum import get_current_request from django.conf import settings +from edx_toggles.toggles import SettingToggle from enterprise.models import EnterpriseCourseEnrollment, EnterpriseCustomerUser from pytz import UTC @@ -137,9 +138,10 @@ def check_start_date(user, days_early_for_beta, start, course_key, display_error # Before returning a StartDateError, determine if the learner should be redirected to the enterprise learner # portal by returning StartDateEnterpriseLearnerError instead. - request = get_current_request() - if request and enterprise_learner_enrolled(request, user, course_key): - return StartDateEnterpriseLearnerError(start, display_error_to_user=display_error_to_user) + if SettingToggle('COURSEWARE_COURSE_NOT_STARTED_ENTERPRISE_LEARNER_ERROR', default=False).is_enabled(): + request = get_current_request() + if request and enterprise_learner_enrolled(request, user, course_key): + return StartDateEnterpriseLearnerError(start, display_error_to_user=display_error_to_user) return StartDateError(start, display_error_to_user=display_error_to_user) diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index b4101a94d8..e89b4f6c4b 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -903,6 +903,7 @@ class CourseOverviewAccessTestCase(ModuleStoreTestCase): ) @ddt.unpack @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False, 'ENABLE_ENTERPRISE_INTEGRATION': True}) + @override_settings(COURSEWARE_COURSE_NOT_STARTED_ENTERPRISE_LEARNER_ERROR=True) def test_course_catalog_access_num_queries_enterprise(self, user_attr_name, course_attr_name): """ Similar to test_course_catalog_access_num_queries_no_enterprise, except enable enterprise features and make the diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 6d991d181e..8b7667ec27 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -3257,6 +3257,7 @@ class AccessUtilsTestCase(ModuleStoreTestCase): ) @ddt.unpack @patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False, 'ENABLE_ENTERPRISE_INTEGRATION': True}) + @override_settings(COURSEWARE_COURSE_NOT_STARTED_ENTERPRISE_LEARNER_ERROR=True) def test_is_course_open_for_learner( self, start_date_modifier, diff --git a/lms/envs/common.py b/lms/envs/common.py index ed8d520660..58eeac2d60 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -4677,6 +4677,19 @@ DATA_CONSENT_SHARE_CACHE_TIMEOUT = 8 * 60 * 60 # 8 hours ENTERPRISE_MARKETING_FOOTER_QUERY_PARAMS = {} ENTERPRISE_TAGLINE = '' +# .. toggle_name: COURSEWARE_COURSE_NOT_STARTED_ENTERPRISE_LEARNER_ERROR +# .. toggle_implementation: SettingToggle +# .. toggle_default: False +# .. toggle_description: If disabled (False), this switch causes the CourseTabView API (or whatever else calls +# check_course_open_for_learner()) to always return the legacy `course_not_started` error code in ALL cases where the +# course has not started. If enabled (True), the API will respond with `course_not_started_enterprise_learner` in a +# subset of cases where the learner is enrolled via subsidy, and `course_not_started` in all other cases. +# .. toggle_use_cases: temporary +# .. toggle_creation_date: 2023-12-18 +# .. toggle_target_removal_date: 2023-12-19 +# .. toggle_tickets: ENT-8078 +COURSEWARE_COURSE_NOT_STARTED_ENTERPRISE_LEARNER_ERROR = False + ############## Settings for Course Enrollment Modes ###################### # The min_price key refers to the minimum price allowed for an instance # of a particular type of course enrollment mode. This is not to be confused