This repository has been archived by the owner on Jan 23, 2024. It is now read-only.
forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support moving a user and it's teams to an org as temporary app…
…roach (calcom#11892)
- Loading branch information
1 parent
d46e80c
commit 225055f
Showing
9 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logger from "@calcom/lib/logger"; | ||
import { safeStringify } from "@calcom/lib/safeStringify"; | ||
import type { RedirectType } from "@calcom/prisma/client"; | ||
|
||
const log = logger.getChildLogger({ prefix: ["lib", "getTemporaryOrgRedirect"] }); | ||
export const getTemporaryOrgRedirect = async ({ | ||
slug, | ||
redirectType, | ||
eventTypeSlug, | ||
}: { | ||
slug: string; | ||
redirectType: RedirectType; | ||
eventTypeSlug: string | null; | ||
}) => { | ||
const prisma = (await import("@calcom/prisma")).default; | ||
log.debug( | ||
`Looking for redirect for`, | ||
safeStringify({ | ||
slug, | ||
redirectType, | ||
eventTypeSlug, | ||
}) | ||
); | ||
const redirect = await prisma.tempOrgRedirect.findUnique({ | ||
where: { | ||
from_type_fromOrgId: { | ||
type: redirectType, | ||
from: slug, | ||
fromOrgId: 0, | ||
}, | ||
}, | ||
}); | ||
|
||
if (redirect) { | ||
log.debug(`Redirecting ${slug} to ${redirect.toUrl}`); | ||
return { | ||
redirect: { | ||
permanent: false, | ||
destination: eventTypeSlug ? `${redirect.toUrl}/${eventTypeSlug}` : redirect.toUrl, | ||
}, | ||
} as const; | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
import type { GetServerSidePropsContext } from "next"; | ||
import withEmbedSsr from "@lib/withEmbedSsr"; | ||
|
||
import { getServerSideProps as _getServerSideProps } from "../[type]"; | ||
|
||
export { default } from "../[type]"; | ||
|
||
export const getServerSideProps = async (context: GetServerSidePropsContext) => { | ||
const ssrResponse = await _getServerSideProps(context); | ||
if (ssrResponse.notFound) { | ||
return ssrResponse; | ||
} | ||
return { | ||
...ssrResponse, | ||
props: { | ||
...ssrResponse.props, | ||
isEmbed: true, | ||
}, | ||
}; | ||
}; | ||
export const getServerSideProps = withEmbedSsr(_getServerSideProps); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/prisma/migrations/20231014180034_add_temp_org_redirect/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- CreateEnum | ||
CREATE TYPE "RedirectType" AS ENUM ('user-event-type', 'team-event-type', 'user', 'team'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "TempOrgRedirect" ( | ||
"id" SERIAL NOT NULL, | ||
"from" TEXT NOT NULL, | ||
"fromOrgId" INTEGER NOT NULL, | ||
"type" "RedirectType" NOT NULL, | ||
"toUrl" TEXT NOT NULL, | ||
"enabled" BOOLEAN NOT NULL DEFAULT true, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "TempOrgRedirect_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "TempOrgRedirect_from_type_fromOrgId_key" ON "TempOrgRedirect"("from", "type", "fromOrgId"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters