forked from dubinc/dub
-
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.
Merge pull request dubinc#1371 from dubinc/cal
Cal 🤝 Dub
- Loading branch information
Showing
15 changed files
with
185 additions
and
124 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
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
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 was deleted.
Oops, something went wrong.
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,4 1,8 @@ | ||
import { isBlacklistedDomain, updateConfig } from "@/lib/edge-config"; | ||
import { | ||
getFeatureFlags, | ||
isBlacklistedDomain, | ||
updateConfig, | ||
} from "@/lib/edge-config"; | ||
import { getPangeaDomainIntel } from "@/lib/pangea"; | ||
import { checkIfUserExists, getRandomKey } from "@/lib/planetscale"; | ||
import { prisma } from "@/lib/prisma"; | ||
|
@@ -29,7 33,10 @@ export async function processLink<T extends Record<string, any>>({ | |
skipExternalIdChecks = false, // only skip when externalId doesn't change (e.g. when editing a link) | ||
}: { | ||
payload: NewLinkProps & T; | ||
workspace?: Pick<WorkspaceProps, "id" | "plan" | "conversionEnabled">; | ||
workspace?: Pick< | ||
WorkspaceProps, | ||
"id" | "plan" | "conversionEnabled" | "flags" | ||
>; | ||
userId?: string; | ||
bulk?: boolean; | ||
skipKeyChecks?: boolean; | ||
|
@@ -199,6 206,35 @@ export async function processLink<T extends Record<string, any>>({ | |
}; | ||
} | ||
|
||
if (domain === "cal.link") { | ||
const flags = await getFeatureFlags({ | ||
workspaceId: workspace?.id, | ||
}); | ||
if (!flags?.callink) { | ||
return { | ||
link: payload, | ||
error: | ||
"You can only use the cal.link domain if you have beta access to it. Contact [email protected] to get access.", | ||
code: "forbidden", | ||
}; | ||
} | ||
} | ||
|
||
if (key?.includes("/")) { | ||
// check if the user has access to the parent link | ||
const parentKey = key.split("/")[0]; | ||
const parentLink = await prisma.link.findUnique({ | ||
where: { domain_key: { domain, key: parentKey } }, | ||
}); | ||
if (parentLink?.userId !== userId) { | ||
return { | ||
link: payload, | ||
error: `You do not have access to create links in the ${domain}/${parentKey}/ subdirectory.`, | ||
code: "forbidden", | ||
}; | ||
} | ||
} | ||
|
||
// else, check if the domain belongs to the workspace | ||
} else if (!domains?.find((d) => d.slug === domain)) { | ||
return { | ||
|
Oops, something went wrong.