@@ -159,12 +159,16 @@ def get_thread(
159159 raise ForumV2RequestError ("Failed to prepare thread API response" ) from error
160160
161161
162- def delete_thread (thread_id : str , course_id : Optional [str ] = None ) -> dict [str , Any ]:
162+ def delete_thread (
163+ thread_id : str , course_id : Optional [str ] = None , deleted_by : Optional [str ] = None
164+ ) -> dict [str , Any ]:
163165 """
164166 Delete the thread for the given thread_id.
165167
166168 Parameters:
167169 thread_id: The ID of the thread to be deleted.
170+ course_id: The ID of the course (optional).
171+ deleted_by: The ID of the user performing the delete (optional).
168172 Response:
169173 The details of the thread that is deleted.
170174 """
@@ -177,7 +181,9 @@ def delete_thread(thread_id: str, course_id: Optional[str] = None) -> dict[str,
177181 f"Thread does not exist with Id: { thread_id } "
178182 ) from exc
179183
180- backend .delete_comments_of_a_thread (thread_id )
184+ count_of_response_deleted , count_of_replies_deleted = (
185+ backend .soft_delete_comments_of_a_thread (thread_id , deleted_by )
186+ )
181187 thread = backend .validate_object ("CommentThread" , thread_id )
182188
183189 try :
@@ -187,10 +193,17 @@ def delete_thread(thread_id: str, course_id: Optional[str] = None) -> dict[str,
187193 raise ForumV2RequestError ("Failed to prepare thread API response" ) from error
188194
189195 backend .delete_subscriptions_of_a_thread (thread_id )
190- result = backend .delete_thread (thread_id )
196+ result = backend .soft_delete_thread (thread_id , deleted_by )
191197 if result and not (thread ["anonymous" ] or thread ["anonymous_to_peers" ]):
192198 backend .update_stats_for_course (
193- thread ["author_id" ], thread ["course_id" ], threads = - 1
199+ thread ["author_id" ],
200+ thread ["course_id" ],
201+ threads = - 1 ,
202+ responses = - count_of_response_deleted ,
203+ replies = - count_of_replies_deleted ,
204+ deleted_threads = 1 ,
205+ deleted_responses = count_of_response_deleted ,
206+ deleted_replies = count_of_replies_deleted ,
194207 )
195208
196209 return serialized_data
@@ -393,6 +406,7 @@ def get_user_threads(
393406 "user_id" : user_id ,
394407 "group_id" : group_id ,
395408 "group_ids" : group_ids ,
409+ "is_deleted" : kwargs .get ("is_deleted" , False ),
396410 "context" : kwargs .get ("context" ),
397411 }
398412 params = {k : v for k , v in params .items () if v is not None }
@@ -420,3 +434,64 @@ def get_course_id_by_thread(thread_id: str) -> str | None:
420434 or MySQLBackend .get_course_id_by_thread_id (thread_id )
421435 or None
422436 )
437+
438+
439+ def get_deleted_threads_for_course (
440+ course_id : str , page : int = 1 , per_page : int = 20 , author_id : Optional [str ] = None
441+ ) -> dict [str , Any ]:
442+ """
443+ Get deleted threads for a specific course.
444+
445+ Args:
446+ course_id (str): The course identifier
447+ page (int): Page number for pagination (default: 1)
448+ per_page (int): Number of threads per page (default: 20)
449+ author_id (str, optional): Filter by author ID
450+
451+ Returns:
452+ dict: Dictionary containing deleted threads and pagination info
453+ """
454+ backend = get_backend (course_id )()
455+ return backend .get_deleted_threads_for_course (course_id , page , per_page , author_id )
456+
457+
458+ def restore_thread (
459+ thread_id : str , course_id : Optional [str ] = None , restored_by : Optional [str ] = None
460+ ) -> bool :
461+ """
462+ Restore a soft-deleted thread.
463+
464+ Args:
465+ thread_id (str): The ID of the thread to restore
466+ course_id (str, optional): The course ID for backend selection
467+ restored_by (str, optional): The ID of the user performing the restoration
468+
469+ Returns:
470+ bool: True if thread was restored, False if not found
471+ """
472+ backend = get_backend (course_id )()
473+ return backend .restore_thread (thread_id , restored_by = restored_by )
474+
475+
476+ def restore_user_deleted_threads (
477+ user_id : str ,
478+ course_ids : list [str ],
479+ course_id : Optional [str ] = None ,
480+ restored_by : Optional [str ] = None ,
481+ ) -> int :
482+ """
483+ Restore all deleted threads for a user across courses.
484+
485+ Args:
486+ user_id (str): The ID of the user whose threads to restore
487+ course_ids (list): List of course IDs to restore threads in
488+ course_id (str, optional): Course ID for backend selection (uses first from list if not provided)
489+ restored_by (str, optional): The ID of the user performing the restoration
490+
491+ Returns:
492+ int: Number of threads restored
493+ """
494+ backend = get_backend (course_id or course_ids [0 ])()
495+ return backend .restore_user_deleted_threads (
496+ user_id , course_ids , restored_by = restored_by
497+ )
0 commit comments