mirror of https://github.com/zulip/zulip.git
js: Convert static/js/csrf.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
38ffd47b90
commit
a05899f1b5
|
@ -122,7 +122,6 @@
|
|||
{
|
||||
"files": ["static/js/**"],
|
||||
"globals": {
|
||||
"csrf_token": false,
|
||||
"current_msg_list": true,
|
||||
"home_msg_list": false,
|
||||
"StripeCheckout": false,
|
||||
|
|
|
@ -1021,7 +1021,6 @@ test_ui("initialize", (override) => {
|
|||
$("#compose #attach_files").addClass("notdisplayed");
|
||||
|
||||
set_global("document", "document-stub");
|
||||
set_global("csrf_token", "fake-csrf-token");
|
||||
|
||||
page_params.max_file_upload_size_mib = 512;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ const upload = mock_esm("../../static/js/upload");
|
|||
mock_esm("../../static/js/resize", {
|
||||
watch_manual_resize() {},
|
||||
});
|
||||
set_global("csrf_token", "fake-csrf-token");
|
||||
set_global("document", {
|
||||
execCommand() {
|
||||
return false;
|
||||
|
|
|
@ -32,6 +32,7 @@ stub_templates((name, data) => {
|
|||
const channel = mock_esm("../../static/js/channel");
|
||||
const overlays = mock_esm("../../static/js/overlays");
|
||||
|
||||
mock_esm("../../static/js/csrf", {csrf_token: "token-stub"});
|
||||
mock_esm("../../static/js/list_widget", {
|
||||
create: () => ({init: noop}),
|
||||
});
|
||||
|
@ -49,7 +50,6 @@ mock_esm("../../static/js/ui_report", {
|
|||
},
|
||||
});
|
||||
|
||||
set_global("csrf_token", "token-stub");
|
||||
set_global("FormData", _FormData);
|
||||
|
||||
const settings_config = zrequire("settings_config");
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const {mock_cjs, set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {mock_cjs, mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
const $ = require("../zjsunit/zjquery");
|
||||
const {page_params} = require("../zjsunit/zpage_params");
|
||||
|
@ -14,7 +14,6 @@ set_global("navigator", {
|
|||
userAgent: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
|
||||
});
|
||||
page_params.max_file_upload_size = 25;
|
||||
set_global("csrf_token", "csrf_token");
|
||||
|
||||
// Setting these up so that we can test that links to uploads within messages are
|
||||
// automatically converted to server relative links.
|
||||
|
@ -34,6 +33,8 @@ Uppy.Plugin = {
|
|||
};
|
||||
mock_cjs("@uppy/core", Uppy);
|
||||
|
||||
mock_esm("../../static/js/csrf", {csrf_token: "csrf_token"});
|
||||
|
||||
const compose_ui = zrequire("compose_ui");
|
||||
const compose_actions = zrequire("compose_actions");
|
||||
const upload = zrequire("upload");
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
/* eslint-env commonjs */
|
||||
import $ from "jquery";
|
||||
|
||||
"use strict";
|
||||
export let csrf_token;
|
||||
|
||||
const $ = require("jquery");
|
||||
|
||||
let csrf_token;
|
||||
$(() => {
|
||||
// This requires that we used Jinja2's {% csrf_input %} somewhere on the page.
|
||||
const csrf_input = $('input[name="csrfmiddlewaretoken"]');
|
||||
if (csrf_input.length > 0) {
|
||||
csrf_token = csrf_input.attr("value");
|
||||
} else {
|
||||
csrf_token = undefined;
|
||||
}
|
||||
window.csrf_token = csrf_token;
|
||||
|
||||
csrf_token = csrf_input.attr("value");
|
||||
if (csrf_token === undefined) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
// remove each declaration when the corresponding module is migrated
|
||||
// to TS.
|
||||
|
||||
declare let csrf_token: any;
|
||||
declare let current_msg_list: any;
|
||||
declare let home_msg_list: any;
|
||||
declare let zulip_test: any;
|
||||
|
|
|
@ -5,6 +5,7 @@ import * as blueslip from "./blueslip";
|
|||
import * as compose from "./compose";
|
||||
import * as compose_actions from "./compose_actions";
|
||||
import * as compose_state from "./compose_state";
|
||||
import {csrf_token} from "./csrf";
|
||||
import * as hashchange from "./hashchange";
|
||||
import {localstorage} from "./localstorage";
|
||||
import * as message_list from "./message_list";
|
||||
|
|
|
@ -9,6 +9,7 @@ import * as avatar from "./avatar";
|
|||
import * as blueslip from "./blueslip";
|
||||
import * as channel from "./channel";
|
||||
import * as common from "./common";
|
||||
import {csrf_token} from "./csrf";
|
||||
import {i18n} from "./i18n";
|
||||
import * as overlays from "./overlays";
|
||||
import {page_params} from "./page_params";
|
||||
|
|
|
@ -10,6 +10,7 @@ import render_settings_edit_outgoing_webhook_service from "../templates/settings
|
|||
import * as avatar from "./avatar";
|
||||
import * as bot_data from "./bot_data";
|
||||
import * as channel from "./channel";
|
||||
import {csrf_token} from "./csrf";
|
||||
import {DropdownListWidget as dropdown_list_widget} from "./dropdown_list_widget";
|
||||
import {i18n} from "./i18n";
|
||||
import * as loading from "./loading";
|
||||
|
|
|
@ -6,6 +6,7 @@ import render_settings_admin_realm_domains_list from "../templates/settings/admi
|
|||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as channel from "./channel";
|
||||
import {csrf_token} from "./csrf";
|
||||
import {DropdownListWidget as dropdown_list_widget} from "./dropdown_list_widget";
|
||||
import {i18n} from "./i18n";
|
||||
import * as loading from "./loading";
|
||||
|
|
|
@ -7,6 +7,7 @@ import * as compose from "./compose";
|
|||
import * as compose_actions from "./compose_actions";
|
||||
import * as compose_state from "./compose_state";
|
||||
import * as compose_ui from "./compose_ui";
|
||||
import {csrf_token} from "./csrf";
|
||||
import {i18n} from "./i18n";
|
||||
import {page_params} from "./page_params";
|
||||
|
||||
|
|
Loading…
Reference in New Issue