Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion lms/djangoapps/discussion/rest_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
FORUM_ROLE_MODERATOR,
Role
)

from common.djangoapps.student.roles import ( eSHEInstructorRole, CourseStaffRole)

class AttributeDict(dict):
"""
Expand Down Expand Up @@ -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()]