Skip to content

Commit 167cbbe

Browse files
committed
fix(ban): Add defensive coding for get_banned_usernames and get_user_ban_scope
1 parent af1f542 commit 167cbbe

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lms/djangoapps/discussion/rest_api/api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,10 +1957,13 @@ def get_course_discussion_user_stats(
19571957

19581958
# Exclude banned users from the learners list
19591959
# Get all active bans for this course using forum API
1960-
banned_usernames = forum_api.get_banned_usernames(
1961-
course_id=course_key,
1962-
org_key=course_key.org
1963-
)
1960+
get_banned_usernames = getattr(forum_api, 'get_banned_usernames', None)
1961+
banned_usernames = []
1962+
if get_banned_usernames:
1963+
banned_usernames = get_banned_usernames(
1964+
course_id=course_key,
1965+
org_key=course_key.org
1966+
)
19641967

19651968
# Filter out banned users from the stats
19661969
if banned_usernames:

lms/djangoapps/discussion/rest_api/serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,10 @@ def get_author_ban_scope(self, obj):
328328
if isinstance(course_id, str):
329329
course_id = CourseKey.from_string(course_id)
330330

331-
return forum_api.get_user_ban_scope(user, course_id)
331+
get_user_ban_scope = getattr(forum_api, 'get_user_ban_scope', None)
332+
if get_user_ban_scope:
333+
return get_user_ban_scope(user, course_id)
334+
return None
332335
except (ObjectDoesNotExist, ValueError, Exception): # pylint: disable=broad-exception-caught
333336
return None
334337

0 commit comments

Comments
 (0)