mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
login_to_access: Take user to web_public_compatible hash on exit.
We save the last web_public_compatible hash that user visited before the modal was shown and take user to that hash when user exits the modal.
This commit is contained in:
@@ -67,3 +67,14 @@ test("update internal hash if required", ({override}) => {
|
||||
// calls to stub.
|
||||
assert.equal(stub.num_calls, 1);
|
||||
});
|
||||
|
||||
test("web public view hash restore", () => {
|
||||
const allowed_hash = "#";
|
||||
browser_history.update(allowed_hash);
|
||||
assert.equal(location.hash, allowed_hash);
|
||||
const new_hash = "#narrow/is/private";
|
||||
browser_history.update(new_hash);
|
||||
assert.equal(location.hash, new_hash);
|
||||
browser_history.return_to_web_public_hash();
|
||||
assert.equal(location.hash, allowed_hash);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,13 @@ export const state = {
|
||||
hash_before_overlay: null,
|
||||
old_hash: window.location.hash,
|
||||
changing_hash: false,
|
||||
// If the spectator's hash changes to a restricted hash, then we store the old hash
|
||||
// so that we can take user back to the allowed hash.
|
||||
// TODO: Store #narrow old hashes. Currently they are not stored here since, the #narrow
|
||||
// hashes are changed without calling `hashchanged` in many ways.
|
||||
spectator_old_hash: hash_util.is_web_public_compatible(window.location.hash)
|
||||
? window.location.hash
|
||||
: "#",
|
||||
};
|
||||
|
||||
export function clear_for_testing() {
|
||||
@@ -73,3 +80,7 @@ export function update_hash_internally_if_required(hash) {
|
||||
update(hash);
|
||||
}
|
||||
}
|
||||
|
||||
export function return_to_web_public_hash() {
|
||||
window.location.hash = state.spectator_old_hash;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,15 @@ import * as user_profile from "./user_profile";
|
||||
import * as util from "./util";
|
||||
|
||||
export function initialize() {
|
||||
// SPECATORS LOGIN TO ACCESS MODAL
|
||||
|
||||
$("body").on("click hide", ".go_back_button", (e) => {
|
||||
browser_history.return_to_web_public_hash();
|
||||
$("#login_to_access_modal").modal("hide");
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
// MESSAGE CLICKING
|
||||
|
||||
function initialize_long_tap() {
|
||||
|
||||
@@ -318,6 +318,11 @@ function hashchanged(from_reload, e) {
|
||||
|
||||
const was_internal_change = browser_history.save_old_hash();
|
||||
|
||||
const is_hash_web_public_compatible = hash_util.is_web_public_compatible(current_hash);
|
||||
if (is_hash_web_public_compatible) {
|
||||
browser_history.state.spectator_old_hash = current_hash;
|
||||
}
|
||||
|
||||
if (was_internal_change) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -329,7 +334,6 @@ function hashchanged(from_reload, e) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const is_hash_web_public_compatible = hash_util.is_web_public_compatible(current_hash);
|
||||
if (page_params.is_spectator && !is_hash_web_public_compatible) {
|
||||
login_to_access.show();
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user