From 8186e23d45eef886e42db99ff141bc10a769abcb Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 15 Jul 2024 20:28:44 -0400 Subject: [PATCH] fix: Incorrect policies returned after unpublishing document Related https://github.com/outline/outline/discussions/7258 --- server/models/Document.ts | 16 ++++++++++++---- server/routes/api/documents/documents.test.ts | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/models/Document.ts b/server/models/Document.ts index b08f30ef5d..998ec6dd16 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -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; + } } }); diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index dba3386184..d738cc1d79 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -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);