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.

channel: Remove PATCH as POST workaround.

Anders Kaseorgc1a95b8ed6c8
diff --git a/web/src/channel.ts b/web/src/channel.ts
index eb61adbbc94..5aebb71d94a 100644
--- a/web/src/channel.ts
+++ b/web/src/channel.ts
@@ -24,11 +24,7 @@ type AjaxRequestHandlerOptions = Omit<JQuery.AjaxSettings, "success"> & {
error?: JQuery.Ajax.ErrorCallback<unknown>;
};
-type PatchRequestData =
- | {processData: false; data: FormData}
- | {processData?: true | undefined; data: Record<string, unknown>};
-
-export type AjaxRequestHandler = typeof call | typeof patch;
+export type AjaxRequestHandler = typeof call;
let password_change_in_progress = false;
export let password_changes = 0;
@@ -195,19 +191,9 @@ export function del(options: AjaxRequestHandlerOptions): JQuery.jqXHR<unknown> |
return call(args);
}
-export function patch(
- options: Omit<AjaxRequestHandlerOptions, "data"> & PatchRequestData,
-): JQuery.jqXHR<unknown> | undefined {
- // Send a PATCH as a POST in order to work around QtWebkit
- // (Linux/Windows desktop app) not supporting PATCH body.
- if (options.processData === false) {
- // If we're submitting a FormData object, we need to add the
- // method this way
- options.data.append("method", "PATCH");
- } else {
- options.data = {...options.data, method: "PATCH"};
- }
- return post(options);
+export function patch(options: AjaxRequestHandlerOptions): JQuery.jqXHR<unknown> | undefined {
+ const args = {type: "PATCH", dataType: "json", ...options};
+ return call(args);
}
export function xhr_error_message(message: string, xhr: JQuery.jqXHR<unknown>): string {
diff --git a/web/tests/channel.test.cjs b/web/tests/channel.test.cjs
index 2d5fe1b3413..2f0fa66676a 100644
--- a/web/tests/channel.test.cjs
+++ b/web/tests/channel.test.cjs
@@ -90,8 +90,7 @@ test("patch", () => {
},
check_ajax_options(options) {
- assert.equal(options.type, "POST");
- assert.equal(options.data.method, "PATCH");
+ assert.equal(options.type, "PATCH");
assert.equal(options.dataType, "json");
// Just make sure these don't explode.
@@ -197,38 +196,6 @@ test("normal_post", () => {
});
});
-test("patch_with_form_data", () => {
- let appended;
-
- const data = {
- append(k, v) {
- assert.equal(k, "method");
- assert.equal(v, "PATCH");
- appended = true;
- },
- };
-
- test_with_mock_ajax({
- run_code() {
- channel.patch({
- data,
- url: "/json/endpoint",
- processData: false,
- });
- assert.ok(appended);
- },
-
- check_ajax_options(options) {
- assert.equal(options.type, "POST");
- assert.equal(options.dataType, "json");
-
- // Just make sure these don't explode.
- options.simulate_success();
- options.simulate_error();
- },
- });
-});
-
test("authentication_error_401_is_spectator", () => {
test_with_mock_ajax({
xhr: xhr_401,