11import type { Context } from 'hono' ;
22
3+ import configuration , { getTrueForgeMode , isOidcConfigured , TrueForgeMode } from '../config' ;
4+
5+ /** TrueFoundry Control Plane role treated as admin until mapping is settled. */
6+ export const TRUEFOUNDRY_ADMIN_ROLE = 'tenant-admin' ;
7+
8+ /** Standalone / default TrueForge admin role string. */
9+ export const STANDALONE_ADMIN_ROLE = 'admin' ;
10+
311export interface RequestSubject {
412 id : string ;
513 type : string ;
@@ -21,7 +29,7 @@ export const STANDALONE_REQUEST_CONTEXT: RequestContext = {
2129 type : 'user' ,
2230 display_name : 'trueforge-default' ,
2331 } ,
24- roles : [ 'admin' ] ,
32+ roles : [ STANDALONE_ADMIN_ROLE ] ,
2533 user_credential : null ,
2634} ;
2735
@@ -41,7 +49,25 @@ export function resolveRequestContext(c: Context): RequestContext {
4149 return requestContext ;
4250}
4351
44- /** Whether the caller holds the TrueForge admin role (`admin`). */
52+ /**
53+ * Whether the caller is treated as admin for settings, capabilities, and schedule bypass.
54+ * Mode and OIDC admin claim value come from process config ({@link getTrueForgeMode}).
55+ * - Standalone: `roles` includes `admin`
56+ * - OIDC: `roles` includes configured `OIDC_ADMIN_ROLE_VALUE`
57+ * - TrueFoundry: `roles` includes `tenant-admin` (temporary; revisit mapping later)
58+ */
4559export function hasAdminRole ( requestContext : Pick < RequestContext , 'roles' > ) : boolean {
46- return requestContext . roles . includes ( 'admin' ) ;
60+ switch ( getTrueForgeMode ( ) ) {
61+ case TrueForgeMode . TrueFoundry :
62+ // TODO: stop treating `tenant-admin` as TrueForge admin once TFY role mapping is settled.
63+ return requestContext . roles . includes ( TRUEFOUNDRY_ADMIN_ROLE ) ;
64+ case TrueForgeMode . Oidc : {
65+ const adminValue = isOidcConfigured ( configuration )
66+ ? configuration . OIDC . OIDC_ADMIN_ROLE_VALUE
67+ : STANDALONE_ADMIN_ROLE ;
68+ return requestContext . roles . includes ( adminValue ) ;
69+ }
70+ case TrueForgeMode . Standalone :
71+ return requestContext . roles . includes ( STANDALONE_ADMIN_ROLE ) ;
72+ }
4773}
0 commit comments