@@ -76,6 +76,7 @@ import { PublicAPIConverter } from "@gitpod/public-api-common/lib/public-api-con
7676import { WatchWorkspaceStatusResponse } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb" ;
7777import { ContextParser } from "./context-parser-service" ;
7878import { scrubber , TrustedValue } from "@gitpod/gitpod-protocol/lib/util/scrubbing" ;
79+ import { WorkspacePermission } from "../authorization/definitions" ;
7980
8081export const GIT_STATUS_LENGTH_CAP_BYTES = 4096 ;
8182
@@ -304,13 +305,22 @@ export class WorkspaceService {
304305 }
305306
306307 // Internal method for allowing for additional DBs to be passed in
307- private async doGetWorkspace ( userId : string , workspaceId : string , db : WorkspaceDB = this . db ) : Promise < Workspace > {
308+ private async doGetWorkspace (
309+ userId : string ,
310+ workspaceId : string ,
311+ db : WorkspaceDB = this . db ,
312+ stopOnly : boolean = false ,
313+ ) : Promise < Workspace > {
308314 const workspace = await db . findById ( workspaceId ) ;
309315
310316 if ( workspace ?. type === "prebuild" && workspace . projectId ) {
311317 await this . auth . checkPermissionOnProject ( userId , "read_prebuild" , workspace . projectId ) ;
312318 } else {
313- await this . auth . checkPermissionOnWorkspace ( userId , "access" , workspaceId ) ;
319+ let effectivePermission : WorkspacePermission = "access" ;
320+ if ( stopOnly ) {
321+ effectivePermission = "stop" ;
322+ }
323+ await this . auth . checkPermissionOnWorkspace ( userId , effectivePermission , workspaceId ) ;
314324 }
315325
316326 // TODO(gpl) We might want to add || !!workspace.softDeleted here in the future, but we were unsure how that would affect existing clients
@@ -366,12 +376,13 @@ export class WorkspaceService {
366376 await this . auth . checkPermissionOnWorkspace ( userId , "stop" , workspaceId ) ;
367377 }
368378
369- const workspace = await this . doGetWorkspace ( userId , workspaceId ) ;
379+ const workspace = await this . doGetWorkspace ( userId , workspaceId , this . db , true ) ;
370380 const instance = await this . db . findRunningInstance ( workspace . id ) ;
371381 if ( ! instance ) {
372382 // there's no instance running - we're done
373383 return ;
374384 }
385+
375386 await this . workspaceStarter . stopWorkspaceInstance ( { } , instance . id , instance . region , reason , policy ) ;
376387 this . asyncUpdateDeletionEligibilityTime ( userId , workspaceId , true ) ;
377388 }
0 commit comments