From 123c23d34e44a1541ff26aa0dd23157c120c1bf9 Mon Sep 17 00:00:00 2001 From: Brett Saviano Date: Wed, 29 May 2024 14:00:18 -0400 Subject: [PATCH] Don't attempt to open the SMP in a Simple Browser for IRIS 2024.1+ (#223) --- src/api/getPortalUriWithToken.ts | 65 +++++++++++++++++++------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/api/getPortalUriWithToken.ts b/src/api/getPortalUriWithToken.ts index 297d77e..904a9ea 100644 --- a/src/api/getPortalUriWithToken.ts +++ b/src/api/getPortalUriWithToken.ts @@ -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;