feat: Attribute document creation to the auth type it was made with

This commit is contained in:
Tom Moor committed 2026-08-05 20:11:00 -04:00
1 parent 81d9bed9ba
commit 6eeb7ebe1b
3 files changed
+13 -4

No files matched your search

+5 -1
View File
@@ -1,3 +1,4 @@
import { AuthenticationType } from "@shared/types";
import { ProsemirrorHelper } from "@server/models/helpers/ProsemirrorHelper";
import {
buildUser,
@@ -317,7 +318,10 @@ describe("documentCreator", () => {
);
expect(document.importId).toBe(fileOperation.id);
expect(document.sourceMetadata).toEqual(sourceMetadata);
expect(document.sourceMetadata).toEqual({
...sourceMetadata,
authType: AuthenticationType.APP,
});
});
});
+6 -2
View File
@@ -173,10 +173,14 @@ export default async function documentCreator(
lastModifiedById,
}: Props
): Promise<Document> {
const { user } = ctx.state.auth;
const { user, type: authType } = ctx.state.auth;
const { transaction } = ctx.state;
const templateId = template ? template.id : undefined;
const eventData = importId || apiImportId ? { source: "import" } : undefined;
// Note authType is applied last so that it always reflects the current
// request, even when metadata is inherited from another document.
const metadata =
authType || sourceMetadata ? { ...sourceMetadata, authType } : null;
if (state && template) {
throw new Error(
@@ -227,7 +231,7 @@ export default async function documentCreator(
publishedAt,
importId,
apiImportId,
sourceMetadata,
sourceMetadata: metadata,
fullWidth: fullWidth ?? template?.fullWidth,
icon: icon ?? template?.icon,
color: color ?? template?.color,
+2 -1
View File
@@ -1,5 +1,5 @@
import { randomUUID } from "node:crypto";
import { MentionType } from "@shared/types";
import { AuthenticationType, MentionType } from "@shared/types";
import { createContext } from "@server/context";
import env from "@server/env";
import { sequelize } from "@server/storage/database";
@@ -163,6 +163,7 @@ describe("documentDuplicator", () => {
fileName: "test.md",
externalId: "ext123",
originalDocumentId: original.id,
authType: AuthenticationType.APP,
});
});