Skip to content

URD: Permissions

ModuleCORE-02Versionv0.4
StatusBuiltDate2026-05-29

1. Purpose

Define how access to features and data is controlled. Permissions lets administrators assign roles to users, grant permissions to those roles, scope roles to a specific organization or merchant, and have every query automatically filtered to what the requesting user is allowed to see — enforced through a Casbin priority-based RBAC model with per-merchant domains.

2. Scope

IncludedExcluded
Eight fixed system roles + priority hierarchyWildcard permissions
System-role bypass (Super Admin / Admin / Operator)Permission categories / UI grouping
Automatic role-based data filteringTime- or shift-based permissions
Custom role creation with priority and scopePermission audit logging
Permission catalog (create / update / delete)Role templates / bundles
Grant / revoke permissions to rolesPer-merchant active-role switching
Grant / revoke roles to usersTechnical API specifications (see developer docs)
Effective-permission query (direct + inherited)
Per-organization & per-merchant scoping
Privilege-escalation guard

3. Definitions

TermDefinition
RoleA named access level with a numeric priority. SYSTEM (fixed) or CUSTOM (user-created).
PermissionA named action on a resource, identified by a globally unique code.
Grant (policy)A record granting a permission to a role or directly to a user.
Membership (group)A record linking a user to a role, a user to an org/merchant, or a role to an org/merchant.
Effective permissionsThe union of all permissions a user holds: direct grants + permissions inherited through roles.
Scoped roleA custom role bound to a specific organization or merchant, limiting where it applies.
DomainThe merchant a grant applies within, selected per request by the active-merchant header.
System-role bypassSuper Admin, Admin, and Operator skip all data filtering and hold every permission.
HQ-owner expansionAn Owner at a head-quarter merchant automatically reaches every sibling merchant of that organizer.
Privilege escalationManaging a role at or above the actor's own priority — always blocked.

4. Conceptual Model

Conceptual only — the full policy data model lives in the developer RBAC docs.

5. Functional Requirements

