katanakit-js / HierarchicalAccessStrategy
Class: HierarchicalAccessStrategy
Defined in: src/core/services/access.service.ts:113
Estrategia por defecto: control de acceso jerárquico basado en roles registrados. Es la estrategia estándar del servicio.
Example
const strategy = new HierarchicalAccessStrategy();
strategy.useCan({ id: 1, roles: ["editor"] }, "content:create"); // trueImplements
Constructors
Constructor
new HierarchicalAccessStrategy(): HierarchicalAccessStrategy;Defined in: src/core/services/access.service.ts:117
Returns
HierarchicalAccessStrategy
Methods
useCan()
useCan(subject, capability): boolean;Defined in: src/core/services/access.service.ts:196
Whether the subject may perform a capability. Any of the subject's roles granting the capability (directly or by inheritance) is enough.
Parameters
| Parameter | Type |
|---|---|
subject | { [key: string]: unknown; id: string | number; roles: string[]; } |
subject.id | string | number |
subject.roles | string[] |
capability | string |
Returns
boolean
Example
useCan({ id: 1, roles: ["author"] }, "content:publish"); // false
useCan({ id: 1, roles: ["author"] }, "content:create"); // true
useCan({ id: 2, roles: ["editor"] }, "content:create"); // true (inherits author)
useCan({ id: 3, roles: [] }, "conversations:use"); // falseImplementation of
useCapabilitiesFor()
useCapabilitiesFor(role): string[];Defined in: src/core/services/access.service.ts:140
Effective capabilities of a role: its own plus every less-privileged role's.
Parameters
| Parameter | Type |
|---|---|
role | string |
Returns
string[]
Example
useCapabilitiesFor("author"); // content:create, content:edit:own, ..., conversations:use
useCapabilitiesFor("guest"); // []Implementation of
IAccessStrategy.useCapabilitiesFor
useHasRole()
useHasRole(subject, role): boolean;Defined in: src/core/services/access.service.ts:180
Exact role membership - no hierarchy involved.
Parameters
| Parameter | Type |
|---|---|
subject | { [key: string]: unknown; id: string | number; roles: string[]; } |
subject.id | string | number |
subject.roles | string[] |
role | string |
Returns
boolean
Implementation of
useRegisterRole()
useRegisterRole(definition): void;Defined in: src/core/services/access.service.ts:161
Registers (or replaces) a role definition. Use it to extend a built-in role's capabilities, e.g. grant content:create to member, or to add a deployment-specific role that inherits from the built-ins by rank. The definition is copied, so mutating the caller's object afterwards has no effect.
Parameters
| Parameter | Type |
|---|---|
definition | { capabilities: string[]; label: string; rank: number; slug: string; } |
definition.capabilities | string[] |
definition.label | string |
definition.rank | number |
definition.slug | string |
Returns
void
Implementation of
IAccessStrategy.useRegisterRole
useResetRoles()
useResetRoles(): void;Defined in: src/core/services/access.service.ts:167
Restores the built-in role registry (mainly for tests).
Returns
void
Implementation of
useRoles()
useRoles(): {
capabilities: string[];
label: string;
rank: number;
slug: string;
}[];Defined in: src/core/services/access.service.ts:175
Lists every registered role definition. Returns copies, not live state.
Returns
{ capabilities: string[]; label: string; rank: number; slug: string; }[]