@@ -2771,9 +2771,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2771
2771
) : Promise < AdminGetListResult < WorkspaceAndInstance > > {
2772
2772
traceAPIParams ( ctx , { req } ) ;
2773
2773
2774
- await this . guardAdminAccess ( "adminGetWorkspaces" , { req } , Permission . ADMIN_WORKSPACES ) ;
2774
+ const admin = await this . guardAdminAccess ( "adminGetWorkspaces" , { req } , Permission . ADMIN_WORKSPACES ) ;
2775
2775
2776
- return await this . workspaceDb
2776
+ const wss = await this . workspaceDb
2777
2777
. trace ( ctx )
2778
2778
. findAllWorkspaceAndInstances (
2779
2779
req . offset ,
@@ -2782,12 +2782,27 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2782
2782
req . orderDir === "asc" ? "ASC" : "DESC" ,
2783
2783
req ,
2784
2784
) ;
2785
+
2786
+ await Promise . all (
2787
+ wss . rows . map ( async ( row ) => {
2788
+ if ( ! ( await this . auth . hasPermissionOnWorkspace ( admin . id , "access" , row . workspaceId ) ) ) {
2789
+ wss . total -- ;
2790
+ wss . rows = wss . rows . filter ( ( ws ) => ws . workspaceId !== row . workspaceId ) ;
2791
+ }
2792
+ } ) ,
2793
+ ) ;
2794
+ return wss ;
2785
2795
}
2786
2796
2787
2797
async adminGetWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < WorkspaceAndInstance > {
2788
2798
traceAPIParams ( ctx , { workspaceId } ) ;
2789
2799
2790
- await this . guardAdminAccess ( "adminGetWorkspace" , { id : workspaceId } , Permission . ADMIN_WORKSPACES ) ;
2800
+ const admin = await this . guardAdminAccess (
2801
+ "adminGetWorkspace" ,
2802
+ { id : workspaceId } ,
2803
+ Permission . ADMIN_WORKSPACES ,
2804
+ ) ;
2805
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "access" , workspaceId ) ;
2791
2806
2792
2807
const result = await this . workspaceDb . trace ( ctx ) . findWorkspaceAndInstance ( workspaceId ) ;
2793
2808
if ( ! result ) {
@@ -2799,7 +2814,12 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2799
2814
async adminGetWorkspaceInstances ( ctx : TraceContext , workspaceId : string ) : Promise < WorkspaceInstance [ ] > {
2800
2815
traceAPIParams ( ctx , { workspaceId } ) ;
2801
2816
2802
- await this . guardAdminAccess ( "adminGetWorkspaceInstances" , { id : workspaceId } , Permission . ADMIN_WORKSPACES ) ;
2817
+ const admin = await this . guardAdminAccess (
2818
+ "adminGetWorkspaceInstances" ,
2819
+ { id : workspaceId } ,
2820
+ Permission . ADMIN_WORKSPACES ,
2821
+ ) ;
2822
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "access" , workspaceId ) ;
2803
2823
2804
2824
const result = await this . workspaceDb . trace ( ctx ) . findInstances ( workspaceId ) ;
2805
2825
return result || [ ] ;
@@ -2813,6 +2833,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2813
2833
{ id : workspaceId } ,
2814
2834
Permission . ADMIN_WORKSPACES ,
2815
2835
) ;
2836
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "admin_control" , workspaceId ) ;
2816
2837
2817
2838
const workspace = await this . workspaceDb . trace ( ctx ) . findById ( workspaceId ) ;
2818
2839
if ( workspace ) {
@@ -2830,11 +2851,12 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2830
2851
async adminRestoreSoftDeletedWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < void > {
2831
2852
traceAPIParams ( ctx , { workspaceId } ) ;
2832
2853
2833
- await this . guardAdminAccess (
2854
+ const admin = await this . guardAdminAccess (
2834
2855
"adminRestoreSoftDeletedWorkspace" ,
2835
2856
{ id : workspaceId } ,
2836
2857
Permission . ADMIN_WORKSPACES ,
2837
2858
) ;
2859
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "admin_control" , workspaceId ) ;
2838
2860
2839
2861
await this . workspaceDb . trace ( ctx ) . transaction ( async ( db ) => {
2840
2862
const ws = await db . findById ( workspaceId ) ;
0 commit comments