@@ -842,11 +842,11 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
842
842
843
843
const user = await this . checkUser ( "getWorkspace" ) ;
844
844
845
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
846
- const latestInstancePromise = this . workspaceDb . trace ( ctx ) . findCurrentInstance ( workspaceId ) ;
845
+ const result = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
846
+ const { workspace, latestInstance } = result ;
847
+
847
848
const teamMembers = await this . organizationService . listMembers ( user . id , workspace . organizationId ) ;
848
849
await this . guardAccess ( { kind : "workspace" , subject : workspace , teamMembers : teamMembers } , "get" ) ;
849
- const latestInstance = await latestInstancePromise ;
850
850
if ( ! ! latestInstance ) {
851
851
await this . guardAccess (
852
852
{
@@ -860,8 +860,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
860
860
}
861
861
862
862
return {
863
- workspace ,
864
- latestInstance : this . censorInstance ( latestInstance ) ,
863
+ ... result ,
864
+ latestInstance : this . censorInstance ( result . latestInstance ) ,
865
865
} ;
866
866
}
867
867
@@ -872,10 +872,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
872
872
const user = await this . checkAndBlockUser ( "getOwnerToken" ) ;
873
873
874
874
//TODO this requests are only here to populate the resource guard check
875
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
876
- if ( ! workspace ) {
877
- throw new Error ( "owner token not found" ) ;
878
- }
875
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
879
876
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
880
877
881
878
const latestInstance = await this . workspaceService . getCurrentInstance ( user . id , workspaceId ) ;
@@ -891,7 +888,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
891
888
const user = await this . checkAndBlockUser ( "getIDECredentials" ) ;
892
889
893
890
//TODO this requests are only here to populate the resource guard check
894
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
891
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
895
892
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
896
893
897
894
return await this . workspaceService . getIDECredentials ( user . id , workspaceId ) ;
@@ -908,11 +905,10 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
908
905
const user = await this . checkAndBlockUser ( "startWorkspace" , undefined , { workspaceId } ) ;
909
906
910
907
// (gpl) We keep this check here for backwards compatibility, it should be superfluous in the future
911
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
908
+ const { workspace, latestInstance : instance } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
912
909
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
913
910
914
911
// (gpl) We keep this check here for backwards compatibility, it should be superfluous in the future
915
- const instance = await this . workspaceService . getCurrentInstance ( user . id , workspace . id ) ;
916
912
if ( instance && instance . status . phase !== "stopped" ) {
917
913
traceWI ( ctx , { instanceId : instance . id } ) ;
918
914
@@ -947,7 +943,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
947
943
const user = await this . checkUser ( "stopWorkspace" , undefined , { workspaceId } ) ;
948
944
const logCtx = { userId : user . id , workspaceId } ;
949
945
950
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
946
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
951
947
if ( workspace . type === "prebuild" ) {
952
948
// If this is a team prebuild, any team member can stop it.
953
949
const teamMembers = await this . organizationService . listMembers ( user . id , workspace . organizationId ) ;
@@ -1027,22 +1023,22 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1027
1023
1028
1024
const user = await this . checkAndBlockUser ( "updateWorkspaceUserPin" ) ;
1029
1025
1030
- const ws = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1031
- await this . guardAccess ( { kind : "workspace" , subject : ws } , "update" ) ;
1026
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1027
+ await this . guardAccess ( { kind : "workspace" , subject : workspace } , "update" ) ;
1032
1028
1033
1029
switch ( action ) {
1034
1030
case "pin" :
1035
- ws . pinned = true ;
1031
+ workspace . pinned = true ;
1036
1032
break ;
1037
1033
case "unpin" :
1038
- ws . pinned = false ;
1034
+ workspace . pinned = false ;
1039
1035
break ;
1040
1036
case "toggle" :
1041
- ws . pinned = ! ws . pinned ;
1037
+ workspace . pinned = ! workspace . pinned ;
1042
1038
break ;
1043
1039
}
1044
1040
1045
- await this . workspaceService . setPinned ( user . id , ws . id , ws . pinned ) ;
1041
+ await this . workspaceService . setPinned ( user . id , workspace . id , workspace . pinned ) ;
1046
1042
}
1047
1043
1048
1044
public async deleteWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < void > {
@@ -1051,8 +1047,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1051
1047
1052
1048
const user = await this . checkAndBlockUser ( "deleteWorkspace" ) ;
1053
1049
1054
- const ws = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1055
- await this . guardAccess ( { kind : "workspace" , subject : ws } , "delete" ) ;
1050
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1051
+ await this . guardAccess ( { kind : "workspace" , subject : workspace } , "delete" ) ;
1056
1052
1057
1053
await this . workspaceService . deleteWorkspace ( user . id , workspaceId , "user" ) ;
1058
1054
}
@@ -1063,7 +1059,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1063
1059
1064
1060
const user = await this . checkAndBlockUser ( "setWorkspaceDescription" ) ;
1065
1061
1066
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1062
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1067
1063
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "update" ) ;
1068
1064
1069
1065
await this . workspaceService . setDescription ( user . id , workspaceId , description ) ;
@@ -1077,22 +1073,17 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1077
1073
1078
1074
const user = await this . checkUser ( "getWorkspaces" ) ;
1079
1075
1080
- const res = await this . workspaceDb . trace ( ctx ) . find ( {
1081
- limit : 20 ,
1082
- ...options ,
1083
- userId : user . id ,
1084
- includeHeadless : false ,
1085
- } ) ;
1086
- await Promise . all ( res . map ( ( ws ) => this . guardAccess ( { kind : "workspace" , subject : ws . workspace } , "get" ) ) ) ;
1076
+ const result = await this . workspaceService . getWorkspaces ( user . id , options ) ;
1077
+ await Promise . all ( result . map ( ( ws ) => this . guardAccess ( { kind : "workspace" , subject : ws . workspace } , "get" ) ) ) ;
1087
1078
await Promise . all (
1088
- res . map ( ( ws ) =>
1079
+ result . map ( ( ws ) =>
1089
1080
this . guardAccess (
1090
1081
{ kind : "workspaceInstance" , subject : ws . latestInstance , workspace : ws . workspace } ,
1091
1082
"get" ,
1092
1083
) ,
1093
1084
) ,
1094
1085
) ;
1095
- return res ;
1086
+ return result ;
1096
1087
}
1097
1088
1098
1089
public async isWorkspaceOwner ( ctx : TraceContext , workspaceId : string ) : Promise < boolean > {
@@ -1101,7 +1092,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1101
1092
1102
1093
const user = await this . checkUser ( "isWorkspaceOwner" , undefined , { workspaceId } ) ;
1103
1094
1104
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1095
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1105
1096
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
1106
1097
return user . id == workspace . ownerId ;
1107
1098
}
@@ -1124,7 +1115,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1124
1115
1125
1116
const user = await this . checkUser ( "getWorkspaceOwner" ) ;
1126
1117
1127
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1118
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1128
1119
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
1129
1120
1130
1121
try {
@@ -1145,7 +1136,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1145
1136
1146
1137
const user = await this . checkAndBlockUser ( "getWorkspaceUsers" , undefined , { workspaceId } ) ;
1147
1138
1148
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1139
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1149
1140
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
1150
1141
1151
1142
// Note: there's no need to try and guard the users below, they're not complete users but just enough to
@@ -1798,7 +1789,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1798
1789
1799
1790
const user = await this . checkAndBlockUser ( "updateGitStatus" ) ;
1800
1791
1801
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1792
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1802
1793
const instance = await this . workspaceService . getCurrentInstance ( user . id , workspaceId ) ;
1803
1794
traceWI ( ctx , { instanceId : instance . id } ) ;
1804
1795
await this . guardAccess ( { kind : "workspaceInstance" , subject : instance , workspace } , "update" ) ;
@@ -1816,7 +1807,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1816
1807
1817
1808
const user = await this . checkAndBlockUser ( "openPort" ) ;
1818
1809
1819
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1810
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1820
1811
const runningInstance = await this . workspaceDb . trace ( ctx ) . findRunningInstance ( workspaceId ) ;
1821
1812
if ( ! runningInstance ) {
1822
1813
log . debug ( { userId : user . id , workspaceId } , "Cannot open port for workspace with no running instance" , {
@@ -1887,12 +1878,13 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1887
1878
} ) ;
1888
1879
}
1889
1880
1881
+ // TODO(gpl): Remove after FGA rollout
1890
1882
private async internGetCurrentWorkspaceInstance (
1891
1883
ctx : TraceContext ,
1892
1884
user : User ,
1893
1885
workspaceId : string ,
1894
1886
) : Promise < { workspace : Workspace ; instance : WorkspaceInstance | undefined } > {
1895
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1887
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1896
1888
1897
1889
const instance = await this . workspaceDb . trace ( ctx ) . findRunningInstance ( workspaceId ) ;
1898
1890
return { instance, workspace } ;
@@ -2017,7 +2009,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2017
2009
2018
2010
async getWorkspaceEnvVars ( ctx : TraceContext , workspaceId : string ) : Promise < EnvVarWithValue [ ] > {
2019
2011
const user = await this . checkUser ( "getWorkspaceEnvVars" ) ;
2020
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
2012
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
2021
2013
await this . guardAccess ( { kind : "workspace" , subject : workspace } , "get" ) ;
2022
2014
const envVars = await this . envVarService . resolveEnvVariables (
2023
2015
workspace . ownerId ,
0 commit comments