fix: Moving document in private collection returns incorrect policies (#1969)

* fix: Return no policies when collection doesn't change
fix: Return correct policies when it does change

* test
This commit is contained in:
Tom Moor
2021-03-19 08:01:51 -07:00
committed by GitHub
parent 7891a8ee8b
commit ad8c08497c
4 changed files with 12 additions and 4 deletions

View File

@ -18,8 +18,8 @@ export default async function documentMover({
ip: string,
}) {
let transaction;
const result = { collections: [], documents: [] };
const collectionChanged = collectionId !== document.collectionId;
const result = { collections: [], documents: [], collectionChanged };
if (document.template) {
if (!collectionChanged) {
@ -72,7 +72,9 @@ export default async function documentMover({
document.updatedBy = user;
const newCollection: Collection = collectionChanged
? await Collection.findByPk(collectionId, { transaction })
? await Collection.scope({
method: ["withMembership", user.id],
}).findByPk(collectionId, { transaction })
: collection;
await newCollection.addDocumentToStructure(document, toIndex, {
documentJson,
@ -104,6 +106,8 @@ export default async function documentMover({
}
await document.save({ transaction });
document.collection = newCollection;
result.documents.push(document);
await transaction.commit();