Policies refactor, guest roles (#6732)

This commit is contained in:
Tom Moor
2024-03-31 18:28:35 -06:00
committed by GitHub
parent ceb7ae1514
commit c27cd945a7
46 changed files with 901 additions and 1032 deletions

View File

@@ -1,19 +1,15 @@
import { ApiKey, User, Team } from "@server/models";
import { allow } from "./cancan";
import { and, isOwner, isTeamModel, isTeamMutable } from "./utils";
allow(User, "createApiKey", Team, (user, team) => {
if (!team || user.isViewer || user.teamId !== team.id) {
return false;
}
return true;
});
allow(User, "createApiKey", Team, (actor, team) =>
and(
//
isTeamModel(actor, team),
isTeamMutable(actor),
!actor.isViewer,
!actor.isGuest
)
);
allow(User, ["read", "update", "delete"], ApiKey, (user, apiKey) => {
if (!apiKey) {
return false;
}
if (user.isViewer) {
return false;
}
return user && user.id === apiKey.userId;
});
allow(User, ["read", "update", "delete"], ApiKey, isOwner);