diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index 880c16ce02..0abaa1220f 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -842,12 +842,12 @@ class CourseOverviewAccessTestCase(ModuleStoreTestCase): if user_attr_name == 'user_staff' and action == 'see_exists': # always checks staff role, and if the course has started, check the duration configuration if course_attr_name == 'course_started': - num_queries = 4 + num_queries = 5 else: num_queries = 1 elif user_attr_name == 'user_normal' and action == 'see_exists': if course_attr_name == 'course_started': - num_queries = 4 + num_queries = 5 else: # checks staff role and enrollment data num_queries = 2 diff --git a/openedx/features/course_duration_limits/access.py b/openedx/features/course_duration_limits/access.py index 379c9c6884..2232a7806d 100644 --- a/openedx/features/course_duration_limits/access.py +++ b/openedx/features/course_duration_limits/access.py @@ -19,7 +19,6 @@ from openedx.core.djangoapps.content.course_overviews.models import CourseOvervi from openedx.core.djangoapps.util.user_messages import PageLevelMessages from openedx.core.djangolib.markup import HTML from openedx.features.course_duration_limits.models import CourseDurationLimitConfig -from student.roles import CourseBetaTesterRole MIN_DURATION = timedelta(weeks=4) MAX_DURATION = timedelta(weeks=12) @@ -69,10 +68,6 @@ def get_user_course_expiration_date(user, course): if enrollment is None or enrollment.mode != 'audit': return None - # if the user is a beta tester their access should not expire - if CourseBetaTesterRole(course.id).has_user(user): - return None - try: # Content availability date is equivalent to max(enrollment date, course start date) # for most people. Using the schedule date will provide flexibility to deal with diff --git a/openedx/features/course_duration_limits/models.py b/openedx/features/course_duration_limits/models.py index 9936f2f652..6678e25b4c 100644 --- a/openedx/features/course_duration_limits/models.py +++ b/openedx/features/course_duration_limits/models.py @@ -12,13 +12,14 @@ from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import ugettext_lazy as _ from experiments.models import ExperimentData -from student.models import CourseEnrollment from openedx.core.djangoapps.config_model_utils.models import StackedConfigurationModel from openedx.features.course_duration_limits.config import ( CONTENT_TYPE_GATING_FLAG, EXPERIMENT_ID, EXPERIMENT_DATA_HOLDBACK_KEY ) +from student.models import CourseEnrollment +from student.roles import CourseBetaTesterRole, CourseInstructorRole, CourseStaffRole @python_2_unicode_compatible @@ -75,6 +76,17 @@ class CourseDurationLimitConfig(StackedConfigurationModel): if enrollment is None: enrollment = CourseEnrollment.get_enrollment(user, course_key) + # if the user is has a role of staff, instructor or beta tester their access should not expire + if user is None and enrollment is not None: + user = enrollment.user + if user: + staff_role = CourseStaffRole(course_key).has_user(user) + instructor_role = CourseInstructorRole(course_key).has_user(user) + beta_tester_role = CourseBetaTesterRole(course_key).has_user(user) + + if staff_role or instructor_role or beta_tester_role: + return False + # enrollment might be None if the user isn't enrolled. In that case, # return enablement as if the user enrolled today if enrollment is None: diff --git a/openedx/features/course_duration_limits/tests/test_models.py b/openedx/features/course_duration_limits/tests/test_models.py index 1b596b6f6f..15aa1856ff 100644 --- a/openedx/features/course_duration_limits/tests/test_models.py +++ b/openedx/features/course_duration_limits/tests/test_models.py @@ -76,9 +76,9 @@ class TestCourseDurationLimitConfig(CacheIsolationTestCase): user = self.user course_key = self.course_overview.id - query_count = 5 + query_count = 6 if not pass_enrollment and already_enrolled: - query_count = 6 + query_count = 7 with self.assertNumQueries(query_count): enabled = CourseDurationLimitConfig.enabled_for_enrollment( diff --git a/openedx/features/course_experience/tests/views/test_course_home.py b/openedx/features/course_experience/tests/views/test_course_home.py index 15a158ccd5..f3a9e6dbb6 100644 --- a/openedx/features/course_experience/tests/views/test_course_home.py +++ b/openedx/features/course_experience/tests/views/test_course_home.py @@ -610,6 +610,23 @@ class TestCourseHomePageAccess(CourseHomePageTestCase): self.assertContains(response, TEST_COURSE_HOME_MESSAGE) self.assertContains(response, TEST_COURSE_HOME_MESSAGE_PRE_START) + def test_course_messaging_for_staff(self): + """ + Staff users will not see the expiration banner when course duration limits + are on for the course. + """ + config = CourseDurationLimitConfig( + course=CourseOverview.get_from_id(self.course.id), + enabled=True, + enabled_as_of=date(2018, 1, 1) + ) + config.save() + url = course_home_url(self.course) + CourseEnrollment.enroll(self.staff_user, self.course.id) + response = self.client.get(url) + bannerText = get_expiration_banner_text(self.staff_user, self.course) + self.assertNotContains(response, bannerText, html=True) + @override_waffle_flag(COURSE_PRE_START_ACCESS_FLAG, active=True) @override_waffle_flag(ENABLE_COURSE_GOALS, active=True) def test_course_goals(self):