Skip to content

Commit

Permalink
refactor: [FC-0047] fix review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Aug 9, 2024
1 parent 6bd6b95 commit cdbdd8c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 1 addition & 3 deletions lms/djangoapps/discussion/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def __init__(self, *args, **kwargs):


class CommentNotification(BaseMessageType):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.options['transactional'] = True
pass


@shared_task(base=LoggedTask)
Expand Down
8 changes: 6 additions & 2 deletions lms/djangoapps/discussion/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
import openedx.core.djangoapps.django_comment_common.comment_client as cc
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY
from lms.djangoapps.discussion.tasks import _is_first_comment, _should_send_message, _track_notification_sent
from lms.djangoapps.discussion.tasks import (
_is_first_comment,
_should_send_message,
_track_notification_sent,
)
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
from openedx.core.djangoapps.django_comment_common.models import ForumsConfig
Expand Down Expand Up @@ -342,7 +346,7 @@ def run_should_not_send_email_test(self, thread, comment_dict):
})

should_email_send = _is_first_comment(comment_dict['id'], thread['id'])
assert should_email_send is False
assert not should_email_send
assert not self.mock_ace_send.called

def test_subcomment_should_not_send_email(self):
Expand Down
26 changes: 13 additions & 13 deletions lms/djangoapps/instructor/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_user_email_language(user):
return UserPreference.get_value(user, LANGUAGE_KEY)


def enroll_email(course_id, student_email, auto_enroll=False, email_students=False, email_params=None, language=None):
def enroll_email(course_id, student_email, auto_enroll=False, email_students=False, message_params=None, language=None):
"""
Enroll a student by email.
Expand All @@ -133,16 +133,16 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal
if auto_enroll is set, then when the email registers, they will be
enrolled in the course automatically.
`email_students` determines if student should be notified of action by email.
`email_params` parameters used while parsing email templates (a `dict`).
`message_params` parameters used while parsing message templates (a `dict`).
`language` is the language used to render the email.
returns two EmailEnrollmentState's
representing state before and after the action.
"""
previous_state = EmailEnrollmentState(course_id, student_email)
enrollment_obj = None
if email_params:
email_params.update({
if message_params:
message_params.update({
'app_label': 'instructor',
'push_notification_extra_context': {
'notification_type': 'enroll',
Expand All @@ -167,22 +167,22 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal

enrollment_obj = CourseEnrollment.enroll_by_email(student_email, course_id, course_mode)
if email_students:
email_params['message_type'] = 'enrolled_enroll'
email_params['email_address'] = student_email
email_params['user_id'] = previous_state.user.id
email_params['full_name'] = previous_state.full_name
send_mail_to_student(student_email, email_params, language=language)
message_params['message_type'] = 'enrolled_enroll'
message_params['email_address'] = student_email
message_params['user_id'] = previous_state.user.id
message_params['full_name'] = previous_state.full_name
send_mail_to_student(student_email, message_params, language=language)

elif not is_email_retired(student_email):
cea, _ = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email)
cea.auto_enroll = auto_enroll
cea.save()
if email_students:
email_params['message_type'] = 'allowed_enroll'
email_params['email_address'] = student_email
message_params['message_type'] = 'allowed_enroll'
message_params['email_address'] = student_email
if previous_state.user:
email_params['user_id'] = previous_state.user.id
send_mail_to_student(student_email, email_params, language=language)
message_params['user_id'] = previous_state.user.id
send_mail_to_student(student_email, message_params, language=language)

after_state = EmailEnrollmentState(course_id, student_email)

Expand Down

0 comments on commit cdbdd8c

Please sign in to comment.