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.

support: Confirm the string_id before scrubbing the realm.

Vishnu KS3cf3f99cf9fb
diff --git a/frontend_tests/node_tests/support.js b/frontend_tests/node_tests/support.js
index da8fe898000..b81acc4ffb2 100644
--- a/frontend_tests/node_tests/support.js
+++ b/frontend_tests/node_tests/support.js
@@ -18,6 +18,37 @@ set_global("$", global.make_zjquery());
run_test("scrub_realm", () => {
jquery_init();
const click_handler = $("body").get_on_handler("click", ".scrub-realm-button");
+
+ const fake_this = $.create("fake-.scrub-realm-button");
+ fake_this.data = (name) => {
+ assert.equal(name, "string-id");
+ return "zulip";
+ };
+
+ let submit_form_called = false;
+ fake_this.form = {
+ submit: () => {
+ submit_form_called = true;
+ },
+ };
+ const event = {
+ preventDefault: () => {},
+ };
+
+ window.prompt = () => "zulip";
+ click_handler.call(fake_this, event);
+ assert(submit_form_called);
+
+ submit_form_called = false;
+ window.prompt = () => "invalid-string-id";
+ let alert_called = false;
+ window.alert = () => {
+ alert_called = true;
+ };
+ click_handler.call(fake_this, event);
+ assert(!submit_form_called);
+ assert(alert_called);
+
assert.equal(typeof click_handler, "function");
assert.equal(document.querySelectorAll(".scrub-realm-button").length, 1);
diff --git a/static/js/analytics/support.js b/static/js/analytics/support.js
index fdfb141a0f5..54527d0319e 100644
--- a/static/js/analytics/support.js
+++ b/static/js/analytics/support.js
@@ -3,14 +3,16 @@
$(() => {
$("body").on("click", ".scrub-realm-button", function (e) {
e.preventDefault();
- const string_id = $(this).data("string-id");
const message =
- 'Do you really want to scrub the realm "' +
- string_id +
- '"? This action is irreversible.';
+ "Confirm the string_id of the realm you want to scrub.\n\n WARNING! This action is irreversible!";
+ const actual_string_id = $(this).data("string-id");
// eslint-disable-next-line no-alert
- if (confirm(message)) {
+ const confirmed_string_id = window.prompt(message);
+ if (confirmed_string_id === actual_string_id) {
this.form.submit();
+ } else {
+ // eslint-disable-next-line no-alert
+ window.alert("The string_id you entered is not correct. Aborted.");
}
});