fix: show staff tag for global staff in discussion forum#181
fix: show staff tag for global staff in discussion forum#181Alam-2U wants to merge 0 commit intorelease-ulmofrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes discussion forum author labeling so platform-wide staff users (Django is_staff=True) display the “Staff” tag even when they don’t hold a course-specific forum role.
Changes:
- Add global staff fallback checks when computing
author_label/ user labels. - Add serializer test coverage for global staff author labeling (anonymous vs non-anonymous).
- Extend deleted-content labeling helper to also recognize platform-wide staff.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
lms/djangoapps/discussion/rest_api/tests/test_serializers.py |
Adds a test ensuring is_staff authors receive “Staff” unless anonymous. |
lms/djangoapps/discussion/rest_api/serializers.py |
Updates _get_user_label to fall back to user.is_staff when not course staff. |
lms/djangoapps/discussion/rest_api/api.py |
Updates deleted-content user label helper to also return “Staff” for is_staff users. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| # Check if user is a platform-wide staff member | ||
| if not is_staff: | ||
| try: | ||
| User = get_user_model() | ||
| user = User.objects.get(id=user_id) | ||
| is_staff = user.is_staff | ||
| except ObjectDoesNotExist: | ||
| pass | ||
|
|
| # Make author a platform-wide staff member | ||
| self.author.is_staff = True | ||
| self.author.save() | ||
|
|
5bca84c to
c44815a
Compare
There was a problem hiding this comment.
Pull request overview
Fixes discussion author labeling so platform-wide staff (global is_staff=True) are shown with the “Staff” tag instead of being treated as learners when they lack a course-specific staff role.
Changes:
- Add a serializer test covering global staff author labeling (including anonymous content behavior).
- Update discussion serializers to treat global staff as “Staff” when computing
author_label. - Update API user-label helper to fall back to global staff (
is_staff=True) for label resolution.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
lms/djangoapps/discussion/rest_api/tests/test_serializers.py |
Adds coverage ensuring global staff users receive the “Staff” author label when not anonymous. |
lms/djangoapps/discussion/rest_api/serializers.py |
Extends label resolution to include platform-wide staff; introduces global staff ID preloading in serializer context. |
lms/djangoapps/discussion/rest_api/api.py |
Extends label resolution to include platform-wide staff via DB lookup when not course staff/mod/TA. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| is_staff = user_id in self.context["course_staff_user_ids"] or user_id in self.context["global_staff_user_ids"] | ||
| is_moderator = user_id in self.context["moderator_user_ids"] | ||
| is_ta = user_id in self.context["ta_user_ids"] | ||
|
|
||
| # Check if user is a platform-wide staff member | ||
| if not is_staff: | ||
| try: | ||
| user = User.objects.get(id=user_id) | ||
| is_staff = user.is_staff | ||
| except ObjectDoesNotExist: | ||
| pass | ||
|
|
| try: | ||
| user = User.objects.get(id=user_id_int) | ||
| if user.is_staff: | ||
| return "Staff" | ||
| except User.DoesNotExist: | ||
| pass |
| return "Moderator" | ||
| elif user_id_int in ta_user_ids: | ||
| return "Community TA" | ||
| else: | ||
| # Check if user is a platform-wide staff member | ||
| try: | ||
| user = User.objects.get(id=user_id_int) | ||
| if user.is_staff: | ||
| return "Staff" |
| 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) | ||
| global_staff_user_ids = list(User.objects.filter(is_staff=True).values_list('id', flat=True)) | ||
| requester = request.user |
c914004 to
8859232
Compare
8859232 to
4420dfb
Compare
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Global staff users were being displayed as learners in the discussion forum, and the staff tag was not shown.
Issue :
The course staff check was overriding the global staff check. As a result, if a user was not marked as course staff, they were displayed as a learner even if they had global staff privileges.
Ticket :
COSMO2-842