fix: post anonymous to peers not visible for ta (#29915)

* fix: post anonymous to peers not visible for ta

* test: fix tests
This commit is contained in:
AsadAzam
2022-02-16 14:41:37 +05:00
committed by GitHub
parent 8070dd9be0
commit 2133ec2099
2 changed files with 5 additions and 3 deletions

View File

@@ -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):

View File

@@ -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.