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.
outline/server/policies/collection.js

22 lines
574 B
JavaScript
Raw Normal View History

// @flow
import policy from './policy';
import { Collection, User } from '../models';
2018-02-20 07:31:18 +00:00
import { AdminRequiredError } from '../errors';
const { allow } = policy;
allow(User, 'create', Collection);
allow(
User,
['read', 'publish', 'update'],
Collection,
(user, collection) => collection && user.teamId === collection.teamId
);
2018-02-20 07:31:18 +00:00
allow(User, 'delete', Collection, (user, collection) => {
if (!collection || user.teamId !== collection.teamId) return false;
if (user.id === collection.creatorId) return true;
if (!user.isAdmin) throw new AdminRequiredError();
});