Manage Roles and User Assignments
This page covers the everyday admin workflow: create a role, add one permission, bind the role to a user, and read direct versus effective authorization state.
Remember Four Methods First
scoped manages only data inside the acme tenant. Bind actorId/requestId here once, and later roles.* or userRoles.* writes reuse the same audit and idempotency context. Pass idempotencyKey manually only when an external gateway or queue already owns the idempotency protocol. permission-core does not create users; u-1 is a stable ID from the host user system.
1. Create a Role
roles.create() creates a role in the current scope. The commonly used return fields are created.data.id and created.data.revision; the full envelope is described in the core response contract.
2. Add One Permission to the Role
roles.allow(roleId, rule) writes one allow rule to the role. The action describes what the subject wants to do, and the resource names the thing being protected.
roles.allow(roleId, rule) means "this role may perform this action on this resource." In this example, order-reader can invoke api:GET:/api/orders. Missing allow rules are denied by default, so most APIs do not need explicit deny rules for every blocked operation.
3. Bind the Role to a User
Use assign() when adding one role. Use set() when saving the complete result of a role multi-select field.
4. Read the Final State
Use direct/own reads for editing screens and effective reads for diagnostics. Do not save effective results back as direct bindings.
Common Questions
assign() appends one role. set() replaces the complete direct-role set. A multi-select form should use set(), while a single "grant role" action should use assign().
What is the difference between assign and set?
Why read direct before set?
Where do updates and removals live?
What to Check When It Fails
When a call fails, first check scope and revision. ROLE_NOT_FOUND usually means the role ID is not in the current tenantId; REVISION_CONFLICT means the edit form used stale data.
Continue with Check Permissions.