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

* restricting platform user from creating another regular org

* changed as suggested, additional check of membership is accepted

---------

Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
This commit is contained in:
Romit Gabani
2025-05-01 03:59:32 +00:00
committed by GitHub
co-authored by Hariom Balhara
parent 55b066c475
commit 7ee451ca02
2 changed files with 13 additions and 1 deletions
@@ -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...",
@@ -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,
},
},
},