Skip to content

Scheduling infrastructure for absolutely everyone.

fix: restricting platform user from creating another regular org (#20929)

Romit Gabani7ee451ca0209
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json
index 82e8899ffd4..94f44f1f689 100644
--- a/apps/web/public/static/locales/en/common.json
+++ b/apps/web/public/static/locales/en/common.json
@@ -3011,6 +3011,7 @@
"you_need_to_have_minimum_published_teams": "You need to have minimum published teams",
"you_are_part_of_this_organization_already": "You are part of this organization already",
"you_are_part_of_another_organization_cannot_create_organization": "You are part of another organization, cannot create a new organization",
+ "you_are_part_of_another_platform_organization_cannot_create_organization": "You are part of another platform organization, cannot create a new organization",
"organization_payment_success": "Organization payment success",
"organization_payment_success_description": "Your organization has been created successfully",
"this_may_take_a_few_seconds": "This may take a few seconds...",
diff --git a/packages/features/ee/organizations/lib/server/orgCreationUtils.ts b/packages/features/ee/organizations/lib/server/orgCreationUtils.ts
index 33e012287e8..286ada189b9 100644
--- a/packages/features/ee/organizations/lib/server/orgCreationUtils.ts
+++ b/packages/features/ee/organizations/lib/server/orgCreationUtils.ts
@@ -75,6 +75,7 @@ type OrgOwner = {
slug: string | null;
isOrganization: boolean;
};
+ accepted: boolean;
}[];
completedOnboarding?: boolean;
emailVerified?: Date | null;
@@ -204,10 +205,19 @@ export async function assertCanCreateOrg({
});
// Let slug verification be done before it as that gives better error message if the user creating the org is already a part of the org(i.e. the org exist and he is a member)
- if (orgOwner.profile?.organizationId) {
+ const isPartOfAnotherOrg = !!orgOwner.profile?.organizationId;
+ if (isPartOfAnotherOrg) {
throw new OrgCreationError("you_are_part_of_another_organization_cannot_create_organization");
}
+ // for platform Organization we don't add org profile to orgOwner so we've to check membership to check if user is part of another platform organization.
+ const isPartOfAnotherPlatformOrg = orgOwner.teams.some(
+ (membership) => membership.team.isOrganization && membership.accepted
+ );
+ if (isPartOfAnotherPlatformOrg) {
+ throw new OrgCreationError("you_are_part_of_another_platform_organization_cannot_create_organization");
+ }
+
const hasExistingPlatformOrOrgTeam = orgOwner?.teams.find((team) => {
return team.team.isPlatform || team.team.isOrganization;
});
@@ -258,6 +268,7 @@ export const findUserToBeOrgOwner = async (email: string) => {
isPlatform: true,
},
},
+ accepted: true,
},
},
},