def test_comment( self, is_author, is_thread_author, is_privileged, allow_anonymous, allow_anonymous_to_peers, has_parent, thread_type ): comment = Comment( user_id="5" if is_author else "6", type="comment", parent_id="parent-id" if has_parent else None, ) context = _get_context( requester_id="5", is_requester_privileged=is_privileged, thread=Thread(user_id="5" if is_thread_author else "6", thread_type=thread_type), allow_anonymous=allow_anonymous, allow_anonymous_to_peers=allow_anonymous_to_peers, ) actual = get_editable_fields(comment, context) expected = {"abuse_flagged", "voted"} if is_privileged: expected |= {"edit_reason_code"} if is_author or is_privileged: expected |= {"raw_body"} if not has_parent and ((is_thread_author and thread_type == "question") or is_privileged): expected |= {"endorsed"} if is_author and allow_anonymous: expected |= {"anonymous"} if is_author and allow_anonymous_to_peers: expected |= {"anonymous_to_peers"} assert actual == expected
def _check_editable_fields(cc_content, data, context): """ Raise ValidationError if the given update data contains a field that is not editable by the requesting user """ _check_fields(get_editable_fields(cc_content, context), data, "This field is not editable.")
def test_thread( self, is_author, is_privileged, is_cohorted, allow_anonymous, allow_anonymous_to_peers ): thread = Thread(user_id="5" if is_author else "6", type="thread") context = _get_context( requester_id="5", is_requester_privileged=is_privileged, is_cohorted=is_cohorted, allow_anonymous=allow_anonymous, allow_anonymous_to_peers=allow_anonymous_to_peers, ) actual = get_editable_fields(thread, context) expected = {"abuse_flagged", "following", "read", "voted"} if is_privileged: expected |= {"closed", "pinned", "close_reason_code", "edit_reason_code"} if is_author or is_privileged: expected |= {"topic_id", "type", "title", "raw_body"} if is_privileged and is_cohorted: expected |= {"group_id"} if is_author and allow_anonymous: expected |= {"anonymous"} if is_author and allow_anonymous_to_peers: expected |= {"anonymous_to_peers"} assert actual == expected
def _check_editable_fields(cc_content, data, context): """ Raise ValidationError if the given update data contains a field that is not editable by the requesting user """ _check_fields( get_editable_fields(cc_content, context), data, "This field is not editable." )
def test_thread(self, is_author, is_privileged, is_cohorted): thread = Thread(user_id="5" if is_author else "6", type="thread") context = _get_context(requester_id="5", is_requester_privileged=is_privileged, is_cohorted=is_cohorted) actual = get_editable_fields(thread, context) expected = {"abuse_flagged", "following", "read", "voted"} if is_author or is_privileged: expected |= {"topic_id", "type", "title", "raw_body"} if is_privileged and is_cohorted: expected |= {"group_id"} self.assertEqual(actual, expected)
def test_comment(self, is_author, is_thread_author, thread_type, is_privileged): comment = Comment(user_id="5" if is_author else "6", type="comment") context = _get_context( requester_id="5", is_requester_privileged=is_privileged, thread=Thread(user_id="5" if is_thread_author else "6", thread_type=thread_type) ) actual = get_editable_fields(comment, context) expected = {"abuse_flagged", "voted"} if is_author or is_privileged: expected |= {"raw_body"} if (is_thread_author and thread_type == "question") or is_privileged: expected |= {"endorsed"} self.assertEqual(actual, expected)
def test_thread(self, is_author, is_privileged, is_cohorted): thread = Thread(user_id="5" if is_author else "6", type="thread") context = _get_context( requester_id="5", is_requester_privileged=is_privileged, is_cohorted=is_cohorted ) actual = get_editable_fields(thread, context) expected = {"abuse_flagged", "following", "read", "voted"} if is_author or is_privileged: expected |= {"topic_id", "type", "title", "raw_body"} if is_privileged and is_cohorted: expected |= {"group_id"} self.assertEqual(actual, expected)
def test_comment(self, is_author, is_thread_author, thread_type, is_privileged): comment = Comment(user_id="5" if is_author else "6", type="comment") context = _get_context( requester_id="5", is_requester_privileged=is_privileged, thread=Thread(user_id="5" if is_thread_author else "6", thread_type=thread_type) ) actual = get_editable_fields(comment, context) expected = {"abuse_flagged", "voted"} if is_author or is_privileged: expected |= {"raw_body"} if (is_thread_author and thread_type == "question") or is_privileged: expected |= {"endorsed"} assert actual == expected
def get_editable_fields(self, obj): """ Return the list of the fields the requester can edit """ return sorted(get_editable_fields(obj, self.context))
def get_editable_fields(self, obj): """ Return the list of the fields the requester can edit """ return sorted(get_editable_fields(obj, self.context))