fix: Incorrect policies returned after unpublishing document

Related https://github.com/outline/outline/discussions/7258
This commit is contained in:
Tom Moor
2024-07-15 20:28:44 -04:00
parent e4492a32d2
commit 8186e23d45
2 changed files with 14 additions and 4 deletions
+12 -4
View File
@@ -831,7 +831,9 @@ class Document extends ParanoidModel<
if (collection) {
await collection.addDocumentToStructure(this, 0, { transaction });
this.collection = collection;
if (this.collection) {
this.collection.documentStructure = collection.documentStructure;
}
}
}
@@ -899,7 +901,9 @@ class Document extends ParanoidModel<
if (collection) {
await collection.removeDocumentInStructure(this, { transaction });
this.collection = collection;
if (this.collection) {
this.collection.documentStructure = collection.documentStructure;
}
}
});
@@ -926,7 +930,9 @@ class Document extends ParanoidModel<
if (collection) {
await collection.removeDocumentInStructure(this, { transaction });
this.collection = collection;
if (this.collection) {
this.collection.documentStructure = collection.documentStructure;
}
}
});
@@ -961,7 +967,9 @@ class Document extends ParanoidModel<
await collection.addDocumentToStructure(this, undefined, {
transaction,
});
this.collection = collection;
if (this.collection) {
this.collection.documentStructure = collection.documentStructure;
}
}
});
@@ -3803,6 +3803,8 @@ describe("#documents.unpublish", () => {
expect(body.data.publishedAt).toBeNull();
expect(body.data.createdBy.id).toEqual(user.id);
expect(body.data.updatedBy.id).toEqual(user.id);
expect(body.policies[0].abilities.createChildDocument).toEqual(false);
expect(body.policies[0].abilities.update).toEqual(true);
const reloaded = await Document.unscoped().findByPk(document.id);
expect(reloaded!.createdById).toEqual(user.id);