From fc86b431afb4c205b7aacdc98f95a2a7676c751c Mon Sep 17 00:00:00 2001 From: ayesha waris <73840786+ayesha-waris@users.noreply.github.com> Date: Thu, 15 Feb 2024 20:43:30 +0500 Subject: [PATCH] feat: modified author labels to add moderator (#34239) Co-authored-by: sohailfatima <23100065@lums.edu.pk> --- .../discussion/rest_api/serializers.py | 8 +++++--- .../discussion/rest_api/tests/test_api.py | 4 ++-- .../rest_api/tests/test_serializers.py | 16 ++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index 4ac573e766..f8868cbed8 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -203,14 +203,16 @@ class _ContentSerializer(serializers.Serializer): 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 ) @@ -218,7 +220,7 @@ class _ContentSerializer(serializers.Serializer): 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) diff --git a/lms/djangoapps/discussion/rest_api/tests/test_api.py b/lms/djangoapps/discussion/rest_api/tests/test_api.py index a9bf98c50a..3d08a9b51a 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_api.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_api.py @@ -1930,7 +1930,7 @@ class CreateThreadTest( 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", @@ -2339,7 +2339,7 @@ class CreateCommentTest( "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", diff --git a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py index e2035c9299..5d958370c1 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py @@ -102,9 +102,9 @@ class SerializerTestMixin(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetM 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), @@ -116,7 +116,7 @@ class SerializerTestMixin(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetM """ 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. @@ -274,7 +274,7 @@ class ThreadSerializerSerializationTest(SerializerTestMixin, SharedModuleStoreTe "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"] @@ -329,7 +329,7 @@ class ThreadSerializerSerializationTest(SerializerTestMixin, SharedModuleStoreTe "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"] @@ -491,8 +491,8 @@ class CommentSerializerTest(SerializerTestMixin, SharedModuleStoreTestCase): 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), ) @@ -501,7 +501,7 @@ class CommentSerializerTest(SerializerTestMixin, SharedModuleStoreTestCase): """ 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.