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:
Vector73
2025-03-17 16:58:23 +00:00
committed by Tim Abbott
parent 9c5535f447
commit d43c877a91
3 changed files with 5 additions and 21 deletions

View File

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

View File

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

View File

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