@@ -649,6 +649,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
649
649
public async maySetTimeout ( ctx : TraceContext ) : Promise < boolean > {
650
650
const user = await this . checkUser ( "maySetTimeout" ) ;
651
651
await this . guardAccess ( { kind : "user" , subject : user } , "get" ) ;
652
+ await this . auth . checkPermissionOnUser ( user . id , "read_info" , user . id ) ;
652
653
653
654
return await this . entitlementService . maySetTimeout ( user . id ) ;
654
655
}
@@ -874,13 +875,14 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
874
875
875
876
const user = await this . checkAndBlockUser ( "getOwnerToken" ) ;
876
877
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 ) ;
878
880
if ( ! workspace ) {
879
881
throw new Error ( "owner token not found" ) ;
880
882
}
881
883
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
882
884
883
- const latestInstance = await this . workspaceDb . trace ( ctx ) . findCurrentInstance ( workspaceId ) ;
885
+ const latestInstance = await this . workspaceService . getCurrentInstance ( user . id , workspaceId ) ;
884
886
await this . guardAccess ( { kind : "workspaceInstance" , subject : latestInstance , workspace } , "get" ) ;
885
887
886
888
return await this . workspaceService . getOwnerToken ( user . id , workspaceId ) ;
@@ -892,6 +894,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
892
894
893
895
const user = await this . checkAndBlockUser ( "getIDECredentials" ) ;
894
896
897
+ //TODO this requests are only here to populate the resource guard check
895
898
const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
896
899
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
897
900
@@ -913,18 +916,18 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
913
916
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
914
917
915
918
// (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 } ) ;
919
922
920
923
// We already have a running workspace.
921
924
// Note: ownership doesn't matter here as this is basically a noop. It's not StartWorkspace's concern
922
925
// to guard workspace access - just to prevent non-owners from starting workspaces.
923
926
924
- await this . guardAccess ( { kind : "workspaceInstance" , subject : runningInstance , workspace } , "get" ) ;
927
+ await this . guardAccess ( { kind : "workspaceInstance" , subject : instance , workspace } , "get" ) ;
925
928
return {
926
- instanceID : runningInstance . id ,
927
- workspaceURL : runningInstance . ideUrl ,
929
+ instanceID : instance . id ,
930
+ workspaceURL : instance . ideUrl ,
928
931
} ;
929
932
}
930
933
@@ -1028,24 +1031,22 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1028
1031
1029
1032
const user = await this . checkAndBlockUser ( "updateWorkspaceUserPin" ) ;
1030
1033
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" ) ;
1046
1036
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 ) ;
1049
1050
}
1050
1051
1051
1052
public async deleteWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < void > {
@@ -1057,9 +1058,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1057
1058
const ws = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1058
1059
await this . guardAccess ( { kind : "workspace" , subject : ws } , "delete" ) ;
1059
1060
1060
- // for good measure, try and stop running instances
1061
- await this . internalStopWorkspace ( ctx , user . id , ws , "deleted via API" ) ;
1062
-
1063
1061
await this . workspaceService . deleteWorkspace ( user . id , workspaceId , "user" ) ;
1064
1062
}
1065
1063
@@ -1070,9 +1068,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1070
1068
const user = await this . checkAndBlockUser ( "setWorkspaceDescription" ) ;
1071
1069
1072
1070
const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1073
-
1074
1071
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 ) ;
1076
1074
}
1077
1075
1078
1076
public async getWorkspaces (
0 commit comments