feat: embed authoring part two (#1768)

This commit is contained in:
Lucas Smith
2025-05-01 23:32:56 +10:00
committed by GitHub
parent bdb0b0ea88
commit 12ada567f5
28 changed files with 1267 additions and 269 deletions

View File

@ -1,10 +1,10 @@
import { isCommunityPlan } from '@documenso/ee/server-only/util/is-community-plan';
import { isUserEnterprise } from '@documenso/ee/server-only/util/is-document-enterprise';
import { isDocumentPlatform } from '@documenso/ee/server-only/util/is-document-platform';
import { IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { createEmbeddingPresignToken } from '@documenso/lib/server-only/embedding-presign/create-embedding-presign-token';
import { getApiTokenByToken } from '@documenso/lib/server-only/public-api/get-api-token-by-token';
import { prisma } from '@documenso/prisma';
import { procedure } from '../trpc';
import {
@ -42,13 +42,24 @@ export const createEmbeddingPresignTokenRoute = procedure
});
}
const [hasCommunityPlan, hasPlatformPlan, hasEnterprisePlan] = await Promise.all([
const [hasCommunityPlan, hasEnterprisePlan] = await Promise.all([
isCommunityPlan({ userId: token.userId, teamId: token.teamId ?? undefined }),
isDocumentPlatform({ userId: token.userId, teamId: token.teamId }),
isUserEnterprise({ userId: token.userId, teamId: token.teamId ?? undefined }),
]);
if (!hasCommunityPlan && !hasPlatformPlan && !hasEnterprisePlan) {
let hasTeamAuthoringFlag = false;
if (token.teamId) {
const teamGlobalSettings = await prisma.teamGlobalSettings.findFirst({
where: {
teamId: token.teamId,
},
});
hasTeamAuthoringFlag = teamGlobalSettings?.allowEmbeddedAuthoring ?? false;
}
if (!hasCommunityPlan && !hasEnterprisePlan && !hasTeamAuthoringFlag) {
throw new AppError(AppErrorCode.UNAUTHORIZED, {
message: 'You do not have permission to create embedding presign tokens',
});