feat: add organisations (#1820)

This commit is contained in:
David Nguyen
2025-06-10 11:49:52 +10:00
committed by GitHub
parent 0b37f19641
commit e6dc237ad2
631 changed files with 37616 additions and 25695 deletions

View File

@ -2,10 +2,8 @@ import { useLayoutEffect } from 'react';
import { Outlet, useLoaderData } from 'react-router';
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 { verifyEmbeddingPresignToken } from '@documenso/lib/server-only/embedding-presign/verify-embedding-presign-token';
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
import { TrpcProvider } from '@documenso/trpc/react';
import { ZBaseEmbedAuthoringSchema } from '~/types/embed-authoring-base-schema';
@ -27,39 +25,25 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
const result = await verifyEmbeddingPresignToken({ token }).catch(() => null);
let hasPlatformPlan = false;
let hasEnterprisePlan = false;
let hasCommunityPlan = false;
let allowEmbedAuthoringWhiteLabel = false;
if (result) {
[hasCommunityPlan, hasPlatformPlan, hasEnterprisePlan] = await Promise.all([
isCommunityPlan({
userId: result.userId,
teamId: result.teamId ?? undefined,
}),
isDocumentPlatform({
userId: result.userId,
teamId: result.teamId,
}),
isUserEnterprise({
userId: result.userId,
teamId: result.teamId ?? undefined,
}),
]);
const organisationClaim = await getOrganisationClaimByTeamId({
teamId: result.teamId,
});
allowEmbedAuthoringWhiteLabel = organisationClaim.flags.embedAuthoringWhiteLabel ?? false;
}
return {
hasValidToken: !!result,
token,
hasCommunityPlan,
hasPlatformPlan,
hasEnterprisePlan,
allowEmbedAuthoringWhiteLabel,
};
};
export default function AuthoringLayout() {
const { hasValidToken, token, hasCommunityPlan, hasPlatformPlan, hasEnterprisePlan } =
useLoaderData<typeof loader>();
const { hasValidToken, token, allowEmbedAuthoringWhiteLabel } = useLoaderData<typeof loader>();
useLayoutEffect(() => {
try {
@ -79,7 +63,7 @@ export default function AuthoringLayout() {
document.documentElement.classList.add('dark-mode-disabled');
}
if (hasCommunityPlan || hasPlatformPlan || hasEnterprisePlan) {
if (allowEmbedAuthoringWhiteLabel) {
injectCss({
css,
cssVars,

View File

@ -4,12 +4,9 @@ import { SigningStatus } from '@prisma/client';
import { useRevalidator } from 'react-router';
import { getOptionalSession } from '@documenso/auth/server/lib/utils/get-session';
import { isCommunityPlan as isUserCommunityPlan } 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 { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
import { getOrganisationClaimByTeamId } from '@documenso/lib/server-only/organisation/get-organisation-claims';
import { getRecipientByToken } from '@documenso/lib/server-only/recipient/get-recipient-by-token';
import { getTeamById } from '@documenso/lib/server-only/team/get-team';
import { BrandingLogo } from '~/components/general/branding-logo';
import { DocumentSigningAuthProvider } from '~/components/general/document-signing/document-signing-auth-provider';
@ -54,26 +51,10 @@ export async function loader({ request }: Route.LoaderArgs) {
});
}
const team = firstDocument.teamId
? await getTeamById({ teamId: firstDocument.teamId, userId: firstDocument.userId }).catch(
() => null,
)
: null;
const organisationClaim = await getOrganisationClaimByTeamId({ teamId: firstDocument.teamId });
const [isPlatformDocument, isEnterpriseDocument, isCommunityPlan] = await Promise.all([
isDocumentPlatform(firstDocument),
isUserEnterprise({
userId: firstDocument.userId,
teamId: firstDocument.teamId ?? undefined,
}),
isUserCommunityPlan({
userId: firstDocument.userId,
teamId: firstDocument.teamId ?? undefined,
}),
]);
const hidePoweredBy = team?.teamGlobalSettings?.brandingHidePoweredBy ?? false;
const allowWhitelabelling = isCommunityPlan || isPlatformDocument || isEnterpriseDocument;
const allowWhitelabelling = organisationClaim.flags.embedSigningWhiteLabel;
const hidePoweredBy = organisationClaim.flags.hidePoweredBy;
return superLoaderJson({
envelopes,