Policies refactor, guest roles (#6732)
This commit is contained in:
@@ -1,38 +1,12 @@
|
||||
import { Attachment, User, Team } from "@server/models";
|
||||
import { allow } from "./cancan";
|
||||
import { and, isOwner, isTeamModel, or } from "./utils";
|
||||
|
||||
allow(User, "createAttachment", Team, (user, team) => {
|
||||
if (!team || user.isViewer || user.teamId !== team.id) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
allow(User, "createAttachment", Team, isTeamModel);
|
||||
|
||||
allow(User, "read", Attachment, (actor, attachment) => {
|
||||
if (!attachment || !actor || 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;
|
||||
}
|
||||
if (!attachment || attachment.teamId !== actor.teamId) {
|
||||
return false;
|
||||
}
|
||||
if (actor.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
if (actor.id === attachment.userId) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
allow(User, ["read", "update", "delete"], Attachment, (actor, attachment) =>
|
||||
and(
|
||||
isTeamModel(actor, attachment),
|
||||
or(actor.isAdmin, isOwner(actor, attachment))
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user