1111from drf_yasg import openapi
1212from edx_rest_framework_extensions .auth .jwt .authentication import JwtAuthentication
1313from edx_rest_framework_extensions .auth .session .authentication import SessionAuthenticationAllowInactiveUser
14+ from forum import api as forum_api
1415from opaque_keys .edx .keys import CourseKey
1516from rest_framework import permissions , status
1617from rest_framework .authentication import SessionAuthentication
3536from openedx .core .djangoapps .discussions .models import DiscussionsConfiguration , Provider
3637from openedx .core .djangoapps .discussions .serializers import DiscussionSettingsSerializer
3738from openedx .core .djangoapps .django_comment_common import comment_client
38- from openedx .core .djangoapps .django_comment_common .comment_client .comment import Comment
39- from openedx .core .djangoapps .django_comment_common .comment_client .thread import Thread
4039from openedx .core .djangoapps .django_comment_common .models import CourseDiscussionSettings , Role
4140from openedx .core .djangoapps .user_api .accounts .permissions import CanReplaceUsername , CanRetireUser
4241from openedx .core .djangoapps .user_api .models import UserRetirementStatus
@@ -1571,7 +1570,6 @@ class BulkDeleteUserPosts(DeveloperErrorViewMixin, APIView):
15711570 def post (self , request , course_id ):
15721571 """
15731572 Implements the delete user posts endpoint.
1574- TODO: Add support for MySQLBackend as well
15751573 """
15761574 username = request .GET .get ("username" , None )
15771575 execute_task = request .GET .get ("execute" , "false" ).lower () == "true"
@@ -1595,8 +1593,12 @@ def post(self, request, course_id):
15951593 log .info (f"<<Bulk Delete>> { username } enrolled in { enrollments } " )
15961594 log .info (f"<<Bulk Delete>> Posts for { username } in { course_ids } - for { course_or_org } { course_id } " )
15971595
1598- comment_count = Comment .get_user_comment_count (user .id , course_ids )
1599- thread_count = Thread .get_user_threads_count (user .id , course_ids )
1596+ thread_count = 0
1597+ comment_count = 0
1598+ for cid in course_ids :
1599+ counts = forum_api .get_user_post_counts (user_id = str (user .id ), course_id = cid )
1600+ thread_count += counts .get ("thread_count" , 0 )
1601+ comment_count += counts .get ("comment_count" , 0 )
16001602 log .info (f"<<Bulk Delete>> { username } in { course_ids } - Count thread { thread_count } , comment { comment_count } " )
16011603
16021604 if execute_task :
0 commit comments