fix: Enable toggling of insights while document is draft

This commit is contained in:
Tom Moor
2023-07-23 13:06:34 -04:00
parent 404f5ff871
commit 217e53d8b6
6 changed files with 32 additions and 23 deletions

View File

@@ -129,6 +129,23 @@ allow(User, "update", Document, (user, document) => {
return user.teamId === document.teamId;
});
allow(User, "updateInsights", Document, (user, document) => {
if (!document || !document.isActive) {
return false;
}
if (document.collectionId) {
invariant(
document.collection,
"collection is missing, did you forget to include in the query scope?"
);
if (cannot(user, "update", document.collection)) {
return false;
}
}
return user.teamId === document.teamId;
});
allow(User, "createChildDocument", Document, (user, document) => {
if (!document || !document.isActive || document.isDraft) {
return false;
@@ -277,20 +294,6 @@ allow(User, "archive", Document, (user, document) => {
return user.teamId === document.teamId;
});
allow(User, "updateInsights", Document, (user, document) => {
if (!document || !document.isActive || document.isDraft) {
return false;
}
invariant(
document.collection,
"collection is missing, did you forget to include in the query scope?"
);
if (cannot(user, "update", document.collection)) {
return false;
}
return user.teamId === document.teamId;
});
allow(User, "unarchive", Document, (user, document) => {
if (!document) {
return false;