Skip to content

Commit

Permalink
Move iframe escape logic to onAdminPanelLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Jan 21, 2025
1 parent 09cba15 commit 57e5908
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
7 changes: 0 additions & 7 deletions src/meshweb/static/admin/iframe_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ async function checkIframed() {

// If we are, do nothing
if (inIframe) {
// ...Unless the iframe is at the login page, in which case, redirect the parent
// to the login
const iframeLocation = window.location.href;
if (iframeLocation.includes("login")) {
window.top.location.href = "/admin/login/";
}

return;
}

Expand Down
17 changes: 12 additions & 5 deletions src/meshweb/static/admin/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,25 @@ async function updateMapLocation(url) {
// Helper function to wrap everything that needs to happen when the admin panel
// loads
async function onAdminPanelLoad() {
const adminPanelIframeUrl = admin_panel_iframe.contentWindow.location.href;
const adminPanelIframeUrl = new URL(admin_panel_iframe.contentWindow.location.href);

// If the admin panel iframe leaves the admin panel (by logging out, going to homescreen, etc)
// we should leave this iframed view and go there.
const escURLs = ["login", "password_reset"]
var shouldEscape = escURLs.some(url => adminPanelIframeUrl.pathname.includes(url));
if (!adminPanelIframeUrl.pathname.includes("admin") || shouldEscape) {
window.location.href = adminPanelIframeUrl;
}

// Save the new admin location. We do this here because it means that the admin panel has
// recently reloaded.
const adminPanelIframeLastPageVisited = new URL(adminPanelIframeUrl).pathname;
localStorage.setItem(MESHDB_LAST_PAGE_VISITED, adminPanelIframeLastPageVisited);
localStorage.setItem(MESHDB_LAST_PAGE_VISITED, adminPanelIframeUrl.pathname);

// Update the URL bar in the browser for viz
window.history.pushState("MeshDB Admin Panel", "", adminPanelIframeLastPageVisited);
window.history.pushState("MeshDB Admin Panel", "", adminPanelIframeUrl.pathname);

// Finally, update the map view
updateMapLocation(adminPanelIframeUrl);
updateMapLocation(adminPanelIframeUrl.toString());
}

// Configures the listener that updates the map based on admin panel activity
Expand Down

0 comments on commit 57e5908

Please sign in to comment.