diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py index 866820c5139f..3b5d4f17e3e6 100644 --- a/lms/djangoapps/instructor/enrollment.py +++ b/lms/djangoapps/instructor/enrollment.py @@ -33,6 +33,7 @@ get_event_transaction_id, set_event_transaction_type ) +from common.djangoapps.student.models import EnrollmentNotAllowed from lms.djangoapps.courseware.models import StudentModule from lms.djangoapps.grades.api import constants as grades_constants from lms.djangoapps.grades.api import disconnect_submissions_signal_receiver @@ -51,6 +52,7 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.models import UserPreference from openedx.core.djangolib.markup import Text +from openedx_filters.learning.filters import CourseEnrollmentStarted from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError # lint-amnesty, pylint: disable=wrong-import-order @@ -166,6 +168,13 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal send_mail_to_student(student_email, email_params, language=language) elif not is_email_retired(student_email): + try: + CourseEnrollmentStarted.run_filter( + user=None, course_key=course_id, mode=None, + ) + except CourseEnrollmentStarted.PreventEnrollment as exc: + raise EnrollmentNotAllowed(str(exc)) from exc + cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email) cea.auto_enroll = auto_enroll cea.save()