Policies refactor, guest roles (#6732)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user