MICROBA-1038 | Don't check enrollment status when removing allowlist entries
[MICROBA-1038] - Today, we check if a learner is actively enrolled in a course-run before we add or remove them from the Instructor Dashboard allow list. We ran into an issue where we couldn't remove an entry from the list because the learner is no longer actively enrolled in the course-run. Update instructor dashboard logic to only check enrollment status when _adding_ a learner to the allow list.
This commit is contained in:
@@ -7,6 +7,7 @@ Python APIs exposed by the student app to other in-process apps.
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.conf import settings
|
||||
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
from common.djangoapps.student.models_api import create_manual_enrollment_audit as _create_manual_enrollment_audit
|
||||
from common.djangoapps.student.models_api import get_course_access_role
|
||||
from common.djangoapps.student.models_api import get_course_enrollment as _get_course_enrollment
|
||||
@@ -101,3 +102,10 @@ def get_access_role_by_role_name(role_name):
|
||||
role_name: the name of the role
|
||||
"""
|
||||
return _REGISTERED_ACCESS_ROLES.get(role_name, None)
|
||||
|
||||
|
||||
def is_user_enrolled_in_course(student, course_key):
|
||||
"""
|
||||
Determines if a learner is enrolled in a given course-run.
|
||||
"""
|
||||
return CourseEnrollment.is_enrolled(student, course_key)
|
||||
|
||||
57
common/djangoapps/student/tests/test_api.py
Normal file
57
common/djangoapps/student/tests/test_api.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
Test Student api.py
|
||||
"""
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
from common.djangoapps.student.api import is_user_enrolled_in_course
|
||||
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
|
||||
|
||||
class TestStudentApi(SharedModuleStoreTestCase):
|
||||
"""
|
||||
Tests for functionality in the api.py file of the Student django app.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.course = CourseFactory.create()
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user = UserFactory.create()
|
||||
self.course_run_key = self.course.id
|
||||
|
||||
def test_is_user_enrolled_in_course(self):
|
||||
"""
|
||||
Verify the correct value is returned when a learner is actively enrolled in a course-run.
|
||||
"""
|
||||
CourseEnrollmentFactory.create(
|
||||
user_id=self.user.id,
|
||||
course_id=self.course.id
|
||||
)
|
||||
|
||||
result = is_user_enrolled_in_course(self.user, self.course_run_key)
|
||||
assert result
|
||||
|
||||
def test_is_user_enrolled_in_course_not_active(self):
|
||||
"""
|
||||
Verify the correct value is returned when a learner is not actively enrolled in a course-run.
|
||||
"""
|
||||
CourseEnrollmentFactory.create(
|
||||
user_id=self.user.id,
|
||||
course_id=self.course.id,
|
||||
is_active=False
|
||||
)
|
||||
|
||||
result = is_user_enrolled_in_course(self.user, self.course_run_key)
|
||||
assert not result
|
||||
|
||||
def test_is_user_enrolled_in_course_no_enrollment(self):
|
||||
"""
|
||||
Verify the correct value is returned when a learner is not enrolled in a course-run.
|
||||
"""
|
||||
result = is_user_enrolled_in_course(self.user, self.course_run_key)
|
||||
assert not result
|
||||
Reference in New Issue
Block a user