@@ -10,12 +10,13 @@ import {
1010import { connectionTarget , terminalWithDocker , currentFile } from "../utils" ;
1111import { mainCommandMenu , mainSourceControlMenu } from "./studio" ;
1212import { AtelierAPI } from "../api" ;
13+ import { getCSPToken } from "../utils/getCSPToken" ;
1314
14- type ServerAction = { detail : string ; id : string ; label : string } ;
15+ type ServerAction = { detail : string ; id : string ; label : string ; rawLink ?: string } ;
1516export async function serverActions ( ) : Promise < void > {
1617 const { apiTarget, configName : workspaceFolder } = connectionTarget ( ) ;
1718 const api = new AtelierAPI ( apiTarget ) ;
18- const { active, host = "" , ns = "" , https, port = 0 , pathPrefix, username , password , docker } = api . config ;
19+ const { active, host = "" , ns = "" , https, port = 0 , pathPrefix, docker } = api . config ;
1920 const explorerCount = ( await explorerProvider . getChildren ( ) ) . length ;
2021 if ( ! explorerCount && ( ! docker || host === "" ) ) {
2122 await vscode . commands . executeCommand ( "ObjectScriptExplorer.focus" ) ;
@@ -70,29 +71,24 @@ export async function serverActions(): Promise<void> {
7071 const file = currentFile ( ) ;
7172 const classname = file && file . name . toLowerCase ( ) . endsWith ( ".cls" ) ? file . name . slice ( 0 , - 4 ) : "" ;
7273 const classnameEncoded = encodeURIComponent ( classname ) ;
73- const connInfo = `${ host } :${ port } [${ nsEncoded } ]` ;
74+ const connInfo = `${ host } :${ port } ${ pathPrefix } [${ nsEncoded } ]` ;
7475 const serverUrl = `${ https ? "https" : "http" } ://${ host } :${ port } ${ pathPrefix } ` ;
75- const portalUrl = `${ serverUrl } /csp/sys/UtilHome.csp?$NAMESPACE=${ nsEncoded } ` ;
76- const classRef = `${ serverUrl } /csp/documatic/%25CSP.Documatic.cls?LIBRARY=${ nsEncoded } ${
76+ const portalPath = `/csp/sys/UtilHome.csp?$NAMESPACE=${ nsEncoded } ` ;
77+ const classRef = `/csp/documatic/%25CSP.Documatic.cls?LIBRARY=${ nsEncoded } ${
7778 classname ? "&CLASSNAME=" + classnameEncoded : ""
7879 } `;
79- const iris = workspaceState . get ( workspaceFolder + ":iris" , false ) ;
80- const usernameEncoded = encodeURIComponent ( username ) ;
81- const passwordEncoded = encodeURIComponent ( password ) ;
82- const auth = iris
83- ? `&IRISUsername=${ usernameEncoded } &IRISPassword=${ passwordEncoded } `
84- : `&CacheUserName=${ usernameEncoded } &CachePassword=${ passwordEncoded } ` ;
8580 let extraLinks = 0 ;
8681 for ( const title in links ) {
87- let link = String ( links [ title ] ) ;
88- if ( classname == "" && ( link . includes ( "${classname}" ) || link . includes ( "${classnameEncoded}" ) ) ) {
82+ const rawLink = String ( links [ title ] ) ;
83+ // Skip link if it requires a classname and we don't currently have one
84+ if ( classname == "" && ( rawLink . includes ( "${classname}" ) || rawLink . includes ( "${classnameEncoded}" ) ) ) {
8985 continue ;
9086 }
91- link = link
87+ const link = rawLink
9288 . replace ( "${host}" , host )
9389 . replace ( "${port}" , port . toString ( ) )
9490 . replace ( "${serverUrl}" , serverUrl )
95- . replace ( "${serverAuth}" , auth )
91+ . replace ( "${serverAuth}" , "" )
9692 . replace ( "${ns}" , nsEncoded )
9793 . replace ( "${namespace}" , ns == "%SYS" ? "sys" : nsEncoded . toLowerCase ( ) )
9894 . replace ( "${classname}" , classname )
@@ -101,6 +97,7 @@ export async function serverActions(): Promise<void> {
10197 id : "extraLink" + extraLinks ++ ,
10298 label : title ,
10399 detail : link ,
100+ rawLink,
104101 } ) ;
105102 }
106103 if ( workspaceState . get ( workspaceFolder + ":docker" , false ) ) {
@@ -113,12 +110,12 @@ export async function serverActions(): Promise<void> {
113110 actions . push ( {
114111 id : "openPortal" ,
115112 label : "Open Management Portal" ,
116- detail : portalUrl ,
113+ detail : serverUrl + portalPath ,
117114 } ) ;
118115 actions . push ( {
119116 id : "openClassReference" ,
120117 label : "Open Class Reference" + ( classname ? ` for ${ classname } ` : "" ) ,
121- detail : classRef ,
118+ detail : serverUrl + classRef ,
122119 } ) ;
123120 if (
124121 ! vscode . window . activeTextEditor ||
@@ -141,17 +138,21 @@ export async function serverActions(): Promise<void> {
141138 placeHolder : `Select action for server: ${ connInfo } ` ,
142139 } )
143140 . then ( connectionActionsHandler )
144- . then ( ( action ) => {
141+ . then ( async ( action ) => {
145142 if ( ! action ) {
146143 return ;
147144 }
148145 switch ( action . id ) {
149146 case "openPortal" : {
150- vscode . env . openExternal ( vscode . Uri . parse ( portalUrl + auth ) ) ;
147+ const token = await getCSPToken ( api , portalPath ) ;
148+ const urlString = `${ serverUrl } ${ portalPath } &CSPCHD=${ token } ` ;
149+ vscode . env . openExternal ( vscode . Uri . parse ( urlString ) ) ;
151150 break ;
152151 }
153152 case "openClassReference" : {
154- vscode . env . openExternal ( vscode . Uri . parse ( classRef + auth ) ) ;
153+ const token = await getCSPToken ( api , classRef ) ;
154+ const urlString = `${ serverUrl } ${ classRef } &CSPCHD=${ token } ` ;
155+ vscode . env . openExternal ( vscode . Uri . parse ( urlString ) ) ;
155156 break ;
156157 }
157158 case "openDockerTerminal" : {
@@ -167,7 +168,15 @@ export async function serverActions(): Promise<void> {
167168 break ;
168169 }
169170 default : {
170- vscode . env . openExternal ( vscode . Uri . parse ( action . detail ) ) ;
171+ let urlString = action . detail ;
172+ if ( action . rawLink ?. startsWith ( "${serverUrl}" ) ) {
173+ const path = vscode . Uri . parse ( urlString ) . path ;
174+ const token = await getCSPToken ( api , path ) ;
175+ if ( token . length > 0 ) {
176+ urlString += `&CSPCHD=${ token } ` ;
177+ }
178+ }
179+ vscode . env . openExternal ( vscode . Uri . parse ( urlString ) ) ;
171180 }
172181 }
173182 } ) ;
0 commit comments