2020-12-20 19:39:09 +00:00
|
|
|
// @flow
|
2021-03-23 03:50:12 +00:00
|
|
|
import { Attachment, User, Team } from "../models";
|
2020-12-20 19:39:09 +00:00
|
|
|
import policy from "./policy";
|
|
|
|
|
|
|
|
const { allow } = policy;
|
|
|
|
|
2021-03-23 03:50:12 +00:00
|
|
|
allow(User, "createAttachment", Team, (user, team) => {
|
2021-04-12 02:39:17 +00:00
|
|
|
if (!team || user.isViewer || user.teamId !== team.id) return false;
|
2021-03-23 03:50:12 +00:00
|
|
|
return true;
|
|
|
|
});
|
2020-12-20 19:39:09 +00:00
|
|
|
|
2021-04-12 02:39:17 +00:00
|
|
|
allow(User, "read", Attachment, (actor, attachment) => {
|
|
|
|
if (!attachment || attachment.teamId !== actor.teamId) return false;
|
|
|
|
if (actor.isAdmin) return true;
|
|
|
|
if (actor.id === attachment.userId) return true;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
allow(User, "delete", Attachment, (actor, attachment) => {
|
|
|
|
if (actor.isViewer) return false;
|
2020-12-20 19:39:09 +00:00
|
|
|
if (!attachment || attachment.teamId !== actor.teamId) return false;
|
|
|
|
if (actor.isAdmin) return true;
|
|
|
|
if (actor.id === attachment.userId) return true;
|
|
|
|
return false;
|
|
|
|
});
|