From 6eeb7ebe1bacdf00aae4a3d991181c8ee4043003 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 5 Aug 2026 20:11:00 -0400 Subject: [PATCH] feat: Attribute document creation to the auth type it was made with --- server/commands/documentCreator.test.ts | 6 +++++- server/commands/documentCreator.ts | 8 ++++++-- server/commands/documentDuplicator.test.ts | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/server/commands/documentCreator.test.ts b/server/commands/documentCreator.test.ts index f5b7e35597..9e893e1c45 100644 --- a/server/commands/documentCreator.test.ts +++ b/server/commands/documentCreator.test.ts @@ -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, + }); }); }); diff --git a/server/commands/documentCreator.ts b/server/commands/documentCreator.ts index 94c596a783..7abd712b9d 100644 --- a/server/commands/documentCreator.ts +++ b/server/commands/documentCreator.ts @@ -173,10 +173,14 @@ export default async function documentCreator( lastModifiedById, }: Props ): Promise { - 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, diff --git a/server/commands/documentDuplicator.test.ts b/server/commands/documentDuplicator.test.ts index f04698a070..8a916845ee 100644 --- a/server/commands/documentDuplicator.test.ts +++ b/server/commands/documentDuplicator.test.ts @@ -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, }); });