This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/server/policies/document.js
Tom Moor 763f57a3dc Move document improvements (#927)
* Show all collections in UI

* Introduce command pattern

* Actually remove from previous collection

* Stash

* Fixes: Promises resolved outside of response lifecycle

* 💚

* 💚

* documentMover tests

* Transaction

* Perf. More in transactions
2019-04-08 21:25:13 -07:00

50 lines
1.2 KiB
JavaScript

// @flow
import policy from './policy';
import { Document, Revision, User } from '../models';
const { allow, cannot } = policy;
allow(User, 'create', Document);
allow(User, ['read', 'delete'], Document, (user, document) => {
if (document.collection) {
if (cannot(user, 'read', document.collection)) return false;
}
return user.teamId === document.teamId;
});
allow(User, ['update', 'move', 'share'], Document, (user, document) => {
if (document.collection) {
if (cannot(user, 'read', document.collection)) return false;
}
if (document.archivedAt) return false;
return user.teamId === document.teamId;
});
allow(User, 'archive', Document, (user, document) => {
if (document.collection) {
if (cannot(user, 'read', document.collection)) return false;
}
if (!document.publishedAt) return false;
return user.teamId === document.teamId;
});
allow(User, 'unarchive', Document, (user, document) => {
if (document.collection) {
if (cannot(user, 'read', document.collection)) return false;
}
if (!document.archivedAt) return false;
return user.teamId === document.teamId;
});
allow(
Document,
'restore',
Revision,
(document, revision) => document.id === revision.documentId
);