feat: Allow unpublishing documents (#1467)

* Allow unpublishing documents

* add block unpublish files that has children

* add api tests to new route
This commit is contained in:
Guilherme DIniz
2020-09-01 00:03:05 -03:00
committed by GitHub
parent de59147418
commit 0aa338cccc
7 changed files with 159 additions and 12 deletions

View File

@ -157,3 +157,27 @@ allow(
Revision,
(document, revision) => document.id === revision.documentId
);
allow(User, "unpublish", Document, (user, document) => {
invariant(
document.collection,
"collection is missing, did you forget to include in the query scope?"
);
if (!document.publishedAt || !!document.deletedAt || !!document.archivedAt)
return false;
if (cannot(user, "update", document.collection)) return false;
const documentID = document.id;
const hasChild = (documents) =>
documents.some((doc) => {
if (doc.id === documentID) return doc.children.length > 0;
return hasChild(doc.children);
});
return (
!hasChild(document.collection.documentStructure) &&
user.teamId === document.teamId
);
});