https://github.com/outline/outline/blob/master/app/scenes/UserDelete.js#L40: corrected "destory" to "destroy" https://github.com/outline/outline/blob/master/app/components/ScrollToTop.js#L16: corrected "postion" to "position" https://github.com/outline/outline/blob/master/server/policies/document.js#L11: corrected "existance" to "existence" https://github.com/outline/outline/blob/master/server/policies/document.js#L23: corrected "existance" to "existence" https://github.com/outline/outline/blob/master/server/models/Document.js#L493: corrected "permanantly" to "permanently" https://github.com/outline/outline/blob/master/shared/utils/domains.js#L12: corrected "unneccessarily" to "unnecessarily" https://github.com/outline/outline/blob/master/server/api/documents.js#L34: corrected "compatablity" to "compatibility"
143 lines
3.9 KiB
JavaScript
143 lines
3.9 KiB
JavaScript
// @flow
|
|
import invariant from "invariant";
|
|
import policy from "./policy";
|
|
import { Document, Revision, User } from "../models";
|
|
|
|
const { allow, cannot } = policy;
|
|
|
|
allow(User, "create", Document);
|
|
|
|
allow(User, ["read", "download"], Document, (user, document) => {
|
|
// existence of collection option is not required here to account for share tokens
|
|
if (document.collection && cannot(user, "read", document.collection)) {
|
|
return false;
|
|
}
|
|
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(User, ["share"], Document, (user, document) => {
|
|
if (document.archivedAt) return false;
|
|
if (document.deletedAt) return false;
|
|
|
|
// existence of collection option is not required here to account for share tokens
|
|
if (document.collection && cannot(user, "read", document.collection)) {
|
|
return false;
|
|
}
|
|
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(User, ["star", "unstar"], Document, (user, document) => {
|
|
if (document.archivedAt) return false;
|
|
if (document.deletedAt) return false;
|
|
if (!document.publishedAt) return false;
|
|
|
|
invariant(
|
|
document.collection,
|
|
"collection is missing, did you forget to include in the query scope?"
|
|
);
|
|
if (cannot(user, "read", document.collection)) return false;
|
|
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(User, "update", Document, (user, document) => {
|
|
if (document.archivedAt) return false;
|
|
if (document.deletedAt) 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, "createChildDocument", Document, (user, document) => {
|
|
if (document.archivedAt) return false;
|
|
if (document.archivedAt) return false;
|
|
if (!document.publishedAt) 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, ["move", "pin", "unpin"], Document, (user, document) => {
|
|
if (document.archivedAt) return false;
|
|
if (document.deletedAt) return false;
|
|
if (!document.publishedAt) 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, "delete", Document, (user, document) => {
|
|
// unpublished drafts can always be deleted
|
|
if (
|
|
!document.deletedAt &&
|
|
!document.publishedAt &&
|
|
user.teamId === document.teamId
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
// allow deleting document without a collection
|
|
if (document.collection && cannot(user, "update", document.collection)) {
|
|
return false;
|
|
}
|
|
|
|
if (document.deletedAt) return false;
|
|
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(User, "restore", Document, (user, document) => {
|
|
if (!document.deletedAt) return false;
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(User, "archive", Document, (user, document) => {
|
|
invariant(
|
|
document.collection,
|
|
"collection is missing, did you forget to include in the query scope?"
|
|
);
|
|
if (cannot(user, "update", document.collection)) return false;
|
|
|
|
if (!document.publishedAt) return false;
|
|
if (document.archivedAt) return false;
|
|
if (document.deletedAt) return false;
|
|
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(User, "unarchive", Document, (user, document) => {
|
|
invariant(
|
|
document.collection,
|
|
"collection is missing, did you forget to include in the query scope?"
|
|
);
|
|
if (cannot(user, "update", document.collection)) return false;
|
|
|
|
if (!document.archivedAt) return false;
|
|
|
|
return user.teamId === document.teamId;
|
|
});
|
|
|
|
allow(
|
|
Document,
|
|
"restore",
|
|
Revision,
|
|
(document, revision) => document.id === revision.documentId
|
|
);
|