File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,16 +88,22 @@ export async function authorizeWatchEnvironment(params: {
8888
8989 if ( ! environment ) return { ok : false , reason : "access_revoked" } ;
9090
91- // Primary for the same reason as the membership read above.
92- const user = await prisma . user . findFirst ( {
93- where : { id : params . userId } ,
94- select : { admin : true } ,
95- } ) ;
96- if ( ! user ) return { ok : false , reason : "access_revoked" } ;
91+ // The gate only reads `isAdmin` while the admin preview is on, so this read is skipped
92+ // otherwise: it runs on every watch check, batch authorization and sweep finalisation.
93+ let isAdmin = false ;
94+ if ( env . DASHBOARD_AGENT_ADMIN_PREVIEW === "1" ) {
95+ // Primary for the same reason as the membership read above.
96+ const user = await prisma . user . findFirst ( {
97+ where : { id : params . userId } ,
98+ select : { admin : true } ,
99+ } ) ;
100+ if ( ! user ) return { ok : false , reason : "access_revoked" } ;
101+ isAdmin = user . admin ;
102+ }
97103
98104 const allowed = await canAccessDashboardAgent ( {
99105 userId : params . userId ,
100- isAdmin : user . admin ,
106+ isAdmin,
101107 // A background check is never an impersonated session.
102108 isImpersonating : false ,
103109 organizationSlug : environment . organization . slug ,
You can’t perform that action at this time.
0 commit comments