@@ -2234,15 +2234,26 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2234
2234
this . checkAndBlockUser ( "getPrebuild" ) ;
2235
2235
2236
2236
const pbws = await this . workspaceDb . trace ( ctx ) . findPrebuiltWorkspaceById ( prebuildId ) ;
2237
- const info = ( await this . workspaceDb . trace ( ctx ) . findPrebuildInfos ( [ prebuildId ] ) ) [ 0 ] ;
2237
+ if ( ! pbws ) {
2238
+ return undefined ;
2239
+ }
2240
+ const [ info , workspace ] = await Promise . all ( [
2241
+ this . workspaceDb
2242
+ . trace ( ctx )
2243
+ . findPrebuildInfos ( [ prebuildId ] )
2244
+ . then ( ( infos ) => ( infos . length > 0 ? infos [ 0 ] : undefined ) ) ,
2245
+ this . workspaceDb . trace ( ctx ) . findById ( pbws . buildWorkspaceId ) ,
2246
+ ] ) ;
2247
+ if ( ! info || ! workspace ) {
2248
+ return undefined ;
2249
+ }
2238
2250
2239
- if ( info && pbws ) {
2240
- const result : PrebuildWithStatus = { info, status : pbws . state } ;
2241
- if ( pbws . error ) {
2242
- result . error = pbws . error ;
2243
- }
2244
- return result ;
2251
+ await this . guardAccess ( { kind : "prebuild" , subject : pbws , workspace, teamMembers : undefined } , "get" ) ;
2252
+ const result : PrebuildWithStatus = { info, status : pbws . state } ;
2253
+ if ( pbws . error ) {
2254
+ result . error = pbws . error ;
2245
2255
}
2256
+ return result ;
2246
2257
}
2247
2258
2248
2259
public async findPrebuildByWorkspaceID (
@@ -2251,7 +2262,17 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2251
2262
) : Promise < PrebuiltWorkspace | undefined > {
2252
2263
traceAPIParams ( ctx , { workspaceId } ) ;
2253
2264
this . checkAndBlockUser ( "findPrebuildByWorkspaceID" ) ;
2254
- return this . workspaceDb . trace ( ctx ) . findPrebuildByWorkspaceID ( workspaceId ) ;
2265
+
2266
+ const [ pbws , workspace ] = await Promise . all ( [
2267
+ this . workspaceDb . trace ( ctx ) . findPrebuildByWorkspaceID ( workspaceId ) ,
2268
+ this . workspaceDb . trace ( ctx ) . findById ( workspaceId ) ,
2269
+ ] ) ;
2270
+ if ( ! pbws || ! workspace ) {
2271
+ return undefined ;
2272
+ }
2273
+
2274
+ await this . guardAccess ( { kind : "prebuild" , subject : pbws , workspace, teamMembers : undefined } , "get" ) ;
2275
+ return pbws ;
2255
2276
}
2256
2277
2257
2278
public async getProjectOverview ( ctx : TraceContext , projectId : string ) : Promise < Project . Overview | undefined > {
0 commit comments