Skip to content

Commit

Permalink
fix: log only for allowed_enroll email (openedx#36273)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhtishamShahid authored Feb 19, 2025
1 parent 9f5fe30 commit b7a2ffa
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lms/djangoapps/instructor/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Does not include any access control, be sure to check access before calling.
"""


import json
import logging
from contextlib import ExitStack, contextmanager
Expand All @@ -16,8 +15,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.translation import override as override_language
from edx_ace import ace, presentation
from edx_ace.channel.django_email import DjangoEmailChannel
from edx_ace import ace
from edx_ace.recipient import Recipient
from eventtracking import tracker
from submissions import api as sub_api # installed from the edx-submissions repository
Expand Down Expand Up @@ -61,6 +59,7 @@

class EmailEnrollmentState:
""" Store the complete enrollment state of an email in a class """

def __init__(self, course_id, email):
# N.B. retired users are not a concern here because they should be
# handled at a higher level (i.e. in enroll_email). Besides, this
Expand Down Expand Up @@ -434,10 +433,10 @@ def _reset_module_attempts(studentmodule):


def _fire_score_changed_for_block(
course_id,
student,
block,
module_state_key,
course_id,
student,
block,
module_state_key,
):
"""
Fires a PROBLEM_RAW_SCORE_CHANGED event for the given module.
Expand Down Expand Up @@ -592,19 +591,17 @@ def send_mail_to_student(student, param_dict, language=None):
user_context=param_dict,
)

render_msg = presentation.render(DjangoEmailChannel, message)
if not render_msg.body_html.count(student) and message_type == 'allowed_enroll':
log.error(
{
'message': 'Email template does not contain required email address',
'email_address': student,
'message_type': message_type,
'render_msg': render_msg.body,
'count': render_msg.body_html.count(student),
'lms_user_id': lms_user_id,
**param_dict
}
)
if message_type == 'allowed_enroll':
log_data = {
'message': 'allowed_enroll email data log',
'message_type': message_type,
'student': student,
'recipient': message.recipient.email_address,
'context_email': message.context.get('email_address'),
'lms_user_id': lms_user_id,
**param_dict
}
log.error(log_data)
ace.send(message)


Expand Down

0 comments on commit b7a2ffa

Please sign in to comment.