From 2133ec2099d2e0436a69b1b377ca82033889bc5e Mon Sep 17 00:00:00 2001 From: AsadAzam Date: Wed, 16 Feb 2022 14:41:37 +0500 Subject: [PATCH] fix: post anonymous to peers not visible for ta (#29915) * fix: post anonymous to peers not visible for ta * test: fix tests --- lms/djangoapps/discussion/rest_api/serializers.py | 4 +++- lms/djangoapps/discussion/rest_api/tests/test_serializers.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/discussion/rest_api/serializers.py b/lms/djangoapps/discussion/rest_api/serializers.py index 75da9986b6..b53a35db8d 100644 --- a/lms/djangoapps/discussion/rest_api/serializers.py +++ b/lms/djangoapps/discussion/rest_api/serializers.py @@ -164,9 +164,11 @@ class _ContentSerializer(serializers.Serializer): Returns a boolean indicating whether the content should be anonymous to the requester. """ + user_id = self.context["request"].user.id + is_user_staff = user_id in self.context["staff_user_ids"] return ( obj["anonymous"] or - obj["anonymous_to_peers"] and not self.context["is_requester_privileged"] + obj["anonymous_to_peers"] and not is_user_staff ) def get_author(self, obj): diff --git a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py index 9b92573c62..d25049ce60 100644 --- a/lms/djangoapps/discussion/rest_api/tests/test_serializers.py +++ b/lms/djangoapps/discussion/rest_api/tests/test_serializers.py @@ -73,7 +73,7 @@ class SerializerTestMixin(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetM (FORUM_ROLE_MODERATOR, True, False, True), (FORUM_ROLE_MODERATOR, False, True, False), (FORUM_ROLE_COMMUNITY_TA, True, False, True), - (FORUM_ROLE_COMMUNITY_TA, False, True, False), + (FORUM_ROLE_COMMUNITY_TA, False, True, True), (FORUM_ROLE_STUDENT, True, False, True), (FORUM_ROLE_STUDENT, False, True, True), ) @@ -82,7 +82,7 @@ class SerializerTestMixin(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetM """ Test that content is properly made anonymous. - Content should be anonymous iff the anonymous field is true or the + Content should be anonymous if the anonymous field is true or the anonymous_to_peers field is true and the requester does not have a privileged role.