diff --git a/lms/djangoapps/courseware/rules.py b/lms/djangoapps/courseware/rules.py index 3a3aec44bbdbfccc46cc7f996380c058b3bc04ee..7bf777b38928aef5e424fbd537a955a6fdae33f5 100644 --- a/lms/djangoapps/courseware/rules.py +++ b/lms/djangoapps/courseware/rules.py @@ -37,7 +37,12 @@ def is_track_ok_for_exam(user, exam): """ course_id = CourseKey.from_string(exam['course_id']) mode, is_active = CourseEnrollment.enrollment_mode_for_user(user, course_id) - return is_active and mode in (CourseMode.VERIFIED, CourseMode.MASTERS, CourseMode.PROFESSIONAL, CourseMode.EXECUTIVE_EDUCATION) + appropriate_modes = [ + CourseMode.VERIFIED, CourseMode.MASTERS, CourseMode.PROFESSIONAL, CourseMode.EXECUTIVE_EDUCATION + ] + if exam.get('is_proctored') and settings.PROCTORING_BACKENDS.get(exam['backend'], {}).get('allow_honor_mode'): + appropriate_modes.append(CourseMode.HONOR) + return is_active and mode in appropriate_modes # The edx_proctoring.api uses this permission to gate access to the diff --git a/lms/djangoapps/courseware/tests/test_rules.py b/lms/djangoapps/courseware/tests/test_rules.py index f08c94470e4a163ac059206f3c488ec74888ed07..ac54e2c89a3fd467ba972d0add845817246e84f7 100644 --- a/lms/djangoapps/courseware/tests/test_rules.py +++ b/lms/djangoapps/courseware/tests/test_rules.py @@ -6,6 +6,7 @@ Tests for permissions defined in courseware.rules import ddt import six from django.test import TestCase +from django.test.utils import override_settings from opaque_keys.edx.locator import CourseLocator from common.djangoapps.course_modes.tests.factories import CourseModeFactory @@ -50,3 +51,26 @@ class PermissionTests(TestCase): has_perm = self.user.has_perm('edx_proctoring.can_take_proctored_exam', {'course_id': six.text_type(self.course_id)}) assert has_perm == should_have_perm + + @override_settings( + PROCTORING_BACKENDS={ + 'mock_proctoring_allow_honor_mode': { + 'allow_honor_mode': True, + }, + } + ) + def test_proctoring_perm_with_honor_mode_permission(self): + """ + Test that the user has the edx_proctoring.can_take_proctored_exam permission in honor enrollment mode. + + If proctoring backend configuration allows exam in honor mode {`allow_honor_mode`: True} the user is + granter proctored exam permission. + """ + CourseEnrollment.enroll(self.user, self.course_id, mode='honor') + self.assertTrue(self.user.has_perm( + 'edx_proctoring.can_take_proctored_exam', { + 'course_id': six.text_type(self.course_id), + 'backend': 'mock_proctoring_allow_honor_mode', + 'is_proctored': True + } + ))