Commit 3287e811 by wajeeha-khalid

Merge pull request #10567 from edx/jia/MA-860

MA-860; No moderator permissions on closed thread
parents 9c2eb1f0 7de58823
...@@ -601,6 +601,10 @@ def create_comment(request, comment_data): ...@@ -601,6 +601,10 @@ def create_comment(request, comment_data):
except Http404: except Http404:
raise ValidationError({"thread_id": ["Invalid value."]}) raise ValidationError({"thread_id": ["Invalid value."]})
# if a thread is closed; no new comments could be made to it
if cc_thread['closed']:
raise PermissionDenied
_check_initializable_comment_fields(comment_data, context) _check_initializable_comment_fields(comment_data, context)
serializer = CommentSerializer(data=comment_data, context=context) serializer = CommentSerializer(data=comment_data, context=context)
actions_form = CommentActionsForm(comment_data) actions_form = CommentActionsForm(comment_data)
......
...@@ -56,8 +56,16 @@ def get_editable_fields(cc_content, context): ...@@ -56,8 +56,16 @@ def get_editable_fields(cc_content, context):
""" """
Return the set of fields that the requester can edit on the given content Return the set of fields that the requester can edit on the given content
""" """
# no edits, except 'abuse_flagged' are allowed on closed threads
ret = {"abuse_flagged"}
if (cc_content["type"] == "thread" and cc_content["closed"]) or (
cc_content["type"] == "comment" and context["thread"]["closed"]
):
return ret
# Shared fields # Shared fields
ret = {"abuse_flagged", "voted"} ret |= {"voted"}
if _is_author_or_privileged(cc_content, context): if _is_author_or_privileged(cc_content, context):
ret |= {"raw_body"} ret |= {"raw_body"}
......
...@@ -614,7 +614,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -614,7 +614,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"title": "Another Test Title", "title": "Another Test Title",
"body": "More content", "body": "More content",
"pinned": False, "pinned": False,
"closed": True, "closed": False,
"abuse_flaggers": [], "abuse_flaggers": [],
"votes": {"up_count": 9}, "votes": {"up_count": 9},
"comments_count": 18, "comments_count": 18,
...@@ -668,7 +668,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto ...@@ -668,7 +668,7 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"raw_body": "More content", "raw_body": "More content",
"rendered_body": "<p>More content</p>", "rendered_body": "<p>More content</p>",
"pinned": False, "pinned": False,
"closed": True, "closed": False,
"following": False, "following": False,
"abuse_flagged": False, "abuse_flagged": False,
"voted": False, "voted": False,
......
...@@ -301,6 +301,16 @@ class CommentsServiceMockMixin(object): ...@@ -301,6 +301,16 @@ class CommentsServiceMockMixin(object):
""" """
self.assert_query_params_equal(httpretty.last_request(), expected_params) self.assert_query_params_equal(httpretty.last_request(), expected_params)
def request_patch(self, request_data):
"""
make a request to PATCH endpoint and return response
"""
return self.client.patch( # pylint: disable=no-member
self.url,
json.dumps(request_data),
content_type="application/merge-patch+json"
)
def make_minimal_cs_thread(overrides=None): def make_minimal_cs_thread(overrides=None):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment