diff --git a/server/commands/documentCreator.test.ts b/server/commands/documentCreator.test.ts index fd152de55a..d46e98bf1d 100644 --- a/server/commands/documentCreator.test.ts +++ b/server/commands/documentCreator.test.ts @@ -4,7 +4,7 @@ import { buildUser, buildCollection, buildDocument, - buildFileOperation, + buildImport, buildTemplate, } from "@server/test/factories"; import { withContext } from "@server/test/support"; @@ -317,23 +317,24 @@ describe("documentCreator", () => { teamId: user.teamId, }); - const fileOperation = await buildFileOperation({ + const importModel = await buildImport({ teamId: user.teamId, + createdById: user.id, }); const sourceMetadata = { fileName: "test" }; const document = await withContext(user, (ctx) => documentCreator(ctx, { - title: "fileOperation Document", - text: "fileOperation content", - importId: fileOperation.id, + title: "Imported Document", + text: "Imported content", + apiImportId: importModel.id, sourceMetadata, collectionId: collection.id, }) ); - expect(document.importId).toBe(fileOperation.id); + expect(document.apiImportId).toBe(importModel.id); expect(document.sourceMetadata).toEqual(sourceMetadata); }); }); diff --git a/server/commands/documentCreator.ts b/server/commands/documentCreator.ts index e836bf7dae..e40b7ce635 100644 --- a/server/commands/documentCreator.ts +++ b/server/commands/documentCreator.ts @@ -24,7 +24,6 @@ type Props = Optional< | "color" | "collectionId" | "parentDocumentId" - | "importId" | "apiImportId" | "fullWidth" | "preferences" @@ -178,7 +177,6 @@ export default async function documentCreator( template, fullWidth, preferences, - importId, apiImportId, createdAt, // allows override for import @@ -194,7 +192,7 @@ export default async function documentCreator( const { user } = ctx.auth; const { transaction } = ctx; const templateId = template ? template.id : undefined; - const eventData = importId || apiImportId ? { source: "import" } : undefined; + const eventData = apiImportId ? { source: "import" } : undefined; if (state && template) { throw new Error( @@ -252,7 +250,6 @@ export default async function documentCreator( createdById: createdById ?? user.id, templateId, publishedAt, - importId, apiImportId, sourceMetadata, fullWidth: fullWidth ?? template?.fullWidth, diff --git a/server/queues/processors/FileOperationDeletedProcessor.ts b/server/queues/processors/FileOperationDeletedProcessor.ts deleted file mode 100644 index dd9757b77e..0000000000 --- a/server/queues/processors/FileOperationDeletedProcessor.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { FileOperationState, FileOperationType } from "@shared/types"; -import { createContext } from "@server/context"; -import Logger from "@server/logging/Logger"; -import { Collection, FileOperation, User } from "@server/models"; -import { sequelize } from "@server/storage/database"; -import type { Event as TEvent, FileOperationEvent } from "@server/types"; -import BaseProcessor from "./BaseProcessor"; - -export default class FileOperationDeletedProcessor extends BaseProcessor { - static applicableEvents: TEvent["name"][] = [ - "fileOperations.delete", - "fileOperations.update", - ]; - - async perform(event: FileOperationEvent) { - await sequelize.transaction(async (transaction) => { - const fileOperation = await FileOperation.unscoped().findByPk( - event.modelId, - { - rejectOnEmpty: true, - paranoid: false, - transaction, - } - ); - if (fileOperation.type === FileOperationType.Export) { - return; - } - - if ( - event.name === "fileOperations.update" && - fileOperation.state !== FileOperationState.Error - ) { - return; - } - - if ( - event.name === "fileOperations.delete" && - ![FileOperationState.Complete, FileOperationState.Error].includes( - fileOperation.state - ) - ) { - return; - } - - const user = await User.findByPk(event.actorId, { - rejectOnEmpty: true, - paranoid: false, - transaction, - }); - - const collections = await Collection.unsafeFindAll({ - transaction, - lock: transaction.LOCK.NO_KEY_UPDATE, - where: { - teamId: fileOperation.teamId, - importId: fileOperation.id, - }, - }); - - for (const collection of collections) { - Logger.debug("processor", "Destroying collection created from import", { - collectionId: collection.id, - }); - await collection.destroyWithCtx( - createContext({ user, ip: event.ip, transaction }) - ); - } - }); - } -} diff --git a/server/queues/processors/NotificationsProcessor.ts b/server/queues/processors/NotificationsProcessor.ts index 3791848866..4ea094bd60 100644 --- a/server/queues/processors/NotificationsProcessor.ts +++ b/server/queues/processors/NotificationsProcessor.ts @@ -127,10 +127,7 @@ export default class NotificationsProcessor extends BaseProcessor { async collectionCreated(event: CollectionEvent) { // never send notifications when batch importing - if ( - !!event.changes?.attributes.apiImportId || - !!event.changes?.attributes.importId - ) { + if (event.changes?.attributes.apiImportId) { return; }