mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
feat: add template enhancements (#1154)
## Description General enhancements for templates. ## Changes Made Added the following changes to the template flow: - Allow adding document meta settings - Allow adding email settings - Allow adding document access & action authentication - Allow adding recipient action authentication - Save the state between template steps similar to how it works for documents Other changes: - Extract common fields between document and template flows - Remove the title field from "Use template" since we now have it as part of the template flow - Add new API endpoint for generating templates ## Testing Performed Added E2E tests for templates and creating documents from templates
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Template" ADD COLUMN "authOptions" JSONB;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "TemplateMeta" (
|
||||
"id" TEXT NOT NULL,
|
||||
"subject" TEXT,
|
||||
"message" TEXT,
|
||||
"timezone" TEXT DEFAULT 'Etc/UTC',
|
||||
"password" TEXT,
|
||||
"dateFormat" TEXT DEFAULT 'yyyy-MM-dd hh:mm a',
|
||||
"templateId" INTEGER NOT NULL,
|
||||
"redirectUrl" TEXT,
|
||||
|
||||
CONSTRAINT "TemplateMeta_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "TemplateMeta_templateId_key" ON "TemplateMeta"("templateId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "TemplateMeta" ADD CONSTRAINT "TemplateMeta_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "Template"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@ -539,15 +539,29 @@ enum TemplateType {
|
||||
PRIVATE
|
||||
}
|
||||
|
||||
model TemplateMeta {
|
||||
id String @id @default(cuid())
|
||||
subject String?
|
||||
message String?
|
||||
timezone String? @default("Etc/UTC") @db.Text
|
||||
password String?
|
||||
dateFormat String? @default("yyyy-MM-dd hh:mm a") @db.Text
|
||||
templateId Int @unique
|
||||
template Template @relation(fields: [templateId], references: [id], onDelete: Cascade)
|
||||
redirectUrl String?
|
||||
}
|
||||
|
||||
model Template {
|
||||
id Int @id @default(autoincrement())
|
||||
type TemplateType @default(PRIVATE)
|
||||
id Int @id @default(autoincrement())
|
||||
type TemplateType @default(PRIVATE)
|
||||
title String
|
||||
userId Int
|
||||
teamId Int?
|
||||
authOptions Json?
|
||||
templateMeta TemplateMeta?
|
||||
templateDocumentDataId String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
team Team? @relation(fields: [teamId], references: [id], onDelete: Cascade)
|
||||
templateDocumentData DocumentData @relation(fields: [templateDocumentDataId], references: [id], onDelete: Cascade)
|
||||
|
||||
@ -2,6 +2,7 @@ import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
import { prisma } from '..';
|
||||
import type { Prisma, User } from '../client';
|
||||
import { DocumentDataType, ReadStatus, RecipientRole, SendStatus, SigningStatus } from '../client';
|
||||
|
||||
const examplePdf = fs
|
||||
@ -14,6 +15,32 @@ type SeedTemplateOptions = {
|
||||
teamId?: number;
|
||||
};
|
||||
|
||||
type CreateTemplateOptions = {
|
||||
key?: string | number;
|
||||
createTemplateOptions?: Partial<Prisma.TemplateUncheckedCreateInput>;
|
||||
};
|
||||
|
||||
export const seedBlankTemplate = async (owner: User, options: CreateTemplateOptions = {}) => {
|
||||
const { key, createTemplateOptions = {} } = options;
|
||||
|
||||
const documentData = await prisma.documentData.create({
|
||||
data: {
|
||||
type: DocumentDataType.BYTES_64,
|
||||
data: examplePdf,
|
||||
initialData: examplePdf,
|
||||
},
|
||||
});
|
||||
|
||||
return await prisma.template.create({
|
||||
data: {
|
||||
title: `[TEST] Template ${key}`,
|
||||
templateDocumentDataId: documentData.id,
|
||||
userId: owner.id,
|
||||
...createTemplateOptions,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const seedTemplate = async (options: SeedTemplateOptions) => {
|
||||
const { title = 'Untitled', userId, teamId } = options;
|
||||
|
||||
|
||||
19
packages/prisma/types/template.ts
Normal file
19
packages/prisma/types/template.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type {
|
||||
DocumentData,
|
||||
Field,
|
||||
Recipient,
|
||||
Template,
|
||||
TemplateMeta,
|
||||
} from '@documenso/prisma/client';
|
||||
|
||||
export type TemplateWithData = Template & {
|
||||
templateDocumentData?: DocumentData | null;
|
||||
templateMeta?: TemplateMeta | null;
|
||||
};
|
||||
|
||||
export type TemplateWithDetails = Template & {
|
||||
templateDocumentData: DocumentData;
|
||||
templateMeta: TemplateMeta | null;
|
||||
Recipient: Recipient[];
|
||||
Field: Field[];
|
||||
};
|
||||
Reference in New Issue
Block a user