diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index ff0c656baf28..0ce566a3a318 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -33,6 +33,8 @@ get_course_staff_users_list, get_moderator_users_list, get_course_ta_users_list, + get_course_eshe_instructors, + get_course_teaching_assistants, ) from openedx.core.djangoapps.discussions.models import DiscussionTopicLink from openedx.core.djangoapps.discussions.utils import get_group_names_by_id @@ -67,6 +69,11 @@ def get_context(course, request, thread=None): course_staff_user_ids = get_course_staff_users_list(course.id) moderator_user_ids = get_moderator_users_list(course.id) ta_user_ids = get_course_ta_users_list(course.id) + + custom_staff_role_user_ids = set( + get_course_eshe_instructors(course.id) + get_course_teaching_assistants(course.id) + ) + requester = request.user cc_requester = CommentClientUser.from_django_user(requester).retrieve(course_id=course.id) cc_requester["course_id"] = course.id @@ -82,6 +89,7 @@ def get_context(course, request, thread=None): "moderator_user_ids": moderator_user_ids, "course_staff_user_ids": course_staff_user_ids, "ta_user_ids": ta_user_ids, + "custom_staff_role_user_ids": custom_staff_role_user_ids, "cc_requester": cc_requester, "has_moderation_privilege": has_moderation_privilege, "is_global_staff": is_global_staff, @@ -207,11 +215,12 @@ def _get_user_label(self, user_id): with the given id. """ is_staff = user_id in self.context["course_staff_user_ids"] + is_custom_staff_role = user_id in self.context["custom_staff_role_user_ids"] is_moderator = user_id in self.context["moderator_user_ids"] is_ta = user_id in self.context["ta_user_ids"] return ( - "Staff" if is_staff else + "Staff" if is_staff or is_custom_staff_role else "Moderator" if is_moderator else "Community TA" if is_ta else None diff --git a/lms/djangoapps/discussion/rest_api/utils.py b/lms/djangoapps/discussion/rest_api/utils.py index e7dca4991008..54f3c0db8a7b 100644 --- a/lms/djangoapps/discussion/rest_api/utils.py +++ b/lms/djangoapps/discussion/rest_api/utils.py @@ -19,7 +19,7 @@ FORUM_ROLE_MODERATOR, Role ) - +from common.djangoapps.student.roles import ( eSHEInstructorRole, CourseStaffRole) class AttributeDict(dict): """ @@ -379,3 +379,18 @@ def is_posting_allowed(posting_restrictions: str, blackout_schedules: List): return not any(schedule["start"] <= now <= schedule["end"] for schedule in blackout_schedules) else: return False + + +def get_course_eshe_instructors(course_key): + """ + Return a list of user ids for users with custom eSHE Instructor Role. + """ + role = eSHEInstructorRole(course_key) + return [user.id for user in role.users_with_role()] + +def get_course_teaching_assistants(course_key): + """ + Return a list of user ids for users with custom TeachingAssistantRole. + """ + role = CourseStaffRole(course_key) + return [user.id for user in role.users_with_role()] \ No newline at end of file