Skip to content

Commit ff842e2

Browse files
committed
fix: use Forum v2 for learner threads to exclude deleted items from abuse count
1 parent 375e74d commit ff842e2

File tree

1 file changed

+20
-1
lines changed
  • lms/djangoapps/discussion/rest_api

1 file changed

+20
-1
lines changed

lms/djangoapps/discussion/rest_api/api.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,13 @@ def get_learner_active_thread_list(request, course_key, query_params):
13161316
filtered_threads = []
13171317
for thread in threads:
13181318
try:
1319+
# Fetch thread with responses to recalculate abuse_flagged_count if needed
1320+
params = {}
1321+
if count_flagged and "abuse_flagged_count" in thread:
1322+
params = {"with_responses": True, "recursive": False}
1323+
13191324
forum_thread = forum_api.get_thread(
1320-
thread.get("id"), course_id=str(course_key)
1325+
thread.get("id"), params=params, course_id=str(course_key)
13211326
)
13221327
is_deleted = forum_thread.get("is_deleted", False)
13231328

@@ -1327,6 +1332,20 @@ def get_learner_active_thread_list(request, course_key, query_params):
13271332
thread["deleted_by"] = forum_thread.get("deleted_by")
13281333
filtered_threads.append(thread)
13291334
elif not show_deleted and not is_deleted:
1335+
# Fix abuse_flagged_count to exclude soft-deleted comments
1336+
if count_flagged and "abuse_flagged_count" in thread:
1337+
try:
1338+
# Recalculate abuse count from Forum v2 data excluding soft-deleted items
1339+
abuse_count = 0
1340+
for response_type in ["endorsed_responses", "non_endorsed_responses", "children"]:
1341+
if response_type in forum_thread:
1342+
for child in forum_thread.get(response_type, []):
1343+
if child.get("abuse_flaggers", []) and not child.get("is_deleted", False):
1344+
abuse_count += 1
1345+
thread["abuse_flagged_count"] = abuse_count
1346+
except (KeyError, TypeError):
1347+
# If structure is unexpected, keep original count
1348+
pass
13301349
filtered_threads.append(thread)
13311350
except Exception as e: # pylint: disable=broad-exception-caught
13321351
log.warning(

0 commit comments

Comments
 (0)