fix: Moving documents between collections does not update attachment permissions (#2136)

* fix: Copy attachments when neccessary and moving between collections

* test: regression
This commit is contained in:
Tom Moor
2021-05-12 22:38:24 -07:00
committed by GitHub
parent 447371f35a
commit a93d034091
3 changed files with 97 additions and 11 deletions

View File

@ -1,6 +1,13 @@
// @flow
import { buildDocument, buildCollection, buildUser } from "../test/factories";
import { Attachment } from "../models";
import {
buildDocument,
buildAttachment,
buildCollection,
buildUser,
} from "../test/factories";
import { flushdb, seed } from "../test/support";
import parseAttachmentIds from "../utils/parseAttachmentIds";
import documentMover from "./documentMover";
beforeEach(() => flushdb());
@ -110,4 +117,46 @@ describe("documentMover", () => {
expect(response.documents[0].collection.id).toEqual(newCollection.id);
expect(response.documents[1].collection.id).toEqual(newCollection.id);
});
it("should move attachments in children to another collection", async () => {
const { document, user, collection } = await seed();
const newCollection = await buildCollection({
teamId: collection.teamId,
});
const attachment = await buildAttachment({
teamId: user.teamId,
userId: user.id,
});
const newDocument = await buildDocument({
parentDocumentId: document.id,
collectionId: collection.id,
teamId: collection.teamId,
userId: collection.createdById,
title: "Child document",
text: `content ![attachment](${attachment.redirectUrl})`,
});
await collection.addDocumentToStructure(newDocument);
await documentMover({
user,
document,
collectionId: newCollection.id,
parentDocumentId: undefined,
index: 0,
ip,
});
// check document ids where updated
await newDocument.reload();
expect(newDocument.collectionId).toBe(newCollection.id);
// check new attachment was created pointint to same key
const attachmentIds = parseAttachmentIds(newDocument.text);
const newAttachment = await Attachment.findByPk(attachmentIds[0]);
expect(newAttachment.documentId).toBe(newDocument.id);
expect(newAttachment.key).toBe(attachment.key);
await document.reload();
expect(document.collectionId).toBe(newCollection.id);
});
});