One table per functional area. <AREA> codes match the test-case IDs. Priority = MoSCoW (Must / Should / Could / Won't).

5.1 Fixed Roles (ROLE)

IDPRequirement
URD-ROLE-001MProvide eight fixed roles seeded at startup: Super Admin, Admin, Operator, Owner, Cashier, Employee, Customer, Guest
URD-ROLE-002MFixed (SYSTEM) roles cannot be modified or deleted
URD-ROLE-003MEach role has a numeric priority that sets its place in the hierarchy
URD-ROLE-004MSuper Admin, Admin, and Operator bypass all data filtering and hold every permission
URD-ROLE-005MOwner sees only their own organization and its merchants
URD-ROLE-006MEmployee (and Cashier) see only merchants they are assigned to
URD-ROLE-007MEvery list and count operation is filtered by the requesting user's scope
URD-ROLE-008MAutomatic filtering cannot be overridden by a user-supplied filter or direct ID access
URD-ROLE-009SAn Owner at a head-quarter merchant reaches every sibling merchant of that organizer

5.2 Custom Roles (CROLE)

IDPRequirement
URD-CROLE-001MAuthorized users can create custom roles with an i18n name, priority, and optional scope
URD-CROLE-002MRole identifier is auto-generated from priority + name and is unique within its scope
URD-CROLE-003MA new role's priority must be strictly lower than the creator's own highest priority
URD-CROLE-004MCustom roles can be scoped to a specific organization or merchant
URD-CROLE-005MCustom roles can be updated (name, description, priority)
URD-CROLE-006MA role cannot be deleted while users are still assigned to it
URD-CROLE-007MDeleting a role cascade-removes its permission grants and scope links
URD-CROLE-008SAn Owner can create roles scoped only to their own organization or merchants

5.3 Permission Catalog (PERM)

IDPRequirement
URD-PERM-001MAdmin can create permissions with a unique code, action, scope, and subject
URD-PERM-002MPermission code must be globally unique
URD-PERM-003MPermission name and description support i18n
URD-PERM-004MAdmin can update and delete permissions
URD-PERM-005MA permission with active grants cannot be deleted

5.4 Grant / Revoke (GRANT)

IDPRequirement
URD-GRANT-001MAdmin can grant one or more permissions to a role
URD-GRANT-002MAdmin can revoke one or more permissions from a role
URD-GRANT-003MGranting an already-granted permission is idempotent (skipped, not duplicated)
URD-GRANT-004MAdmin can grant and revoke roles to/from users
URD-GRANT-005MPrivilege-escalation guard is enforced on every grant/revoke operation
URD-GRANT-006MAdmin can view all permissions granted to a role
URD-GRANT-007MAdmin can view all users assigned to a role and all roles assigned to a user

5.5 Effective Permissions & Scope (EFF)

IDPRequirement
URD-EFF-001MCompute effective permissions as the union of direct + role-inherited grants (deduplicated)
URD-EFF-002SThe query supports a mode filter: direct, inherit, or both
URD-EFF-003MRetrieve all organizations and all merchants a user belongs to
URD-EFF-004MA grant resolves only within the active merchant domain chosen per request

6. Acceptance Criteria

AC-ROLE-01: Data filtering by role
GivenWhenThen
Users with different rolesThey hit the same endpointSuper Admin/Admin/Operator see all; Owner sees own org; Employee/Cashier see assigned merchants
Any list/count queryRun by a scoped userFiltering is automatic and cannot be overridden
A scoped user supplies a wider filter or a foreign IDRequest is madeThe filter is ignored / access denied
AC-ROLE-02: Fixed-role protection
GivenWhenThen
Any of the eight system rolesUser tries to modify or delete itOperation rejected
A fixed role's priorityUser tries to change itRejected — priorities are immutable
AC-CROLE-01: Custom role creation
GivenWhenThen
Admin or OwnerCreates a role with priority + nameRole created with type CUSTOM, identifier auto-generated
Priority ≥ creator's ownCreation attemptedRejected (privilege escalation)
Org/merchant scope providedRole createdScope link created
Same priority + name in same scopeCreation attemptedRejected (identifier collision)
AC-GRANT-01: Permission grant
GivenWhenThen
Role + permission IDsAdmin grantsGrant records created, count returned
Permission already grantedAdmin grants againSkipped (idempotent), skip count returned
Actor priority ≤ role priorityAdmin grantsRejected (privilege escalation)
AC-EFF-01: Effective permissions
GivenWhenThen
User with roles + direct grantsEffective queryUnion of direct + inherited, deduplicated
Mode = directQueryOnly direct grants returned
Mode = inheritQueryOnly role-inherited grants returned
AC-CROLE-02: Role deletion
GivenWhenThen
Custom role with no usersAdmin deletesRole + grants + scope links soft-deleted
Custom role with assigned usersAdmin deletesBlocked — must unassign users first
System roleAdmin deletesRejected — fixed roles are immutable

7. Constraints & Non-Goals

Constraints

IDConstraint
C-01Eight fixed roles are seeded at startup and are immutable
C-02No one can create or manage a role at or above their own priority
C-03Permission codes are globally unique
C-04Grant operations are idempotent
C-05All records are soft-deleted, never physically removed
C-06The session token is stateless — role/permission changes take effect on next sign-in
C-07All operations require authentication
C-08A grant resolves within one active merchant domain per request

Non-Goals

  • Wildcard permissions (e.g. sales.*)
  • Permission categories and UI grouping
  • Time- or shift-based permissions
  • Permission audit log
  • Role templates / pre-configured bundles
  • Per-merchant active-role switching

8. Version History

DateAuthorDescriptionVer
2026-02-26P. Do - Product OwnerInitial user storiesv0.1
2026-04-16ProductRestructured to URD formatv0.3
2026-05-29ProductMigrated to module-docs convention; reconciled with Casbin per-merchant RBAC (8 roles, priorities, domains); re-keyed areas (ROLE/CROLE/PERM/GRANT/EFF)v0.4

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.