Skip to content

Commit

Permalink
HPCC-30983 Honour direct URLs to ECL Watch
Browse files Browse the repository at this point in the history
Bypass the user nominated selection when direct URLs are provided.

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed Dec 11, 2023
1 parent bf67c4f commit 161548e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 58 deletions.
20 changes: 3 additions & 17 deletions esp/src/eclwatch/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ define([

"src/Utility",
"src/Session",
"src/KeyValStore",
"src/BuildInfo",
"hpcc/LockDialogWidget",

"dojox/html/entities",
Expand All @@ -22,28 +20,16 @@ define([
"css!hpcc/css/hpcc.css"

], function (fx, dom, domStyle, ioQuery, ready, lang, arrayUtil, topic,
Utility, Session, KeyValStore, BuildInfo, LockDialogWidget,
Utility, Session, LockDialogWidget,
entities, Toaster) {

Session.initSession();

const params = ioQuery.queryToObject(dojo.doc.location.search.substr((dojo.doc.location.search.substr(0, 1) === "?" ? 1 : 0)));
const hpccWidget = params.Widget ? params.Widget : "HPCCPlatformWidget";

const store = KeyValStore.userKeyValStore();
store.getEx(BuildInfo.ModernMode, { defaultValue: String(BuildInfo.containerized) }).then(modernMode => {
if (modernMode === String(true) && hpccWidget !== "IFrameWidget") {
switch (hpccWidget) {
case "WUDetailsWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}`);
break;
case "GraphsWUWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}/metrics`);
break;
default:
window.location.replace("/esp/files/index.html");
}
} else {
Session.needsRedirectV5().then(redirected => {
if (!redirected) {
ready(function () {
parseUrl();
initUI();
Expand Down
77 changes: 39 additions & 38 deletions esp/src/src-react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as React from "react";
import * as ReactDOM from "react-dom";
import { initializeIcons } from "@fluentui/react";
import { scopedLogger } from "@hpcc-js/util";
import { cookieKeyValStore, userKeyValStore } from "src/KeyValStore";
import { containerized, ModernMode } from "src/BuildInfo";
import { cookieKeyValStore } from "src/KeyValStore";
import { needsRedirectV9 } from "src/Session";
import { ECLWatchLogger } from "./hooks/logging";
import { replaceUrl } from "./util/history";

Expand Down Expand Up @@ -32,42 +32,43 @@ dojoConfig.urlInfo = {
};
dojoConfig.disableLegacyHashing = true;

const store = userKeyValStore();
store.getEx(ModernMode, { defaultValue: String(containerized) }).then(async modernMode => {
if (modernMode === String(false)) {
window.location.replace("/esp/files/stub.htm");
needsRedirectV9().then(async redirected => {
if (!redirected) {
loadUI();
}
});

async function loadUI() {
const authTypeResp = await fetch("/esp/getauthtype");
const authType = await authTypeResp?.text() ?? "None";
const userStore = cookieKeyValStore();
const userSession = await userStore.getAll();
if (authType.indexOf("None") < 0 && (userSession["ESPSessionState"] === "false" || userSession["ECLWatchUser"] === "false" || (!userSession["Status"] || userSession["Status"] === "Locked"))) {
if (window.location.hash.indexOf("login") < 0) {
replaceUrl("/login");
}
import("./components/forms/Login").then(_ => {
try {
ReactDOM.render(
<_.Login />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
});
} else {
const authTypeResp = await fetch("/esp/getauthtype");
const authType = await authTypeResp?.text() ?? "None";
const userStore = cookieKeyValStore();
const userSession = await userStore.getAll();
if (authType.indexOf("None") < 0 && (userSession["ESPSessionState"] === "false" || userSession["ECLWatchUser"] === "false" || (!userSession["Status"] || userSession["Status"] === "Locked"))) {
if (window.location.hash.indexOf("login") < 0) {
replaceUrl("/login");
import("./components/Frame").then(_ => {
try {
ReactDOM.render(
<_.Frame />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
import("./components/forms/Login").then(_ => {
try {
ReactDOM.render(
<_.Login />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
});
} else {
import("./components/Frame").then(_ => {
try {
ReactDOM.render(
<_.Frame />,
document.getElementById("placeholder")
);
document.getElementById("loadingOverlay").remove();
} catch (e) {
logger.error(e);
}
});
}
});
}
});
}
75 changes: 72 additions & 3 deletions esp/src/src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import * as xhr from "dojo/request/xhr";
import * as topic from "dojo/topic";
import { format as d3Format } from "@hpcc-js/common";
import { SMCService } from "@hpcc-js/comms";
import { cookieKeyValStore } from "src/KeyValStore";
import { cookieKeyValStore, sessionKeyValStore, userKeyValStore } from "src/KeyValStore";
import { singletonDebounce } from "../src-react/util/throttle";
import { parseSearch } from "../src-react/util/history";
import { ModernMode } from "./BuildInfo";
import * as ESPUtil from "./ESPUtil";
import { scopedLogger } from "@hpcc-js/util";

Expand All @@ -20,7 +22,74 @@ let _prevReset = Date.now();

declare const dojoConfig;

const userStore = cookieKeyValStore();
const cookieStore = cookieKeyValStore();
const sessionStore = sessionKeyValStore();
const userStore = userKeyValStore();

export async function fetchModernMode(): Promise<string> {
return Promise.all([
sessionStore.get(ModernMode),
userStore.getEx(ModernMode, { defaultValue: String(true) })
]).then(([sessionModernMode, userModernMode]) => {
return sessionModernMode ?? userModernMode;
});
}

const isV5DirectURL = () => !!parseSearch(window.location.search)?.["Widget"];
const isV9DirectURL = () => window.location.hash && window.location.hash.indexOf("#/stub/") !== 0;

export async function needsRedirectV5(): Promise<boolean> {
if (isV9DirectURL()) {
window.location.replace(`/esp/files/index.html${window.location.hash}`);
return true;
}
if (isV5DirectURL()) {
return false;
}

const v9Mode = await fetchModernMode() === String(true);
if (v9Mode) {
const params = parseSearch(window.location.search);
if (params?.["hpccWidget"] !== "IFrameWidget") {
switch (params?.["hpccWidget"]) {
case "WUDetailsWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}`);
break;
case "GraphsWUWidget":
window.location.replace(`/esp/files/index.html#/workunits/${params.Wuid}/metrics`);
break;
case "TopologyWidget":
case "DiskUsageWidget":
case "TargetClustersQueryWidget":
case "ClusterProcessesQueryWidget":
case "SystemServersQueryWidget":
case "LogWidget":
return false;
default:
window.location.replace("/esp/files/index.html");
}
return true;
}
}
return false;
}

export async function needsRedirectV9(): Promise<boolean> {
if (isV5DirectURL()) {
window.location.replace(`/esp/files/stub.htm${window.location.search}`);
return true;
}
if (isV9DirectURL()) {
return false;
}

const v5Mode = await fetchModernMode() === String(false);
if (v5Mode) {
window.location.replace(`/esp/files/stub.htm${window.location.search}`);
return true;
}
return false;
}

const smc = new SMCService({ baseUrl: "" });

Expand Down Expand Up @@ -95,7 +164,7 @@ export function fireIdle() {
}

async function resetESPTime() {
const userSession = userStore.getAll();
const userSession = cookieStore.getAll();
if (!userSession || !userSession["ECLWatchUser"] || !userSession["Status"] || userSession["Status"] === "Locked") return;
if (Date.now() - _prevReset > SESSION_RESET_FREQ) {
_prevReset = Date.now();
Expand Down

0 comments on commit 161548e

Please sign in to comment.