Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

api: Update saved snippets edit endpoint.

Vector73d43c877a9116
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 462db6c8c0c..953adbdd602 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -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:
diff --git a/zerver/tests/test_saved_snippets.py b/zerver/tests/test_saved_snippets.py
index fafbb202a40..b6128602038 100644
--- a/zerver/tests/test_saved_snippets.py
+++ b/zerver/tests/test_saved_snippets.py
@@ -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(
diff --git a/zerver/views/saved_snippets.py b/zerver/views/saved_snippets.py
index 877df46bb9f..5c2288b1377 100644
--- a/zerver/views/saved_snippets.py
+++ b/zerver/views/saved_snippets.py
@@ -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)