File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -393,7 +393,16 @@ export const verifyApiKey = async (apiKeyPayload: ApiKeyPayload): Promise<{ apiK
393393
394394export const createApiKey = async ( name : string , domain : string ) : Promise < { key : string } | ServiceError > => sew ( ( ) =>
395395 withAuth ( ( userId ) =>
396- withOrgMembership ( userId , domain , async ( { org } ) => {
396+ withOrgMembership ( userId , domain , async ( { org, userRole } ) => {
397+ if ( env . EXPERIMENT_DISABLE_API_KEY_CREATION_FOR_NON_ADMIN_USERS === 'true' && userRole !== OrgRole . OWNER ) {
398+ logger . error ( `API key creation is disabled for non-admin users. User ${ userId } is not an owner.` ) ;
399+ return {
400+ statusCode : StatusCodes . FORBIDDEN ,
401+ errorCode : ErrorCode . INSUFFICIENT_PERMISSIONS ,
402+ message : "API key creation is disabled for non-admin users." ,
403+ } satisfies ServiceError ;
404+ }
405+
397406 const existingApiKey = await prisma . apiKey . findFirst ( {
398407 where : {
399408 createdById : userId ,
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export const env = createEnv({
1818
1919 // Auth
2020 FORCE_ENABLE_ANONYMOUS_ACCESS : booleanSchema . default ( 'false' ) ,
21-
21+
2222 AUTH_SECRET : z . string ( ) ,
2323 AUTH_URL : z . string ( ) . url ( ) ,
2424 AUTH_CREDENTIALS_LOGIN_ENABLED : booleanSchema . default ( 'true' ) ,
@@ -130,10 +130,12 @@ export const env = createEnv({
130130
131131 SOURCEBOT_DEMO_EXAMPLES_PATH : z . string ( ) . optional ( ) ,
132132
133+ // Experimental Environment Variables
134+ // @note : These environment variables are subject to change at any time and are not garunteed to be backwards compatible.
135+ EXPERIMENT_DISABLE_API_KEY_CREATION_FOR_NON_ADMIN_USERS : booleanSchema . default ( 'false' ) ,
133136 EXPERIMENT_SELF_SERVE_REPO_INDEXING_ENABLED : booleanSchema . default ( 'false' ) ,
134137 // @NOTE : Take care to update actions.ts when changing the name of this.
135138 EXPERIMENT_SELF_SERVE_REPO_INDEXING_GITHUB_TOKEN : z . string ( ) . optional ( ) ,
136-
137139 EXPERIMENT_EE_PERMISSION_SYNC_ENABLED : booleanSchema . default ( 'false' ) ,
138140 } ,
139141 // @NOTE : Please make sure of the following:
You can’t perform that action at this time.
0 commit comments