Collection Permissions (#829)
see https://github.com/outline/outline/issues/668
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
import policy from './policy';
|
||||
import { map } from 'lodash';
|
||||
import { Collection, User } from '../models';
|
||||
import { AdminRequiredError } from '../errors';
|
||||
|
||||
@@ -11,12 +12,27 @@ allow(
|
||||
User,
|
||||
['read', 'publish', 'update', 'export'],
|
||||
Collection,
|
||||
(user, collection) => collection && user.teamId === collection.teamId
|
||||
(user, collection) => {
|
||||
if (!collection || user.teamId !== collection.teamId) return false;
|
||||
|
||||
if (
|
||||
collection.private &&
|
||||
!map(collection.users, u => u.id).includes(user.id)
|
||||
)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
allow(User, 'delete', Collection, (user, collection) => {
|
||||
if (!collection || user.teamId !== collection.teamId) return false;
|
||||
if (user.id === collection.creatorId) return true;
|
||||
|
||||
if (collection.private && !map(collection.users, u => u.id).includes(user.id))
|
||||
return false;
|
||||
|
||||
if (user.isAdmin) return true;
|
||||
if (user.id === collection.creatorId) return true;
|
||||
|
||||
throw new AdminRequiredError();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user