mirror of
https://github.com/documenso/documenso.git
synced 2026-07-24 00:43:40 +10:00
chore: remove unnecessary constant extraction and defensive optional chaining
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { isPublicDocumentAccessEnabled } from '@documenso/lib/universal/document-access';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { maybeAuthenticatedProcedure } from '../trpc';
|
||||
@@ -62,15 +63,15 @@ const handleGetEnvelopeItemsByToken = async ({
|
||||
envelopeId: string;
|
||||
token: string;
|
||||
}) => {
|
||||
const isQrToken = token.startsWith('qr_');
|
||||
|
||||
const envelope = await prisma.envelope.findFirst({
|
||||
where: {
|
||||
id: envelopeId,
|
||||
type: EnvelopeType.DOCUMENT, // You cannot get template envelope items by token.
|
||||
recipients: {
|
||||
some: {
|
||||
token,
|
||||
},
|
||||
},
|
||||
type: EnvelopeType.DOCUMENT,
|
||||
...(isQrToken
|
||||
? { qrToken: token, status: DocumentStatus.COMPLETED }
|
||||
: { recipients: { some: { token } } }),
|
||||
},
|
||||
include: {
|
||||
envelopeItems: {
|
||||
@@ -78,6 +79,20 @@ const handleGetEnvelopeItemsByToken = async ({
|
||||
documentData: true,
|
||||
},
|
||||
},
|
||||
team: {
|
||||
include: {
|
||||
teamGlobalSettings: {
|
||||
select: { allowPublicCompletedDocumentAccess: true },
|
||||
},
|
||||
organisation: {
|
||||
include: {
|
||||
organisationGlobalSettings: {
|
||||
select: { allowPublicCompletedDocumentAccess: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -87,6 +102,12 @@ const handleGetEnvelopeItemsByToken = async ({
|
||||
});
|
||||
}
|
||||
|
||||
if (isQrToken && !isPublicDocumentAccessEnabled(envelope.team)) {
|
||||
throw new AppError(AppErrorCode.UNAUTHORIZED, {
|
||||
message: 'Public completed-document access is disabled',
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
envelopeItems: envelope.envelopeItems,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user