Files
outline/server/policies/share.ts
Tom Moor 15b1069bcc chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
2021-11-29 06:40:55 -08:00

27 lines
771 B
TypeScript

import { Share, User } from "@server/models";
import { AdminRequiredError } from "../errors";
import policy from "./policy";
const { allow, cannot } = policy;
allow(User, "read", Share, (user, share) => {
return user.teamId === share.teamId;
});
allow(User, "update", Share, (user, share) => {
if (user.isViewer) return false;
// only the user who can share the document publicly can update the share.
if (cannot(user, "share", share.document)) return false;
return user.teamId === share.teamId;
});
allow(User, "revoke", Share, (user, share) => {
if (user.isViewer) return false;
if (!share || user.teamId !== share.teamId) return false;
if (user.id === share.userId) return true;
if (user.isAdmin) return true;
throw AdminRequiredError();
});