feat: [MICROBA-1531] bulk email deny list logic (#29465)

* feat: [MICROBA-1531] bulk_email deny list logic
This commit is contained in:
Thomas Tracy
2021-12-02 13:11:55 -05:00
committed by GitHub
parent 1886e940ea
commit 038d68d53c
3 changed files with 25 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ from django.conf import settings
from django.urls import reverse
from lms.djangoapps.bulk_email.models_api import (
is_bulk_email_disabled_for_course,
is_bulk_email_enabled_for_course,
is_bulk_email_feature_enabled,
is_user_opted_out_for_course
@@ -30,7 +31,7 @@ def get_emails_enabled(user, course_id):
(bool): True if emails are enabled for the course associated with course_id for the user;
False otherwise
"""
if is_bulk_email_feature_enabled(course_id=course_id):
if is_bulk_email_feature_enabled(course_id=course_id) and not is_bulk_email_disabled_for_course(course_id):
return not is_user_opted_out_for_course(user=user, course_id=course_id)
return None

View File

@@ -11,10 +11,12 @@ from opaque_keys.edx.keys import CourseKey
from common.djangoapps.student.tests.factories import AdminFactory
from lms.djangoapps.bulk_email.api import is_bulk_email_enabled_for_course, is_bulk_email_feature_enabled
from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseAuthorization
from lms.djangoapps.bulk_email.models import BulkEmailFlag, CourseAuthorization, DisabledCourse
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_MODULESTORE, SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory
from lms.djangoapps.bulk_email.models_api import is_bulk_email_disabled_for_course
class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
"""
@@ -94,6 +96,20 @@ class TestNewInstructorDashboardEmailViewMongoBacked(SharedModuleStoreTestCase):
response = self.client.get(self.url)
self.assertContains(response, self.email_link)
def test_course_authorized_and_on_deny_list(self):
BulkEmailFlag.objects.create(enabled=True, require_course_email_auth=True)
# Authorize the course to use email
cauth = CourseAuthorization(course_id=self.course.id, email_enabled=True)
cauth.save()
# Disabled the course to use email
disabled_course = DisabledCourse(course_id=self.course.id)
disabled_course.save()
# Assert that instructor email is disabled for this course
assert is_bulk_email_disabled_for_course(self.course.id)
# Assert that the URL for the email view is not in the response
response = self.client.get(self.url)
self.assertNotContains(response, self.email_link)
# Flag is disabled, but course is authorized
def test_course_authorized_feature_off(self):
BulkEmailFlag.objects.create(enabled=False, require_course_email_auth=True)

View File

@@ -38,6 +38,7 @@ from common.djangoapps.student.roles import (
)
from common.djangoapps.util.json_request import JsonResponse
from lms.djangoapps.bulk_email.api import is_bulk_email_feature_enabled
from lms.djangoapps.bulk_email.models_api import is_bulk_email_disabled_for_course
from lms.djangoapps.certificates import api as certs_api
from lms.djangoapps.certificates.data import CertificateStatuses
from lms.djangoapps.certificates.models import (
@@ -177,7 +178,11 @@ def instructor_dashboard_2(request, course_id): # lint-amnesty, pylint: disable
sections.insert(3, _section_extensions(course))
# Gate access to course email by feature flag & by course-specific authorization
if is_bulk_email_feature_enabled(course_key) and (access['staff'] or access['instructor']):
if (
is_bulk_email_feature_enabled(course_key) and not
is_bulk_email_disabled_for_course(course_key) and
(access['staff'] or access['instructor'])
):
sections.append(_section_send_email(course, access))
# Gate access to Special Exam tab depending if either timed exams or proctored exams