feat: suppress user task email after importing content in libraries (#37771)

This commit is contained in:
Navin Karkera
2025-12-18 21:45:32 +05:30
committed by GitHub
parent c67558f17d
commit 781feb1883
2 changed files with 24 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ from .tasks import send_task_complete_email
LOGGER = logging.getLogger(__name__)
LIBRARY_CONTENT_TASK_NAME_TEMPLATE = 'updating .*type@library_content.* from library'
LIBRARY_IMPORT_TASK_NAME_TEMPLATE = '(.*)?migrate_from_modulestore'
@receiver(user_task_stopped, dispatch_uid="cms_user_task_stopped")
@@ -50,7 +51,17 @@ def user_task_stopped_handler(sender, **kwargs): # pylint: disable=unused-argum
True if the end-of-task email should be suppressed
"""
p = re.compile(LIBRARY_CONTENT_TASK_NAME_TEMPLATE)
return p.match(task_name)
return p.match(task_name) is not None
def is_library_import_task(task_name: str) -> bool:
"""
Decides whether to suppress an end-of-task email on the basis that the just-ended task was a library import
operation, and that emails following such operations amount to spam
`LIBRARY_IMPORT_TASK_NAME_TEMPLATE` matches both `bulk_migrate_from_modulestore` and `migrate_from_modulestore`
tasks.
"""
p = re.compile(LIBRARY_IMPORT_TASK_NAME_TEMPLATE)
return p.match(task_name) is not None
def get_olx_validation_from_artifact():
"""
@@ -84,7 +95,8 @@ def user_task_stopped_handler(sender, **kwargs): # pylint: disable=unused-argum
return (
is_library_content_update(task_name) or
is_library_backup_task(task_name) or
is_library_restore_task(task_name)
is_library_restore_task(task_name) or
is_library_import_task(task_name)
)
status = kwargs['status']

View File

@@ -208,6 +208,16 @@ class TestUserTaskStopped(APITestCase):
self.assert_msg_subject(msg)
self.assert_msg_body_fragments(msg, body_fragments)
def test_email_not_sent_with_libary_import_task(self):
"""
Check that email is not sent when library import task is completed.
"""
end_of_task_status = self.status
end_of_task_status.name = "bulk_migrate_from_modulestore"
user_task_stopped.send(sender=UserTaskStatus, status=end_of_task_status)
self.assertEqual(len(mail.outbox), 0)
def test_email_not_sent_with_libary_content_update(self):
"""
Check the signal receiver and email sending.