feat: enable all users to create platform team (#17707)
* add extra checks for platform to make sure user is genuine * make slug unique for every team
This commit is contained in:
1 parent
0f3773d724
commit
f743db9eaa
2 files changed
+13
-2
No files matched your search
@@ -99,6 +99,8 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
id: true,
|
||||
role: true,
|
||||
email: true,
|
||||
completedOnboarding: true,
|
||||
emailVerified: true,
|
||||
teams: {
|
||||
select: {
|
||||
team: {
|
||||
@@ -116,6 +118,7 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
if (!loggedInUser) throw new TRPCError({ code: "UNAUTHORIZED", message: "You are not authorized." });
|
||||
|
||||
const IS_USER_ADMIN = loggedInUser.role === UserPermissionRole.ADMIN;
|
||||
const verifiedUser = loggedInUser.completedOnboarding && !!loggedInUser.emailVerified;
|
||||
|
||||
// We only allow creating an annual billing period if you are a system admin
|
||||
const billingPeriod = (IS_USER_ADMIN ? billingPeriodRaw : BillingPeriod.MONTHLY) ?? BillingPeriod.MONTHLY;
|
||||
@@ -131,7 +134,14 @@ export const createHandler = async ({ input, ctx }: CreateOptions) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (isNotACompanyEmail(orgOwnerEmail)) {
|
||||
if (isPlatform && !verifiedUser) {
|
||||
throw new TRPCError({
|
||||
code: "FORBIDDEN",
|
||||
message: "You need to complete onboarding before creating a platform team",
|
||||
});
|
||||
}
|
||||
|
||||
if (isNotACompanyEmail(orgOwnerEmail) && !isPlatform) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Use company email to create an organization" });
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user