From acbefd107966f047ebf8e7b0096431d5e816e360 Mon Sep 17 00:00:00 2001 From: Igor Degtiarov <igoryok.d@gmail.com> Date: Tue, 5 Jan 2021 20:20:35 +0200 Subject: [PATCH] Extend appropriate proctoring exam modes if provider allows it. (#25927) The honor enrollment mode is widely used in OpenEdx installations, and recently it was not allowed for proctoring exam, but very anticipated. Current PR makes it possible to start the proctoring exam in the honor enrollment mode in case the provider is configured in that way. --- lms/djangoapps/courseware/rules.py | 7 +++++- lms/djangoapps/courseware/tests/test_rules.py | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/courseware/rules.py b/lms/djangoapps/courseware/rules.py index 3a3aec44bbd..7bf777b3892 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 f08c94470e4..ac54e2c89a3 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 + } + )) -- GitLab