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.
This commit is contained in:
Igor Degtiarov
2021-01-05 20:20:35 +02:00
committed by GitHub
parent 3cd212ee70
commit acbefd1079
2 changed files with 30 additions and 1 deletions

View File

@@ -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

View File

@@ -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
}
))