fix: Don't trigger email and slack notifications when mass importing
feat: Show success message after import
This commit is contained in:
@@ -1124,7 +1124,7 @@ router.post("documents.batchImport", auth(), async (ctx) => {
|
||||
const user = ctx.state.user;
|
||||
authorize(user, "batchImport", Document);
|
||||
|
||||
const { collections } = await documentBatchImporter({
|
||||
const { documents, attachments, collections } = await documentBatchImporter({
|
||||
file,
|
||||
user,
|
||||
type,
|
||||
@@ -1133,6 +1133,9 @@ router.post("documents.batchImport", auth(), async (ctx) => {
|
||||
|
||||
ctx.body = {
|
||||
data: {
|
||||
attachmentCount: attachments.length,
|
||||
documentCount: documents.length,
|
||||
collectionCount: collections.length,
|
||||
collections: collections.map((collection) =>
|
||||
presentCollection(collection)
|
||||
),
|
||||
@@ -1189,6 +1192,7 @@ router.post("documents.import", auth(), async (ctx) => {
|
||||
});
|
||||
|
||||
const document = await documentCreator({
|
||||
source: "import",
|
||||
title,
|
||||
text,
|
||||
publish,
|
||||
|
||||
@@ -8,12 +8,14 @@ export default async function attachmentCreator({
|
||||
type,
|
||||
buffer,
|
||||
user,
|
||||
source,
|
||||
ip,
|
||||
}: {
|
||||
name: string,
|
||||
type: string,
|
||||
buffer: Buffer,
|
||||
user: User,
|
||||
source?: "import",
|
||||
ip: string,
|
||||
}) {
|
||||
const key = `uploads/${user.id}/${uuid.v4()}/${name}`;
|
||||
@@ -32,7 +34,7 @@ export default async function attachmentCreator({
|
||||
|
||||
await Event.create({
|
||||
name: "attachments.create",
|
||||
data: { name },
|
||||
data: { name, source },
|
||||
modelId: attachment.id,
|
||||
teamId: user.teamId,
|
||||
actorId: user.id,
|
||||
|
||||
@@ -114,6 +114,7 @@ export default async function documentBatchImporter({
|
||||
}
|
||||
|
||||
const document = await documentCreator({
|
||||
source: "import",
|
||||
title,
|
||||
text,
|
||||
publish: true,
|
||||
@@ -134,6 +135,7 @@ export default async function documentBatchImporter({
|
||||
if (item.type === "attachment") {
|
||||
const buffer = await item.item.async("nodebuffer");
|
||||
const attachment = await attachmentCreator({
|
||||
source: "import",
|
||||
name: item.name,
|
||||
type,
|
||||
buffer,
|
||||
|
||||
@@ -14,6 +14,7 @@ export default async function documentCreator({
|
||||
index,
|
||||
user,
|
||||
editorVersion,
|
||||
source,
|
||||
ip,
|
||||
}: {
|
||||
title: string,
|
||||
@@ -28,6 +29,7 @@ export default async function documentCreator({
|
||||
index?: number,
|
||||
user: User,
|
||||
editorVersion?: string,
|
||||
source?: "import",
|
||||
ip: string,
|
||||
}): Document {
|
||||
const templateId = templateDocument ? templateDocument.id : undefined;
|
||||
@@ -53,7 +55,7 @@ export default async function documentCreator({
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
data: { title: document.title, templateId },
|
||||
data: { source, title: document.title, templateId },
|
||||
ip,
|
||||
});
|
||||
|
||||
@@ -66,7 +68,7 @@ export default async function documentCreator({
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: user.id,
|
||||
data: { title: document.title },
|
||||
data: { source, title: document.title },
|
||||
ip,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@ export type DocumentEvent =
|
||||
teamId: string,
|
||||
actorId: string,
|
||||
ip: string,
|
||||
data: {
|
||||
title: string,
|
||||
source?: "import",
|
||||
},
|
||||
}
|
||||
| {
|
||||
name: "documents.move",
|
||||
|
||||
@@ -27,6 +27,9 @@ export default class Notifications {
|
||||
}
|
||||
|
||||
async documentUpdated(event: DocumentEvent) {
|
||||
// never send notifications when batch importing documents
|
||||
if (event.data && event.data.source === "import") return;
|
||||
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
if (!document) return;
|
||||
|
||||
|
||||
@@ -55,6 +55,9 @@ export default class Slack {
|
||||
}
|
||||
|
||||
async documentUpdated(event: DocumentEvent) {
|
||||
// never send notifications when batch importing documents
|
||||
if (event.data && event.data.source === "import") return;
|
||||
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
if (!document) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user