Skip to content
Open
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
8 changes: 8 additions & 0 deletions lms/djangoapps/discussion/rest_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,14 @@ def get_user_label(user_id):
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"
except User.DoesNotExist:
pass
except (ValueError, TypeError):
# If user_id has any issues, there's no label to return
pass
Expand Down
8 changes: 8 additions & 0 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,14 @@ def _get_user_label(self, user_id):
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

return (
"Staff"
if is_staff
Expand Down
24 changes: 24 additions & 0 deletions lms/djangoapps/discussion/rest_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ def test_author_labels(self, role_name, anonymous, expected_label):
serialized = self.serialize(self.make_cs_content({"anonymous": anonymous}))
assert serialized["author_label"] == expected_label

@ddt.data(
(False, "Staff"),
(True, None),
)
@ddt.unpack
def test_author_label_for_global_staff(self, anonymous, expected_label):
"""
Test that platform-wide staff members get the "Staff" label.

Users with is_staff=True should receive the "Staff" label even if they
don't have a course-specific role, unless the content is anonymous.

anonymous is the value of the anonymous field in the content.
expected_label is the expected value of the author_label field in the
API output.
"""
# Make author a platform-wide staff member
self.author.is_staff = True
self.author.save()

# Don't assign any forum role - author should still get "Staff" label
serialized = self.serialize(self.make_cs_content({"anonymous": anonymous}))
assert serialized["author_label"] == expected_label

def test_abuse_flagged(self):
serialized = self.serialize(
self.make_cs_content({"abuse_flaggers": [str(self.user.id)]})
Expand Down
Loading