Roles & Permissions
Version: 1.0.1
CMS uses a role-based access control system. Each user has a role and optional per-page permissions that determine what they can view, edit, and delete.
User Roles
| Role | Description |
|---|---|
| Admin | Full access to everything. Bypasses permission checks. Can manage users, business profile, and all data. |
| Editor | Access controlled by assigned permissions. Can be granted View, Edit, and/or Delete per page. |
| Viewer | Read-only access. Can only View pages — Edit and Delete are always blocked, even if checkboxes are set. |
Permission Types
Each page supports three permission levels:
| Permission | What it allows |
|---|---|
| View | Open the page and see data |
| Edit | Create new records and modify existing ones |
| Delete | Remove records (with confirmation) |
Permissions are stored per user, per page in the user_permissions database table.
Page Keys
These internal keys map to application pages:
| Page Key | Route(s) | Menu Label |
|---|---|---|
dashboard | /, /dashboard | Dashboard |
complaints | /complaints, /complaints/*/print | Complaints |
resolution-workflow | /resolution-workflow | Resolution Workflow |
settings | /profile, /settings | Settings / Profile |
settings-users-access | /settings/users-access | Users and Access |
settings-complaint-type | /settings/complaint-type | Complaint Type |
Access Matrix by Role
Admin
| Page | View | Edit | Delete |
|---|---|---|---|
| Dashboard | ✅ | ✅ | ✅ |
| Complaints | ✅ | ✅ | ✅ |
| Resolution Workflow | ✅ | ✅ | ✅ |
| Settings / Profile | ✅ | ✅ | ✅ |
| Users and Access | ✅ | ✅ | ✅ |
| Complaint Type | ✅ | ✅ | ✅ |
Admins also have exclusive access to:
- Users and Access page (sidebar only shows for admin role)
- Business Profile section on Profile page (logo and business name)
Editor (Example — Custom Permissions)
Editors get whatever permissions the admin assigns. Example configurations:
Customer Service Editor
| Page | View | Edit | Delete |
|---|---|---|---|
| Dashboard | ✅ | — | — |
| Complaints | ✅ | ✅ | — |
| Resolution Workflow | ✅ | ✅ | — |
| Settings | ✅ | — | — |
Senior Agent
| Page | View | Edit | Delete |
|---|---|---|---|
| Dashboard | ✅ | — | — |
| Complaints | ✅ | ✅ | ✅ |
| Resolution Workflow | ✅ | ✅ | ✅ |
| Complaint Type | ✅ | ✅ | — |
Viewer (Example)
| Page | View | Edit | Delete |
|---|---|---|---|
| Dashboard | ✅ | ❌ | ❌ |
| Complaints | ✅ | ❌ | ❌ |
| Resolution Workflow | ✅ | ❌ | ❌ |
Viewers can:
- See dashboard stats
- Browse complaints and workflows
- Copy customer messages
- Open complaint detail and print views
Viewers cannot:
- Add, edit, or delete any records
- Access Users and Access
- Change business profile
How Permissions Are Enforced
Permissions are checked at multiple layers:
1. Middleware
- Requires a valid login session cookie for all routes except
/loginand auth API routes - Does not check roles — only authentication
2. Route Guard (LayoutContent)
- Maps current URL to a page key
- Redirects to the first page the user can view if they lack access
- Logs out if the user has no viewable pages at all
3. Sidebar Menu
- Menu items are filtered by
canView(pageKey) - Users and Access only appears for
role === 'admin' - Complaint Type only appears if user has view permission
4. Page Components
- Each page checks permissions before showing content
- Action buttons (Add, Edit, Delete) are hidden when permission is missing
- Unauthorized users see "You do not have access" message
5. API Routes
- User CRUD (
/api/users/*) — Admin only - Business profile update and logo upload — Admin only
- Password change — Authenticated user (own account)
- Complaint image upload — Any authenticated user
Note: Complaints, workflows, and complaint types are read/written directly via Supabase client from the browser. API-level permission enforcement for these is handled by the UI, not separate API middleware.
Default Permissions (New Database)
When cms-schema.sql is run:
Admin user (admin@admin.com):
- All pages, all permissions set to
true
Non-admin users (if created without explicit permissions):
- Default view-only on: Dashboard, Complaints, Resolution Workflow, Settings
- No access to Users and Access or Complaint Type unless explicitly granted
Managing Permissions (Admin Guide)
Create a New User
- Go to Settings → Users and Access
- Click Add User
- Fill in name, email, password, and role
- Set permissions in the grid (View / Edit / Delete per page)
- Save
Change Existing User Permissions
- Find the user in the table
- Click Edit
- Update role and/or permission checkboxes
- Save — changes apply on the user's next page load
Best Practices
| Scenario | Recommended Setup |
|---|---|
| Team lead / manager | Admin role |
| Customer service agent | Editor — View + Edit on Complaints and Resolution Workflow |
| Read-only auditor | Viewer — View only on Dashboard, Complaints, Resolution Workflow |
| Template manager | Editor — View + Edit on Complaint Type only |
| New trainee | Viewer — View on Complaints only |
Security Notes
- Change the default admin password immediately after setup
- Use strong passwords (minimum 6 characters enforced; recommend 12+)
- Set a strong
JWT_SECRETin production (32+ random characters) - Review user permissions periodically
- Remove users who no longer need access
Permission Helper Functions (Developer Reference)
The AuthContext exposes these helpers used throughout the UI:
canView(pageKey: string): boolean // Can open the page
canEdit(pageKey: string): boolean // Can add/modify records
canDelete(pageKey: string): boolean // Can delete records
For admin users, all three always return true.
For viewer role, canEdit and canDelete always return false.