Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Fix browser history when redirecting deprecated URLs.
Sahil Batraee6bd4fbdfee
diff --git a/web/src/hashchange.ts b/web/src/hashchange.tsindex 83c8e264ba4..4691094eac2 100644--- a/web/src/hashchange.ts+++ b/web/src/hashchange.ts@@ -289,21 +289,36 @@ function do_hashchange_overlay(old_hash: string | undefined): void {}const coming_from_overlay = hash_parser.is_overlay_hash(old_hash);- if (section === "display-settings") {+ if (base === "settings" && section === "display-settings") {// Since display-settings was deprecated and replaced with preferences// #settings/display-settings is being redirected to #settings/preferences.section = "preferences";+ window.history.replaceState(+ null,+ "",+ browser_history.get_full_url("#settings/preferences"),+ );}- if (section === "bot-list-admin") {- // #organization/bot-list-admin is being redirected to #organization/bots.+ if (base === "organization" && section === "bot-list-admin") {+ // #organization/bot-list-admin is being redirected to #organization/bots/all-bots.section = "bots";- base = "organization";+ window.history.replaceState(+ null,+ "",+ browser_history.get_full_url("#organization/bots/all-bots"),+ );}- if (section === "user-list-admin") {- // #settings/user-list-admin is being redirected to #settings/users after it was renamed.+ if (base === "organization" && section === "user-list-admin") {+ // #organization/user-list-admin is being redirected to #organization/users/active+ // after it was renamed.section = "users";+ window.history.replaceState(+ null,+ "",+ browser_history.get_full_url("#organization/users/active"),+ );}- if (section === "your-bots") {+ if (base === "settings" && section === "your-bots") {// #settings/your-bots is being redirected to #organization/bots/your-bots.section = "bots";base = "organization";diff --git a/web/tests/hashchange.test.cjs b/web/tests/hashchange.test.cjsindex 9299d442dac..e665e0434e6 100644--- a/web/tests/hashchange.test.cjs+++ b/web/tests/hashchange.test.cjs@@ -374,6 +374,11 @@ run_test("hash_interactions", ({override, override_rewire}) => {[admin, "launch", ["users", "active"]],]);+ let fixed_url;+ override(history, "replaceState", (_state, _title, url) => {+ fixed_url = url;+ });+window.location.hash = "#organization/user-list-admin";// Check whether `user-list-admin` is redirect to `users`, we@@ -382,6 +387,7 @@ run_test("hash_interactions", ({override, override_rewire}) => {// the arguments passed to `admin.launch`.helper.clear_events();$window_stub.trigger("hashchange");+ assert.equal(fixed_url, "http://zulip.zulipdev.com/#organization/users/active");helper.assert_events([[overlays, "close_for_hash_change"],[settings, "build_page"],