Skip to content

Commit

Permalink
feat: modified author labels to add moderator (#34239)
Browse files Browse the repository at this point in the history
Co-authored-by: sohailfatima <[email protected]>
  • Loading branch information
ayesha-waris and sohailfatima authored Feb 15, 2024
1 parent d59dbbd commit fc86b43
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,24 @@ def get_author(self, obj):

def _get_user_label(self, user_id):
"""
Returns the role label (i.e. "Staff" or "Community TA") for the user
Returns the role label (i.e. "Staff", "Moderator" or "Community TA") for the user
with the given id.
"""
is_staff = user_id in self.context["course_staff_user_ids"] or user_id in self.context["moderator_user_ids"]
is_staff = user_id in self.context["course_staff_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
"Moderator" if is_moderator else
"Community TA" if is_ta else
None
)

def _get_user_label_from_username(self, username):
"""
Returns role label of user from username
Possible Role Labels: Staff, Community TA or None
Possible Role Labels: Staff, Moderator, Community TA or None
"""
try:
user = User.objects.get(username=username)
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/discussion/rest_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,7 @@ def test_basic_in_blackout_period_with_user_access(self, mock_emit):
with self.assert_signal_sent(api, 'thread_created', sender=None, user=self.user, exclude_args=('post',)):
actual = create_thread(self.request, self.minimal_data)
expected = self.expected_thread_data({
"author_label": "Staff",
"author_label": "Moderator",
"id": "test_id",
"course_id": str(self.course.id),
"comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_id",
Expand Down Expand Up @@ -2339,7 +2339,7 @@ def test_success_in_black_out_with_user_access(self, parent_id, mock_emit):
"thread_id": "test_thread",
"parent_id": parent_id,
"author": self.user.username,
"author_label": "Staff",
"author_label": "Moderator",
"created_at": "2015-05-27T00:00:00Z",
"updated_at": "2015-05-27T00:00:00Z",
"raw_body": "Test body",
Expand Down
16 changes: 8 additions & 8 deletions lms/djangoapps/discussion/rest_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def test_anonymity(self, role_name, anonymous, anonymous_to_peers, expected_seri
assert actual_serialized_anonymous == expected_serialized_anonymous

@ddt.data(
(FORUM_ROLE_ADMINISTRATOR, False, "Staff"),
(FORUM_ROLE_ADMINISTRATOR, False, "Moderator"),
(FORUM_ROLE_ADMINISTRATOR, True, None),
(FORUM_ROLE_MODERATOR, False, "Staff"),
(FORUM_ROLE_MODERATOR, False, "Moderator"),
(FORUM_ROLE_MODERATOR, True, None),
(FORUM_ROLE_COMMUNITY_TA, False, "Community TA"),
(FORUM_ROLE_COMMUNITY_TA, True, None),
Expand All @@ -116,7 +116,7 @@ def test_author_labels(self, role_name, anonymous, expected_label):
"""
Test correctness of the author_label field.
The label should be "Staff", "Staff", or "Community TA" for the
The label should be "Staff", "Moderator", or "Community TA" for the
Administrator, Moderator, and Community TA roles, respectively, but
the label should not be present if the content is anonymous.
Expand Down Expand Up @@ -274,7 +274,7 @@ def test_closed_by_label_field(self, role, visible):
"unread_comments_count": 3,
"closed_by": moderator
})
closed_by_label = "Staff" if visible else None
closed_by_label = "Moderator" if visible else None
closed_by = moderator if visible else None
can_delete = role != FORUM_ROLE_STUDENT
editable_fields = ["abuse_flagged", "copy_link", "following", "read", "voted"]
Expand Down Expand Up @@ -329,7 +329,7 @@ def test_edit_by_label_field(self, role, visible):
"unread_comments_count": 3,
"closed_by": None
})
edit_by_label = "Staff" if visible else None
edit_by_label = "Moderator" if visible else None
can_delete = role != FORUM_ROLE_STUDENT
last_edit = None if role == FORUM_ROLE_STUDENT else {"editor_username": moderator}
editable_fields = ["abuse_flagged", "copy_link", "following", "read", "voted"]
Expand Down Expand Up @@ -491,8 +491,8 @@ def test_endorsed_by(self, endorser_role_name, thread_anonymous):
assert actual_endorser_anonymous == expected_endorser_anonymous

@ddt.data(
(FORUM_ROLE_ADMINISTRATOR, "Staff"),
(FORUM_ROLE_MODERATOR, "Staff"),
(FORUM_ROLE_ADMINISTRATOR, "Moderator"),
(FORUM_ROLE_MODERATOR, "Moderator"),
(FORUM_ROLE_COMMUNITY_TA, "Community TA"),
(FORUM_ROLE_STUDENT, None),
)
Expand All @@ -501,7 +501,7 @@ def test_endorsed_by_labels(self, role_name, expected_label):
"""
Test correctness of the endorsed_by_label field.
The label should be "Staff", "Staff", or "Community TA" for the
The label should be "Staff", "Moderator", or "Community TA" for the
Administrator, Moderator, and Community TA roles, respectively.
role_name is the name of the author's role.
Expand Down

0 comments on commit fc86b43

Please sign in to comment.