Skip to content

Commit

Permalink
fix: filter allow email domain manage course team
Browse files Browse the repository at this point in the history
Allow to add course team users that aren't allowed to enroll by the filter allow email domain.
Use the normal procedure to skip the email domain,
then the manage course team user case won't block adding the user to the course team.
The filter only validates the email domain if the user is not already enrolled in the course.

fccn/nau-technical#397
  • Loading branch information
igobranco committed Jan 10, 2025
1 parent 245f480 commit 3e341db
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 22 deletions.
21 changes: 16 additions & 5 deletions nau_openedx_extensions/edxapp_wrapper/backends/student_l_v1.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
"""
Real implementation on getting a student course enrollment allowed.
"""
from common.djangoapps.student.models import CourseEnrollmentAllowed # pylint: disable=import-error
from common.djangoapps.student.models import CourseEnrollment, CourseEnrollmentAllowed # pylint: disable=import-error


def get_student_course_enrollment_allowed(user, course_id, *args, **kwargs):
"""
Return configuration value for the key specified as name argument.
Get the student CourseEnrollmentAllowed class instance from the edx-platform.
Args:
val_name (str): Name of the key for which to return configuration value.
default: default value tp return if key is not found in the configuration
user: The user id to find the CourseEnrollmentAllowed instance.
course_id: The course id to find the CourseEnrollmentAllowed instance.
Returns:
Configuration value for the given key.
A CourseEnrollmentAllowed instance or None
"""
return CourseEnrollmentAllowed.for_user(user).filter(course_id=course_id).first()

def get_enrollment(user, course_key, *args, **kwargs):
"""
Gets the student CourseEnrollment class from the edx-platform.
This class represents an user enrolled in a course.
Args:
user: The user id to find the Enrollment.
course_key: The course key to find the Enrollment.
"""
return CourseEnrollment.get_enrollment(user, course_key)
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@

def get_student_course_enrollment_allowed(user, course_id, *args, **kwargs): # pylint: disable=unused-argument
"""
Return configuration value for the key specified as name argument.
Get the student CourseEnrollmentAllowed class instance from the edx-platform.
Args:
val_name (str): Name of the key for which to return configuration value.
default: default value tp return if key is not found in the configuration
user: The user id to find the CourseEnrollmentAllowed instance.
course_id: The course id to find the CourseEnrollmentAllowed instance.
Returns:
Configuration value for the given key.
A CourseEnrollmentAllowed instance or None
"""
return None

def get_enrollment(user, course_key, *args, **kwargs): # pylint: disable=unused-argument
"""
Gets the student CourseEnrollment class from the edx-platform.
This class represents an user enrolled in a course.
Args:
user: The user id to find the Enrollment.
course_key: The course key to find the Enrollment.
"""
return None
27 changes: 22 additions & 5 deletions nau_openedx_extensions/edxapp_wrapper/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,29 @@

def get_student_course_enrollment_allowed(user, course_id, *args, **kwargs):
"""
Gets the student CourseEnrollmentAllowed class from the edx-platform.
This class represents an user represented by its email address that is
allowed to enroll in a course.
"""
Get the student CourseEnrollmentAllowed class instance from the edx-platform.
Args:
user: The user id to find the CourseEnrollmentAllowed instance.
course_id: The course id to find the CourseEnrollmentAllowed instance.
Returns:
A CourseEnrollmentAllowed instance or None
"""
backend_module = settings.NAU_STUDENT_MODULE
backend = import_module(backend_module)

return backend.get_student_course_enrollment_allowed(user, course_id, *args, **kwargs)


def get_enrollment(user, course_key, *args, **kwargs):
"""
Gets the student CourseEnrollment class from the edx-platform.
This class represents an user enrolled in a course.
Args:
user: The user id to find the Enrollment.
course_key: The course key to find the Enrollment.
"""
backend_module = settings.NAU_STUDENT_MODULE
backend = import_module(backend_module)
return backend.get_enrollment(user, course_key, *args, **kwargs)
5 changes: 3 additions & 2 deletions nau_openedx_extensions/filters/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from nau_openedx_extensions.edxapp_wrapper import site_configuration_helpers as configuration_helpers
from nau_openedx_extensions.edxapp_wrapper.course_module import get_other_course_settings
from nau_openedx_extensions.edxapp_wrapper.student import get_student_course_enrollment_allowed
from nau_openedx_extensions.edxapp_wrapper.student import get_enrollment, get_student_course_enrollment_allowed


class FilterEnrollmentByDomain(PipelineStep): # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -56,7 +56,8 @@ def run_filter(self, user, course_key, mode): # pylint: disable=unused-argumen

cea = get_student_course_enrollment_allowed(user, course_key)
# if the student is allowed to enroll, skip checking the email domain
if not cea:
# validate the email domain if user is not already enrolled
if not cea and not get_enrollment(user, course_key):
if not FilterEnrollmentByDomain._is_user_email_allowed(user, domains_allowed):
custom_message = other_course_settings.get("value", {}).get(
"filter_enrollment_by_domain_custom_exception_message",
Expand Down
Binary file modified nau_openedx_extensions/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions nau_openedx_extensions/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-12-12 12:58-0500\n"
"POT-Creation-Date: 2025-01-10 16:09+0000\n"
"PO-Revision-Date: 2021-02-15 15:56+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand Down Expand Up @@ -115,11 +115,11 @@ msgid ""
"{platform_name}."
msgstr ""

#: nau_openedx_extensions/filters/pipeline.py:63
#: nau_openedx_extensions/filters/pipeline.py:64
msgid "If you think this is an error, contact the course support."
msgstr ""

#: nau_openedx_extensions/filters/pipeline.py:64
#: nau_openedx_extensions/filters/pipeline.py:65
#, python-format
msgid ""
"You can't enroll on this course because your email domain is not allowed."
Expand Down
Binary file modified nau_openedx_extensions/locale/pt_PT/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions nau_openedx_extensions/locale/pt_PT/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-12-12 12:58-0500\n"
"POT-Creation-Date: 2025-01-10 16:09+0000\n"
"PO-Revision-Date: 2021-02-15 15:56+0000\n"
"Last-Translator: Ivo Branco <[email protected]>\n"
"Language: pt_PT\n"
Expand Down Expand Up @@ -120,11 +120,11 @@ msgstr ""
"Verifique no seu e-mail {email} o link de ativação da conta "
"{platform_name}."

#: nau_openedx_extensions/filters/pipeline.py:63
#: nau_openedx_extensions/filters/pipeline.py:64
msgid "If you think this is an error, contact the course support."
msgstr "Se achar que se trata de um erro, contacte o suporte."

#: nau_openedx_extensions/filters/pipeline.py:64
#: nau_openedx_extensions/filters/pipeline.py:65
#, python-format
msgid ""
"You can't enroll on this course because your email domain is not allowed."
Expand Down

0 comments on commit 3e341db

Please sign in to comment.