Пример #1
0
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.")
Пример #2
0
 def test_thread(self, is_author, is_privileged):
     thread = Thread(user_id="5" if is_author else "6", type="thread")
     context = _get_context(requester_id="5", is_requester_privileged=is_privileged)
     actual = get_editable_fields(thread, context)
     expected = {"following", "voted"}
     if is_author or is_privileged:
         expected |= {"topic_id", "type", "title", "raw_body"}
     self.assertEqual(actual, expected)
Пример #3
0
 def test_thread(self, is_author, is_privileged):
     thread = Thread(user_id="5" if is_author else "6", type="thread")
     context = _get_context(requester_id="5",
                            is_requester_privileged=is_privileged)
     actual = get_editable_fields(thread, context)
     expected = {"abuse_flagged", "following", "voted"}
     if is_author or is_privileged:
         expected |= {"topic_id", "type", "title", "raw_body"}
     self.assertEqual(actual, expected)
Пример #4
0
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."
    )
Пример #5
0
def _check_editable_fields(cc_content, data, context):
    """
    Raise ValidationError if the given update data contains a field that is not
    in editable_fields.
    """
    editable_fields = get_editable_fields(cc_content, context)
    non_editable_errors = {
        field: ["This field is not editable."]
        for field in data.keys() if field not in editable_fields
    }
    if non_editable_errors:
        raise ValidationError(non_editable_errors)
Пример #6
0
def _check_editable_fields(cc_content, data, context):
    """
    Raise ValidationError if the given update data contains a field that is not
    in editable_fields.
    """
    editable_fields = get_editable_fields(cc_content, context)
    non_editable_errors = {
        field: ["This field is not editable."]
        for field in data.keys()
        if field not in editable_fields
    }
    if non_editable_errors:
        raise ValidationError(non_editable_errors)
Пример #7
0
 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_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)
Пример #9
0
 def get_editable_fields(self, obj):
     """Return the list of the fields the requester can edit"""
     return sorted(get_editable_fields(obj, self.context))
Пример #10
0
 def get_editable_fields(self, obj):
     """Return the list of the fields the requester can edit"""
     return sorted(get_editable_fields(obj, self.context))