fix: prevent creating multiple platform orgs (#16629)
* set error messages to know whats wrong * trying to find if org with same owner already exists * ensure a user cannot create more than one platform team --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
co-authored by
Anik Dhabal Babu
parent
e3e2bc804a
commit
a775e42e85
@@ -65,11 +65,13 @@ const CreateANewPlatformFormChild = ({ session }: { session: Ensure<SessionConte
|
||||
onError: (err) => {
|
||||
if (err.message === "organization_url_taken") {
|
||||
newOrganizationFormMethods.setError("slug", { type: "custom", message: t("url_taken") });
|
||||
setServerErrorMessage(err.message);
|
||||
} else if (err.message === "domain_taken_team" || err.message === "domain_taken_project") {
|
||||
newOrganizationFormMethods.setError("slug", {
|
||||
type: "custom",
|
||||
message: t("problem_registering_domain"),
|
||||
});
|
||||
setServerErrorMessage(err.message);
|
||||
} else {
|
||||
setServerErrorMessage(err.message);
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
team: {
|
||||
select: {
|
||||
slug: true,
|
||||
isOrganization: true,
|
||||
isPlatform: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -160,6 +162,14 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
if (hasAnOrgWithSameSlug || RESERVED_SUBDOMAINS.includes(slug))
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "organization_url_taken" });
|
||||
|
||||
const hasExistingPlatformOrOrgTeam = loggedInUser?.teams.find((team) => {
|
||||
return team.team.isPlatform || team.team.isOrganization;
|
||||
});
|
||||
|
||||
if (!!hasExistingPlatformOrOrgTeam?.team && isPlatform) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "User is already part of a team" });
|
||||
}
|
||||
|
||||
const availability = getAvailabilityFromSchedule(DEFAULT_SCHEDULE);
|
||||
|
||||
const isOrganizationConfigured = isPlatform ? true : await createDomain(slug);
|
||||
|
||||
Reference in New Issue
Block a user