chore: added tracker event for bulk delete posts api (#37060)

This commit is contained in:
Muhammad Adeel Tajamul
2025-07-23 12:21:43 +05:00
committed by GitHub
parent ce13251596
commit 082819cca2
2 changed files with 15 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ from celery import shared_task
from django.contrib.auth import get_user_model
from edx_django_utils.monitoring import set_code_owner_attribute
from opaque_keys.edx.locator import CourseKey
from eventtracking import tracker
from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole
from lms.djangoapps.courseware.courses import get_course_with_access
@@ -92,12 +93,18 @@ def send_response_endorsed_notifications(thread_id, response_id, course_key_str,
@shared_task
@set_code_owner_attribute
def delete_course_post_for_user(user_id, username, course_ids):
def delete_course_post_for_user(user_id, username, course_ids, event_data=None):
"""
Deletes all posts for user in a course.
"""
event_data = event_data or {}
log.info(f"<<Bulk Delete>> Deleting all posts for {username} in course {course_ids}")
threads_deleted = Thread.delete_user_threads(user_id, course_ids)
comments_deleted = Comment.delete_user_comments(user_id, course_ids)
log.info(f"<<Bulk Delete>> Deleted {threads_deleted} posts and {comments_deleted} comments for {username} "
f"in course {course_ids}")
event_data.update({
"number_of_posts_deleted": threads_deleted,
"number_of_comments_deleted": comments_deleted,
})
tracker.emit('edx.discussion.bulk_delete_user_posts', event_data)

View File

@@ -1585,8 +1585,14 @@ class BulkDeleteUserPosts(DeveloperErrorViewMixin, APIView):
thread_count = Thread.get_user_threads_count(user.id, course_ids)
if execute_task:
event_data = {
"triggered_by": request.user.username,
"username": username,
"course_or_org": course_or_org,
"course_key": course_id,
}
delete_course_post_for_user.apply_async(
args=(user.id, username, course_ids),
args=(user.id, username, course_ids, event_data),
)
return Response(
{"comment_count": comment_count, "thread_count": thread_count},