Role & Permission API
Role CRUD, permission assignment, tenant-scoped roles, and permission catalog for RBAC management.
The Role & Permission API manages the RBAC (Role-Based Access Control) system. Roles are tenant-scoped, meaning each tenant has its own set of roles. Permissions are seeded from the backend and are read-only. Roles compose permissions with optional field-level restrictions.
Role CRUD
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/v1/roles | List all roles in the current tenant with admin counts. | 🔒 Required |
| GET | /api/v1/roles/{id} | Get role details including permissions, menu items, and field restrictions. | 🔒 Required |
| POST | /api/v1/roles | Create a new custom role with permissions and menu visibility. | 🔒 Required |
| PUT | /api/v1/roles/{id} | Update role name, description, and menu visibility. | 🔒 Required |
| DELETE | /api/v1/roles/{id} | Delete a role. Fails if admins are still assigned to it. | 🔒 Required |
| POST | /api/v1/roles/{id}/clone | Clone an existing role with all its permissions and menu items. | 🔒 Required |
{
"id": "role-uuid",
"name": "Branch Manager",
"description": "Manager for branch offices",
"isDefault": false,
"isSystem": false,
"adminCount": 5,
"permissions": [
{
"id": "perm-uuid",
"name": "admins.view",
"category": "Admin Management",
"restrictedFields": ["email", "phoneNumber"]
}
],
"menuItems": [
{ "id": "menu-uuid", "title": "Dashboard", "isVisible": true }
],
"createdAt": "2026-01-01T00:00:00Z"
}Permission Assignment
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| PUT | /api/v1/roles/{id}/permissions | Replace all permissions for a role. Supports field-level restrictions per permission. | 🔒 Required |
| GET | /api/v1/roles/{id}/permissions | Get the current permissions assigned to a role. | 🔒 Required |
| POST | /api/v1/roles/{id}/sync-scopes | Sync permission scopes and restricted fields from the parent tenant. | 🔒 Required |
// Request: Replace all permissions for this role
{
"permissionIds": [
"perm-admins-view",
"perm-admins-create",
"perm-users-view",
"perm-dashboard-view"
],
"restrictedFields": {
"perm-admins-view": ["email", "phoneNumber", "lastLoginIp"],
"perm-users-view": ["email"]
}
}
// Response (200)
{
"message": "Permissions updated",
"totalPermissions": 4,
"restrictedFieldsCount": 2
}Tenant-Scoped Roles
Each tenant has its own set of roles that can only use permissions available in the tenant's scope. The available permissions are controlled by the parent tenant's role assignment. Admins can only see and assign permissions their tenant is allowed to use.
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/v1/roles/my-tenant-roles | List roles available in the current admin's tenant. | 🔒 Required |
| GET | /api/v1/roles/my-tenant-available-permissions | List permissions available for assignment in the current tenant's scope. | 🔒 Required |
Permissions (Read-Only)
Permissions are seeded automatically from the backend. They cannot be created or modified through the API. Each permission belongs to a category and can have field-level restrictions when assigned to a role.
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/v1/permissions | List all permissions grouped by category. | 🔒 Required |
| GET | /api/v1/permissions/my | Get the current admin's effective permissions. | 🔒 Required |
| GET | /api/v1/permissions/{id} | Get a single permission by ID with full details. | 🔒 Required |
| GET | /api/v1/permissions/categories | Get permission categories with all permissions in each. | 🔒 Required |
| GET | /api/v1/permissions/available-for-tenant | List permissions available for a specific tenant (for tenant creation/editing). | 🔒 Required |
[
{
"name": "Admin Management",
"slug": "admins",
"permissions": [
{ "id": "p1", "name": "admins.view", "description": "View admin list" },
{ "id": "p2", "name": "admins.create", "description": "Create new admins" },
{ "id": "p3", "name": "admins.update", "description": "Update admin details" },
{ "id": "p4", "name": "admins.delete", "description": "Delete admins" }
]
},
{
"name": "User Management",
"slug": "users",
"permissions": [
{ "id": "p5", "name": "users.view", "description": "View user list" },
{ "id": "p6", "name": "users.create", "description": "Register users" }
]
}
]