Commit 63bddca
feat: admin and roles (#270)
# Admin System with Role-Based Access Control
## Summary
This PR introduces a complete user admin system with role-based access
control (RBAC), user management capabilities, and enhanced MCP server
sharing (featured) features. The implementation provides organizations
with control over users and user permissions while maintaining a clean
interface for all user roles.
It is designed to keep functionality the same for users who are not
interested in the admin features but adds the ability to manage users,
and restrict access and functionality for users who are not admins.
Before this PR, everyone would be an "editor" in this system. That is
still the default role. The FIRST user who registers becomes an admin
for a new installation. For existing installations, users will need to
update the user record to role to "admin" in the database to use the
admin features. It seemed like too much of a security risk to do this in
an automated way, but I would be open to a more automated solution if we
find a way to do it safely.
## Key Features
### 1. 🏢 Full Admin System
#### User Management Dashboard
<img width="1280" height="1061" alt="01-admin-users-list"
src="https://github.com/user-attachments/assets/1258120e-c005-4d72-8d65-8f7311db788c"
/>
_Comprehensive user listing with search, sorting, and pagination_
- **Advanced User Table**: Displays user information with sortable
columns for name, email, role, status, and creation date
- **Search & Filter**: Real-time search functionality with state
preservation across navigation
- **Pagination**: Efficient handling of large user bases with
configurable items per page
- **Quick Navigation**: Click any user row to view detailed information
#### Search Functionality
Can search by user name or email with case-insensitive, fuzzy matching.
<img width="1280" height="720" alt="80-admin-users-search-14"
src="https://github.com/user-attachments/assets/441cadf1-681e-4544-b70f-1879dc6d2c79"
/>
_Real-time search: typing "14" instantly finds "Test User 14"_
#### Sorting
Can sort by role, date joined or user name.
<img width="1280" height="1063" alt="03-admin-users-sorted"
src="https://github.com/user-attachments/assets/4410e5ce-621a-4a3d-a5da-bb96a2023be2"
/>
_Sort users by role, date joined or user name_
### 2. 👤 User Detail Management
<img width="1280" height="720" alt="61-admin-user-detail-edit-form"
src="https://github.com/user-attachments/assets/44b0017d-1c65-490c-bd64-3fab31aa961f"
/>
_Admin user detail page showing full management interface with real
usage statistics (1,558 tokens across 5 models)_
- **Profile Editing**: Admins can modify user name, email, and reset
passwords
- **Status Management**: Ban/unban users with reason tracking (visible
in users list with "Banned" badge)
- **Role Assignment**: Edit roles through dedicated interface (Admin,
Editor, User)
- **Security Controls**: Password reset, account status management
- **Danger Zone**: Delete user with confirmation (requires typing user
name)
- **Activity Tracking**: View join date, last updated, and usage
statistics
### 3. 📊 AI Usage Analytics
<img width="1280" height="720" alt="62-admin-user-statistics"
src="https://github.com/user-attachments/assets/143891ab-4a6f-49a9-9f22-693ecb11a735"
/>
The user detail page includes comprehensive statistics when available.
Users who haven't used AI assistants yet will see "No AI Activity Yet"
message.
- **Usage Statistics**: Track token consumption, model usage, and
message counts
- **Top Models**: Visualize which AI models users prefer (gpt-4o,
claude-3.5-sonnet, gemini-2.0-flash)
- **Activity Timeline**: See user engagement patterns over the last 30
days
- **Graceful Degradation**: Stats fail gracefully for providers without
telemetry
### 4. 🔐 Three-Tier Role System
This is a starter system that could be expanded to include more roles
and permissions in the future, most likely with dynamic roles and
permissions controlled in the admin dashboard.
#### Admin Role
- Can do everything an Editor (the current default role) can do, plus:
- Full user management capabilities
- Create and feature MCP servers for organization-wide use
- Access to all administrative functions
- View detailed usage statistics across all users
#### Editor Role (Default)
<img width="1280" height="720" alt="13-agents-page-editor"
src="https://github.com/user-attachments/assets/26182a33-8ce7-4afd-9536-8da0bc6d5ac0"
/>
_Editors can create, use, and share agents, workflows. This image is an
example of the agents view._
- Create and manage agents, workflows, and MCP connections
- Share resources with other users
- Full app functionality except admin features
- Self-service profile management
#### User Role
<img width="1280" height="720" alt="16-agents-page-user"
src="https://github.com/user-attachments/assets/2779ce01-b585-4054-aa78-0f9b43eaea09"
/>
_Users can use shared agents and workflows. This image is an example of
the agent view. Users can still "bookmark" agents to show them in their
own sidebar._
- Use shared agents and workflows
- Access featured MCP servers
- Bookmark favorite resources
- Cannot create new resources (simplified experience)
### 5. 🔌 MCP Server Management
When introducing roles, MCP servers were global and there the only way
to get MCP servers up for all users was via file based MCP servers
configs, which was prolematic and bug prone. While MCP server
"featuring" and user specific MCPs were not originally part of the scope
of this PR, it made sense to include it since roles were being
introduced and implmented for features.
Using the same "private" and "public" visibility options as agents and
workflows and the same sharing component, mcps can be featured by
admins. Public = Featured, the logic is the same but the term "featured"
made more sense.
Admins are the only ones who can feature MCP servers, since sharing MCP
servers would be less common than sharing agents and workflows and too
many MCP servers can significantly impact performance.
#### Admin MCP Dashboard
<img width="1280" height="720" alt="68-admin-mcp-all-servers"
src="https://github.com/user-attachments/assets/96e7ba07-8696-48ed-8a76-565791d34cd6"
/>
_Admins can create and feature MCP servers_
#### Role-Based MCP Views
- **Admins**: Can create, use and feature MCP servers
- **Editors**: Can create and use personal MCP connections and use
featured ones
- **Users**: Can only use featured MCP servers
**Editors**
Editors can create and manage their own MCP servers and use featured
ones
<img width="1280" height="720" alt="69-editor-mcp-servers"
src="https://github.com/user-attachments/assets/0a5f8e1b-8900-4e13-ab8a-560be1accb1a"
/>
**Users**
Users see and use featured MCP servers
<img width="1280" height="720" alt="71-user-mcp-featured-only"
src="https://github.com/user-attachments/assets/7ed424c0-c5dc-44b0-ae38-d9d553d52d13"
/>
### 6. 🛠️ Workflow Management
Wofkflows have not been changed except that the "user" role cannot
create workflows, they can only use shared ones.
#### Admin Workflow Dashboard
Admins can create, use and share workflows.
<img width="1280" height="720" alt="71-admin-workflows"
src="https://github.com/user-attachments/assets/6749378f-4e0c-4b29-acd8-a73c76567ae2"
/>
_Admins can create, use and share workflows_
#### Editor Workflow Access
Editors can create, use and share workflows.
<img width="1280" height="720" alt="72-editor-workflows"
src="https://github.com/user-attachments/assets/5bbea6a3-0d13-471a-a358-1aa77046a645"
/>
_Editors can create, use and share workflows_
#### User Workflow Access
Users can use shared workflows.
<img width="1280" height="720" alt="73-user-workflows"
src="https://github.com/user-attachments/assets/57ec3c77-7e85-402f-ae3e-86e860dda332"
/>
_Users can use shared workflows_
### 7. 👥 Self-Service Features
Users can access and edit their own profile information with the same
interface that admins see, but with restricted permissions:
- Users can edit their own profile (name, email, password)
- Password updates are only available for users with password
authentication
- OAuth-only users cannot set passwords
- Simple user settings interface
- Users can view their "stats" for the last 30 days
### 8. 🌍 Internationalization
- All fields are translatable, the current language for new fields is
English
## Technical Implementation
### Architecture Highlights
- **Repository Pattern**: Clean separation of data access logic
- **Server Components**: Leveraging Next.js 15 server components and
React 19 Form Actions for optimal performance
- **Role-Based Middleware**: Secure API routes with automatic permission
checks
- **Optimistic Updates User Updates**: User updates are immediately
reflected in the UI with optimistic updates
### Security Features
- **Role-based access control** at API and UI levels
- **Self-modification restrictions**: Users cannot change their own
roles
- **Secure password updates**: Verification required for own password
changes, admins can set passwords for other users
- **Ban system**: Prevents access while maintaining audit trail
- **Permission boundaries**: Clear separation between roles
## Testing Coverage
### Comprehensive E2E Test Suite
This PR includes **3,500+ lines of new E2E tests** across 14 test files,
ensuring coverage of all new features:
#### Test Files Added/Modified:
- **Admin System Tests** (21 tests)
- `admin-permissions.spec.ts` - Admin access control
- `admin-user-detail.spec.ts` - User management operations
- `admin-users-list.spec.ts` - User listing and search
- **Permission System Tests** (30 tests)
- `mcp-permissions.spec.ts` - MCP server role-based access
- `resource-permissions.spec.ts` - Agent/workflow permissions
- **User Experience Tests**
- `user-settings-popup.spec.ts` - Self-service features
- `user-name-sync.spec.ts` - Profile updates
- Authentication flow updates
### E2E Test Coverage Areas
✅ User listing, search, and pagination
✅ User detail viewing and editing
✅ Role assignment and restrictions
✅ Ban/unban functionality
✅ Delete user with confirmation
✅ MCP server visibility rules
✅ Featured vs private servers
✅ Agent/workflow permissions
✅ Self-service profile editing
✅ Statistics display and empty states
✅ Navigation state preservation
✅ First user admin assignment
✅ Role-based UI variations
### Test Infrastructure Improvements
- Multi-user auth states for parallel testing
- Seeded test data for consistent scenarios
- State preservation validation
- Permission boundary testing
## Database Migration Notes
12_kind_multiple_man.sql was updated to migrate model and usage data to
the new metadata format. This will only affect users who have not run
that migration yet, since the migration will have dropped those columns.
It doesn't break anything but did lose any usage or model stats for
existing chats. This migration update will maintain that existing data.
Added 13_graceful_leo.sql migrates for the admin system, roles and fixes
some cascade issues noticed in automated cleanup scripts.
### Environment Variables
No new environment variables required. The system uses the existing auth
configuration.
## Breaking Changes
- None. All existing functionality remains intact. MCP servers are all
migrated to the 1st user in the database (which may be updated to an
admin by updating that row in the database)
- New users default to the 'editor' role, maintaining the current
behavior
- Existing MCP configurations continue working the same.
## Performance Considerations
- **Lazy Loading**: Statistics load asynchronously to prevent blocking
- **Pagination**: Efficient handling of large user bases
- **Search Debouncing**: Prevents excessive API calls
- **Optimistic Updates**: Immediate UI feedback for better UX
- **Suspense Boundaries**: Graceful loading states throughout
## Future Enhancements
The architecture supports these planned features:
- User groups for team collaboration
- Model access control per user/group
- Spending limits and usage quotas
- Audit logs for compliance
Future UX improvements:
- Better UX for "featured" MCP servers, the existing interface was used,
and we might want to show more information about what they do.
- Better UX for "featured" agents. I've found my users having a hard
time finding shared agents, an essential feature for our company, since
they are the ones who will be using them.
## Review Checklist
- [ ] Database migrations tested
- [ ] Role permissions verified
- [ ] UI responsive on all screen sizes
- [ ] Error messages helpful
- [ ] Loading states smooth
- [ ] Search functionality fast
- [ ] Statistics display correctly
- [ ] Ban functionality works
- [ ] Self-service features accessible
---------
Co-authored-by: choi sung keun <[email protected]>
Co-authored-by: cgoing <[email protected]>1 parent 5eb4701 commit 63bddca
File tree
188 files changed
+16176
-2038
lines changed- .github/workflows
- docs/tips-guides
- messages
- scripts
- src
- app
- (auth)
- sign-in
- sign-up
- email
- (chat)
- (admin)
- admin/users
- (list)
- [id]
- agents
- agent/[id]
- mcp
- workflow
- [id]
- api
- admin
- agent
- [id]
- auth
- chat
- openai-realtime
- temporary
- mcp
- [id]
- list
- user
- details
- [id]
- workflow
- [id]
- execute
- structure
- tools
- store
- components
- admin
- agent
- auth
- layouts
- tool-invocation
- ui
- user/user-detail
- workflow
- node-config
- hooks
- queries
- lib
- admin
- ai
- mcp
- auth
- db
- migrations/pg
- meta
- pg
- repositories
- user
- validations
- types
- tests
- admin
- agents
- auth
- constants
- core
- fixtures
- helpers
- lifecycle
- models
- permissions
- user
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
188 files changed
+16176
-2038
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
87 | 90 | | |
88 | 91 | | |
89 | 92 | | |
| |||
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
95 | | - | |
| 98 | + | |
96 | 99 | | |
97 | | - | |
98 | | - | |
| 100 | + | |
| 101 | + | |
99 | 102 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
84 | 73 | | |
85 | | - | |
86 | | - | |
87 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
88 | 77 | | |
89 | | - | |
90 | | - | |
91 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
92 | 81 | | |
93 | | - | |
| 82 | + | |
94 | 83 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
98 | 87 | | |
99 | 88 | | |
100 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
20 | | - | |
| 19 | + | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
90 | 88 | | |
91 | | - | |
| 89 | + | |
92 | 90 | | |
93 | 91 | | |
94 | 92 | | |
| |||
103 | 101 | | |
104 | 102 | | |
105 | 103 | | |
106 | | - | |
107 | 104 | | |
108 | 105 | | |
109 | 106 | | |
| |||
144 | 141 | | |
145 | 142 | | |
146 | 143 | | |
147 | | - | |
| 144 | + | |
148 | 145 | | |
149 | 146 | | |
150 | 147 | | |
| 148 | + | |
151 | 149 | | |
152 | 150 | | |
153 | 151 | | |
| |||
277 | 275 | | |
278 | 276 | | |
279 | 277 | | |
280 | | - | |
| 278 | + | |
281 | 279 | | |
282 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
283 | 294 | | |
284 | 295 | | |
285 | 296 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | 86 | | |
91 | | - | |
92 | 87 | | |
93 | 88 | | |
94 | 89 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | 90 | | |
102 | 91 | | |
103 | 92 | | |
104 | 93 | | |
105 | | - | |
| 94 | + | |
106 | 95 | | |
107 | | - | |
| 96 | + | |
108 | 97 | | |
109 | 98 | | |
110 | 99 | | |
| |||
116 | 105 | | |
117 | 106 | | |
118 | 107 | | |
| 108 | + | |
119 | 109 | | |
120 | | - | |
| 110 | + | |
121 | 111 | | |
122 | 112 | | |
123 | 113 | | |
| |||
128 | 118 | | |
129 | 119 | | |
130 | 120 | | |
| 121 | + | |
131 | 122 | | |
132 | | - | |
| 123 | + | |
133 | 124 | | |
134 | 125 | | |
135 | 126 | | |
| |||
142 | 133 | | |
143 | 134 | | |
144 | 135 | | |
| 136 | + | |
145 | 137 | | |
146 | 138 | | |
147 | 139 | | |
148 | 140 | | |
149 | | - | |
| 141 | + | |
150 | 142 | | |
151 | 143 | | |
152 | 144 | | |
153 | 145 | | |
154 | 146 | | |
155 | | - | |
| 147 | + | |
156 | 148 | | |
157 | 149 | | |
158 | 150 | | |
| |||
213 | 205 | | |
214 | 206 | | |
215 | 207 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | 208 | | |
221 | 209 | | |
222 | 210 | | |
223 | 211 | | |
224 | 212 | | |
225 | | - | |
| 213 | + | |
226 | 214 | | |
227 | 215 | | |
228 | | - | |
| 216 | + | |
229 | 217 | | |
230 | 218 | | |
231 | | - | |
| 219 | + | |
232 | 220 | | |
233 | 221 | | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | 222 | | |
241 | 223 | | |
242 | 224 | | |
| |||
286 | 268 | | |
287 | 269 | | |
288 | 270 | | |
289 | | - | |
| 271 | + | |
290 | 272 | | |
291 | | - | |
| 273 | + | |
292 | 274 | | |
293 | 275 | | |
294 | 276 | | |
| |||
310 | 292 | | |
311 | 293 | | |
312 | 294 | | |
| 295 | + | |
313 | 296 | | |
314 | 297 | | |
315 | 298 | | |
316 | 299 | | |
317 | 300 | | |
318 | | - | |
| 301 | + | |
319 | 302 | | |
320 | 303 | | |
321 | 304 | | |
| |||
0 commit comments