mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
api: Update saved snippets edit endpoint.
If no data is provided to the `saved_snippets/{saved_snippet_id}:patch`
endpoint, do no-op instead of throwing error.
This commit is contained in:
@@ -6451,7 +6451,6 @@ paths:
|
||||
required: true
|
||||
example: 3
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/x-www-form-urlencoded:
|
||||
schema:
|
||||
@@ -6473,22 +6472,6 @@ paths:
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/SimpleSuccess"
|
||||
"400":
|
||||
description: Bad request.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/CodedError"
|
||||
- example:
|
||||
{
|
||||
"code": "BAD_REQUEST",
|
||||
"msg": "No new data is supplied",
|
||||
"result": "error",
|
||||
}
|
||||
description: |
|
||||
A typical failed JSON response for when neither title nor content is
|
||||
provided in the request:
|
||||
"404":
|
||||
description: Not Found.
|
||||
content:
|
||||
|
||||
@@ -67,10 +67,11 @@ class SavedSnippetTests(ZulipTestCase):
|
||||
)
|
||||
self.assert_json_success(result)
|
||||
|
||||
# No-op requests succeed.
|
||||
result = self.client_patch(
|
||||
f"/json/saved_snippets/{saved_snippet_id}",
|
||||
)
|
||||
self.assert_json_error(result, "No new data is supplied", status_code=400)
|
||||
self.assert_json_success(result)
|
||||
|
||||
# Tests if error is thrown when the provided ID does not exist.
|
||||
result = self.client_patch(
|
||||
|
||||
@@ -2,7 +2,6 @@ from typing import Annotated
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.utils.translation import gettext as _
|
||||
from pydantic import StringConstraints
|
||||
|
||||
from zerver.actions.saved_snippets import (
|
||||
@@ -11,7 +10,6 @@ from zerver.actions.saved_snippets import (
|
||||
do_edit_saved_snippet,
|
||||
do_get_saved_snippets,
|
||||
)
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import PathOnly, typed_endpoint
|
||||
from zerver.models import SavedSnippet, UserProfile
|
||||
@@ -68,7 +66,9 @@ def edit_saved_snippet(
|
||||
] = None,
|
||||
) -> HttpResponse:
|
||||
if title is None and content is None:
|
||||
raise JsonableError(_("No new data is supplied"))
|
||||
# No changes are requested; exit early to avoid sending a
|
||||
# spurious event to clients.
|
||||
return json_success(request)
|
||||
|
||||
do_edit_saved_snippet(saved_snippet_id, title, content, user_profile)
|
||||
return json_success(request)
|
||||
|
||||
Reference in New Issue
Block a user