mirror of
https://github.com/outline/outline.git
synced 2026-11-22 14:01:41 +03:00
* Allow viewers to create and access API keys Still guarded by their view permissions * Drop Member role gate from apiKeys routes Lets viewers reach the createApiKey/listApiKeys/delete policy checks now that the policy itself permits them. Updates CleanupDemotedUserTask to retain viewer keys and adds coverage for viewer create + guest reject. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Tighten apiKeys test assertions and broaden viewer coverage - Use not.toBeNull() instead of toBeTruthy() for retention check - Add viewer coverage for apiKeys.list and apiKeys.delete Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
913 B
TypeScript
45 lines
913 B
TypeScript
import { TeamPreference } from "@shared/types";
|
|
import { ApiKey, User, Team } from "@server/models";
|
|
import { allow } from "./cancan";
|
|
import {
|
|
and,
|
|
isCloudHosted,
|
|
isOwner,
|
|
isTeamModel,
|
|
isTeamMutable,
|
|
or,
|
|
} from "./utils";
|
|
|
|
allow(User, "createApiKey", Team, (actor, team) =>
|
|
and(
|
|
isTeamModel(actor, team),
|
|
isTeamMutable(actor),
|
|
!actor.isGuest,
|
|
!actor.isSuspended,
|
|
actor.isAdmin ||
|
|
!!team?.getPreference(TeamPreference.MembersCanCreateApiKey)
|
|
)
|
|
);
|
|
|
|
allow(User, "listApiKeys", Team, (actor, team) =>
|
|
and(
|
|
//
|
|
isCloudHosted(),
|
|
isTeamModel(actor, team),
|
|
actor.isAdmin
|
|
)
|
|
);
|
|
|
|
allow(User, ["read", "update", "delete"], ApiKey, (actor, apiKey) =>
|
|
and(
|
|
isTeamModel(actor, apiKey?.user),
|
|
or(
|
|
actor.isAdmin,
|
|
and(
|
|
isOwner(actor, apiKey),
|
|
!!actor.team?.getPreference(TeamPreference.MembersCanCreateApiKey)
|
|
)
|
|
)
|
|
)
|
|
);
|