A comprehensive role-based client visibility system has been implemented that allows administrators to control whether each role can see all clients in the system or only clients assigned to their user account.
- New Permission:
view_all_clients - If a role has this permission =
true: Users can see ALL clients in the system - If a role has this permission =
false: Users can only see:- Clients assigned to them (where
salesRepIdmatches their user ID) - Unassigned clients (where
salesRepIdisnull)
- Clients assigned to them (where
| Role | view_all_clients | Description |
|---|---|---|
| ADMIN | ✅ true | Can view all clients |
| ADMINISTRATION | ✅ true | Can view all clients |
| INTERNAL | ❌ false | Only assigned/unassigned clients |
| EXTERNAL | ❌ false | Only assigned/unassigned clients |
Administrators can modify these settings through the admin panel:
- Navigate to Admin Dashboard
- Find the Role Permissions section
- Toggle the
view_all_clientspermission for each role as needed
All client-related API endpoints now enforce visibility rules:
GET /api/clients- Filters clients based on visibility permissionsGET /api/clients/[id]- Checks if user can view specific clientPUT /api/clients/[id]- Checks if user can edit specific clientDELETE /api/clients/[id]- Checks if user can delete specific client
GET /api/clients/export- Only exports visible clientsPOST /api/clients/import- Imports with current user's permissions
- Client List Page: Shows visibility status indicator
- Individual Client Page: Blocks access to unauthorized clients
- Action buttons only show when user has proper permissions
- Clear feedback when access is denied
/src/lib/client-visibility.ts- Core visibility logic/src/hooks/useClientVisibility.ts- Frontend permission hooks/src/components/ClientVisibilityIndicator.tsx- UI indicators
- All client routes updated with visibility filters
- Consistent permission checking across all endpoints
-
Grant Full Access: Set
view_all_clients = truefor a role- Users in this role will see all clients regardless of assignment
-
Restrict to Assigned Only: Set
view_all_clients = falsefor a role- Users will only see clients where they are the assigned sales rep
- Users will also see unassigned clients (for potential assignment)
- Sees indicator: "You can view all clients in the system"
- Can access any client detail page
- Export includes all clients
- Sees indicator: "You can only view clients assigned to you or unassigned clients"
- Cannot access client detail pages for clients assigned to others
- Export only includes their assigned clients + unassigned ones
- Data Isolation: Sales reps can't see each other's clients
- Flexible Management: Admins can easily adjust visibility rules
- Audit Trail: All access attempts are logged
- Consistent Enforcement: Both frontend and backend enforce the same rules
- Existing clients remain visible to all users until an admin adjusts role permissions
- No data migration required - the system works with existing client assignments
- Default permissions are automatically set up via the initialization script
Run the initialization script to set up default permissions:
node src/scripts/init-client-visibility-permissions.jsThen test with different user roles to verify the visibility rules work as expected.