mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
channel: Remove PATCH as POST workaround.
Fixes part of #1403. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
8f6c376835
commit
c1a95b8ed6
@@ -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 {
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user