chore: Remove server leftovers from the FileOperation import path (#14797)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-28 10:58:56 -05:00
1 parent 9372771031
commit 87c29eaa3c
4 files changed
+9 -84

No files matched your search

+7 -6
View File
@@ -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);
});
});
+1 -4
View File
@@ -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,
@@ -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 })
);
}
});
}
}
@@ -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;
}