chore: Relying on feature flag (#10162)
This commit is contained in:
1 parent
ef483a6520
commit
d5f3623377
8 files changed
+84
-5
No files matched your search
@@ -135,13 +135,12 @@ export const VerifyCodeDialog = ({
|
||||
);
|
||||
};
|
||||
|
||||
export const CreateANewOrganizationForm = () => {
|
||||
export const CreateANewOrganizationForm = ({ slug }: { slug?: string }) => {
|
||||
const { t, i18n } = useLocale();
|
||||
const router = useRouter();
|
||||
const telemetry = useTelemetry();
|
||||
const [serverErrorMessage, setServerErrorMessage] = useState<string | null>(null);
|
||||
const [showVerifyCode, setShowVerifyCode] = useState(false);
|
||||
const { slug } = router.query;
|
||||
|
||||
const newOrganizationFormMethods = useForm<{
|
||||
name: string;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { GetServerSidePropsContext } from "next";
|
||||
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { getFeatureFlagMap } from "@calcom/features/flags/server/utils";
|
||||
import { MembershipRole } from "@calcom/prisma/client";
|
||||
|
||||
export const getServerSideProps = async ({ req, res }: GetServerSidePropsContext) => {
|
||||
const prisma = await import("@calcom/prisma").then((mod) => mod.default);
|
||||
const flags = await getFeatureFlagMap(prisma);
|
||||
// Check if organizations are enabled
|
||||
if (flags["organizations"] !== true) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
// Check if logged in user has an organization assigned
|
||||
const session = await getServerSession({ req, res });
|
||||
if (!session?.user.organizationId) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
// Check if logged in user has OWNER/ADMIN role in organization
|
||||
const membership = await prisma.membership.findFirst({
|
||||
where: {
|
||||
userId: session?.user.id,
|
||||
teamId: session?.user.organizationId,
|
||||
},
|
||||
select: {
|
||||
role: true,
|
||||
},
|
||||
});
|
||||
if (!membership?.role || membership?.role === MembershipRole.MEMBER) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
// Otherwise, all good
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user