@@ -16,6 +16,8 @@ import { EmailAddressAlreadyTakenException, SelectAccountException } from "../au
1616import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth" ;
1717import { UserService } from "./user-service" ;
1818import { Authorizer } from "../authorization/authorizer" ;
19+ import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server" ;
20+ import { isOrganizationOwned , isAllowedToCreateOrganization } from "@gitpod/public-api-common/lib/user-utils" ;
1921
2022export interface CreateUserParams {
2123 organizationId ?: string ;
@@ -193,12 +195,26 @@ export class UserAuthentication {
193195 }
194196
195197 /**
196- * Only installation-level users are allowed to create/ join other orgs then the one they belong to
198+ * Only installation-level users are allowed to join other orgs then the one they belong to
197199 * @param user
198200 * @returns
199201 */
200- async mayCreateOrJoinOrganization ( user : User ) : Promise < boolean > {
201- return ! user . organizationId ;
202+ async mayJoinOrganization ( user : User ) : Promise < boolean > {
203+ return ! isOrganizationOwned ( user ) ;
204+ }
205+
206+ /**
207+ * gitpod.io: Only installation-level users are allowed to create orgs
208+ * Dedicated: Only if multiOrg is enabled, installation-level users (=admin-user) can create orgs
209+ * @param user
210+ * @returns
211+ */
212+ async mayCreateOrganization ( user : User ) : Promise < boolean > {
213+ const isDedicated = this . config . isDedicatedInstallation ;
214+ const isMultiOrgEnabled = await getExperimentsClientForBackend ( ) . getValueAsync ( "enable_multi_org" , false , {
215+ gitpodHost : this . config . hostUrl . url . host ,
216+ } ) ;
217+ return isAllowedToCreateOrganization ( user , isDedicated , isMultiOrgEnabled ) ;
202218 }
203219
204220 async isBlocked ( params : CheckIsBlockedParams ) : Promise < boolean > {
0 commit comments