@@ -649,6 +649,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
649649 public async maySetTimeout ( ctx : TraceContext ) : Promise < boolean > {
650650 const user = await this . checkUser ( "maySetTimeout" ) ;
651651 await this . guardAccess ( { kind : "user" , subject : user } , "get" ) ;
652+ await this . auth . checkPermissionOnUser ( user . id , "read_info" , user . id ) ;
652653
653654 return await this . entitlementService . maySetTimeout ( user . id ) ;
654655 }
@@ -874,13 +875,14 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
874875
875876 const user = await this . checkAndBlockUser ( "getOwnerToken" ) ;
876877
877- const workspace = await this . workspaceDb . trace ( ctx ) . findById ( workspaceId ) ;
878+ //TODO this requests are only here to populate the resource guard check
879+ const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
878880 if ( ! workspace ) {
879881 throw new Error ( "owner token not found" ) ;
880882 }
881883 await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
882884
883- const latestInstance = await this . workspaceDb . trace ( ctx ) . findCurrentInstance ( workspaceId ) ;
885+ const latestInstance = await this . workspaceService . getCurrentInstance ( user . id , workspaceId ) ;
884886 await this . guardAccess ( { kind : "workspaceInstance" , subject : latestInstance , workspace } , "get" ) ;
885887
886888 return await this . workspaceService . getOwnerToken ( user . id , workspaceId ) ;
@@ -892,6 +894,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
892894
893895 const user = await this . checkAndBlockUser ( "getIDECredentials" ) ;
894896
897+ //TODO this requests are only here to populate the resource guard check
895898 const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
896899 await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
897900
@@ -913,18 +916,18 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
913916 await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
914917
915918 // (gpl) We keep this check here for backwards compatibility, it should be superfluous in the future
916- const runningInstance = await this . workspaceDb . trace ( ctx ) . findRunningInstance ( workspace . id ) ;
917- if ( runningInstance ) {
918- traceWI ( ctx , { instanceId : runningInstance . id } ) ;
919+ const instance = await this . workspaceService . getCurrentInstance ( user . id , workspace . id ) ;
920+ if ( instance && instance . status . phase !== "stopped" ) {
921+ traceWI ( ctx , { instanceId : instance . id } ) ;
919922
920923 // We already have a running workspace.
921924 // Note: ownership doesn't matter here as this is basically a noop. It's not StartWorkspace's concern
922925 // to guard workspace access - just to prevent non-owners from starting workspaces.
923926
924- await this . guardAccess ( { kind : "workspaceInstance" , subject : runningInstance , workspace } , "get" ) ;
927+ await this . guardAccess ( { kind : "workspaceInstance" , subject : instance , workspace } , "get" ) ;
925928 return {
926- instanceID : runningInstance . id ,
927- workspaceURL : runningInstance . ideUrl ,
929+ instanceID : instance . id ,
930+ workspaceURL : instance . ideUrl ,
928931 } ;
929932 }
930933
@@ -1028,24 +1031,22 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
10281031
10291032 const user = await this . checkAndBlockUser ( "updateWorkspaceUserPin" ) ;
10301033
1031- await this . workspaceDb . trace ( ctx ) . transaction ( async ( db ) => {
1032- const ws = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1033- await this . guardAccess ( { kind : "workspace" , subject : ws } , "update" ) ;
1034-
1035- switch ( action ) {
1036- case "pin" :
1037- ws . pinned = true ;
1038- break ;
1039- case "unpin" :
1040- ws . pinned = false ;
1041- break ;
1042- case "toggle" :
1043- ws . pinned = ! ws . pinned ;
1044- break ;
1045- }
1034+ const ws = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1035+ await this . guardAccess ( { kind : "workspace" , subject : ws } , "update" ) ;
10461036
1047- await db . store ( ws ) ;
1048- } ) ;
1037+ switch ( action ) {
1038+ case "pin" :
1039+ ws . pinned = true ;
1040+ break ;
1041+ case "unpin" :
1042+ ws . pinned = false ;
1043+ break ;
1044+ case "toggle" :
1045+ ws . pinned = ! ws . pinned ;
1046+ break ;
1047+ }
1048+
1049+ await this . workspaceService . setPinned ( user . id , ws . id , ws . pinned ) ;
10491050 }
10501051
10511052 public async deleteWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < void > {
@@ -1057,9 +1058,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
10571058 const ws = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
10581059 await this . guardAccess ( { kind : "workspace" , subject : ws } , "delete" ) ;
10591060
1060- // for good measure, try and stop running instances
1061- await this . internalStopWorkspace ( ctx , user . id , ws , "deleted via API" ) ;
1062-
10631061 await this . workspaceService . deleteWorkspace ( user . id , workspaceId , "user" ) ;
10641062 }
10651063
@@ -1070,9 +1068,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
10701068 const user = await this . checkAndBlockUser ( "setWorkspaceDescription" ) ;
10711069
10721070 const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1073-
10741071 await this . guardAccess ( { kind : "workspace" , subject : workspace } , "update" ) ;
1075- await this . workspaceDb . trace ( ctx ) . updatePartial ( workspaceId , { description } ) ;
1072+
1073+ await this . workspaceService . setDescription ( user . id , workspaceId , description ) ;
10761074 }
10771075
10781076 public async getWorkspaces (
0 commit comments