Documentation / zerotal / auth / Permissions
Function: Permissions()
Permissions<
TBase>(Base): {(...args):(Anonymous class);withPermissions:boolean;prototype:(Anonymous class)<any>; } &TBase
Defined in: packages/auth/src/rbac/Permissions.ts:76
Model mixin adding DB-backed direct permissions — abilities granted to a model independently of any role.
Direct permissions are a polymorphic many-to-many (model_permissions),
eager-loaded on every query via the permissionsEagerLoad global scope, so
can is synchronous. Writes (givePermissionTo,
revokePermissionTo, syncPermissions) are async.
Type Parameters
TBase
TBase extends Constructor<object>
The model constructor being extended.
Parameters
Base
TBase
The base model (or another mixin) to compose onto.
Returns
A subclass of Base with the direct-permissions API mixed in.
Remarks
When composed with Roles, the effective can is the union of
directly-granted and role-derived permissions (resolution lives in
authz-core). Both .* and * wildcards are honored. Disable eager-loading
with static withPermissions = false.
Example
import { BaseModelWith, Authenticatable } from "@zerotal/orm";
import { Permissions, Roles } from "@zerotal/auth";
export class User extends BaseModelWith(Authenticatable, Permissions, Roles) {}
const user = await User.find(1);
await user.givePermissionTo("post.publish");
user.can("post.publish"); // true — synchronous, direct or via a role