Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't attempt to open the SMP in a Simple Browser for IRIS 2024.1+ #223

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions src/api/getPortalUriWithToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,63 @@ export async function getPortalUriWithToken(
const spec: IServerSpec | undefined = await myApi.getServerSpec(name, scope);
if (typeof spec !== "undefined") {

// Retrieve previously cached token
let token = allTokens[target].get(name) || "";

// Revalidate and extend existing token, or obtain a new one
const response = await makeRESTRequest(
"POST",
spec,
{ apiVersion: 1, namespace, path: "/action/query" },
{ query: "select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token", parameters: [page, token] },
);

if (!response) {
// User will have to enter credentials
token = "";
allTokens[target].delete(name);
} else {
token = response.data?.result?.content[0]?.token || "";
allTokens[target].set(name, token);
}

if (target === BrowserTarget.SIMPLE && !simpleBrowserCompatible.has(name)) {
// Check that the portal webapps have all been altered so they don't require session cookie support, which Simple Browser cannot provide
const response = await makeRESTRequest(
"POST",
spec,
{ apiVersion: 1, namespace: "%SYS", path: "/action/query" },
{ query: "SELECT Name FROM Security.Applications WHERE {fn CONCAT(Name, '/')} %STARTSWITH '/csp/sys/' AND UseCookies = 2" },
{
query:
"SELECT Name FROM Security.Applications WHERE {fn CONCAT(Name, '/')} %STARTSWITH '/csp/sys/' AND UseCookies = 2 " +
"UNION SELECT $PIECE($PIECE($PIECE($ZVERSION,') ',2),' '),'.') AS Name"
},
);
if (response) {
const appsRequiringCookie = (response.data?.result?.content as any[]).map((row) => {
return row.Name as string;
});
if (appsRequiringCookie.length > 0) {
await vscode.window.showWarningMessage(`Portal web apps cannot be used in the Simple Browser tab if their 'UseCookies' property is set to 'Always' (the default). To resolve this, use Portal's security section to change it to 'Autodetect' in these apps: ${appsRequiringCookie.join(", ")}`, { modal: true });
return;
if (appsRequiringCookie.length && parseInt(appsRequiringCookie[appsRequiringCookie.length - 1], 10) >= 2024) {
// SMP in 2024.1+ can't be embedded in a cross-origin iframe
vscode.window.showWarningMessage(`The Portal cannot be opened in the Simple Browser for IRIS versions 2024.1+.`, "Dismiss");
simpleBrowserCompatible.set(name, false);
}
else if (appsRequiringCookie.length > 1) {
vscode.window.showWarningMessage(`Portal web apps cannot be used in the Simple Browser tab if their 'UseCookies' property is set to 'Always' (the default). To resolve this, use Portal's security section to change it to 'Autodetect' in these apps: ${appsRequiringCookie.slice(0, -1).join(", ")}`, { modal: true });
}
else {
simpleBrowserCompatible.set(name, true);
}
}
else {
vscode.window.showWarningMessage(`Unable to check the Portal web apps for compatibility with Simple Browser.`);
simpleBrowserCompatible.set(name, true);
vscode.window.showWarningMessage(`Unable to check the Portal web apps for compatibility with Simple Browser.`, "Dismiss");
}
if (!simpleBrowserCompatible.get(name)) return;
}

if (target === BrowserTarget.SIMPLE && simpleBrowserCompatible.has(name) && !simpleBrowserCompatible.get(name)) {
vscode.window.showWarningMessage(`The Portal cannot be opened in the Simple Browser for IRIS versions 2024.1+.`, "Dismiss");
return;
}

// Retrieve previously cached token
let token = allTokens[target].get(name) || "";

// Revalidate and extend existing token, or obtain a new one
const response = await makeRESTRequest(
"POST",
spec,
{ apiVersion: 1, namespace, path: "/action/query" },
{ query: "select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token", parameters: [page, token] },
);

if (!response) {
// User will have to enter credentials
token = "";
allTokens[target].delete(name);
} else {
token = response.data?.result?.content[0]?.token || "";
allTokens[target].set(name, token);
}

const webServer = spec.webServer;
Expand Down
Loading