feat: prevent sending goal reminder email to disabled users (#36505)

This commit is contained in:
Muhammad Adeel Tajamul
2025-04-09 16:29:44 +05:00
committed by GitHub
parent 40c82c2ff4
commit 27d03cb906
2 changed files with 20 additions and 2 deletions

View File

@@ -49,6 +49,9 @@ def send_ace_message(goal, session_id):
Returns true if sent, false if it absorbed an exception and did not send
"""
user = goal.user
if not user.has_usable_password():
log.info(f'Goal Reminder User is disabled {user.username} course {goal.course_key}')
return False
try:
course = CourseOverview.get_from_id(goal.course_key)
except CourseOverview.DoesNotExist:

View File

@@ -1,5 +1,5 @@
"""Tests for the goal_reminder_email command"""
import uuid
from datetime import datetime
from botocore.exceptions import NoCredentialsError
@@ -18,7 +18,7 @@ from waffle import get_waffle_flag_model # pylint: disable=invalid-django-waffl
from common.djangoapps.student.models import CourseEnrollment
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from lms.djangoapps.course_goals.management.commands.goal_reminder_email import send_email_using_ses
from lms.djangoapps.course_goals.management.commands.goal_reminder_email import send_email_using_ses, send_ace_message
from lms.djangoapps.course_goals.models import CourseGoalReminderStatus
from lms.djangoapps.course_goals.tests.factories import (
CourseGoalFactory, CourseGoalReminderStatusFactory, UserActivityFactory,
@@ -220,6 +220,21 @@ class TestGoalReminderEmailCommand(TestCase):
assert 'override_default_channel' not in msg.options
assert 'from_address' not in msg.options
@ddt.data(True, False)
@mock.patch('lms.djangoapps.course_goals.management.commands.goal_reminder_email.ace.send')
def test_goal_reminder_email_sent_to_disable_user(self, value, mock_ace):
"""
Test that the goal reminder email is not sent to disabled users.
"""
goal = self.make_valid_goal()
if value:
goal.user.set_password("12345678")
else:
goal.user.set_unusable_password()
goal.user.save()
send_ace_message(goal, str(uuid.uuid4()))
assert mock_ace.called is value
class TestGoalReminderEmailSES(TestCase):
"""