Role-Based Permission System Implementation Summary¶
✅ What's Been Implemented¶
Backend (Already Exists)¶
- Database Schema
permissionstable - stores all available permissionsrolestable - team-specific roles with editable flagrole_permissionsjunction table - many-to-many relationship-
Migration file:
2025_12_17_0002_seed_permissions_catalog.py -
Default Permissions Seeded
*- All permissions (wildcard)team.manage- Manage team settings and rolesteam.invite- Invite team membersevents:read- Read SSE eventsbilling.view- View billingbilling.edit- Edit billingserver.create- Create serverserver.restart- Restart server-
server.delete- Delete server -
Default Roles Created per Team
- Owner (not editable): Has
*permission - Manager (editable): Has team., billing., server.*, events:read
-
Developer (editable): Has server.*, events:read
-
API Endpoints
GET /api/v1/rbac/permissions- List all permissionsGET /api/v1/rbac/teams/{teamId}/roles- List team rolesPOST /api/v1/rbac/teams/{teamId}/roles- Create custom rolePATCH /api/v1/rbac/teams/{teamId}/roles/{roleId}- Update role metadataPUT /api/v1/rbac/teams/{teamId}/roles/{roleId}/permissions- Update role permissionsDELETE /api/v1/rbac/teams/{teamId}/roles/{roleId}- Delete role-
PUT /api/v1/rbac/teams/{teamId}/members/{userId}/role- Assign role to member -
Security Features
- Automatic session revocation when permissions change
- Owner role protection (cannot be edited/deleted)
- In-use role protection (cannot delete roles assigned to members)
- Cross-tenant access prevention
Frontend (Newly Created)¶
-
Type Definitions (
frontend/src/features/teams/types/team.types.ts) -
Service Methods (
frontend/src/features/teams/services/teamService.ts) getPermissions()- Fetch all available permissionsgetRoles(teamId)- Fetch team rolescreateRole(teamId, name, description, permissionSlugs)- Create custom roleupdateRolePermissions(teamId, roleId, permissionSlugs)- Update permissionsdeleteRole(teamId, roleId)- Delete role-
assignMemberRole(teamId, userId, roleId)- Assign role to member -
RoleManagement Component (
frontend/src/features/teams/components/RoleManagement.tsx)
Features: - Grid display of all team roles - Role cards showing name, description, and first 3 permissions - Hover tooltip showing ALL permissions with descriptions - Visual badges for "System" and "Default" roles - "Create Custom Role" button (only for users with team.manage permission)
Create Role Dialog: - Name and description fields - Grouped permission checkboxes by category (team, billing, server, events) - Select All / Deselect All buttons - Permission counter - Validation (name required, at least one permission)
Edit Permissions Dialog: - Same checkbox interface as create - Pre-selected with current role permissions - Only available for editable roles
Role Card Actions: - "Edit Permissions" button (for editable roles) - "Delete" button with confirmation (for editable roles) - Actions hidden for system roles and non-managers
📋 How to Use¶
1. Import the Component¶
2. Use in Your Page¶
function TeamSettingsPage() {
const user = useCurrentUser(); // Your auth hook
return (
<RoleManagement
teamId={user.team_id}
currentUserPermissions={user.permissions}
/>
);
}
3. Permission Requirements¶
- View roles: Any team member
- Create/Edit/Delete roles:
team.manageor*permission
🎨 UI Features¶
Role Card Display¶
- Name with system/default badges
- Description text
- First 3 permissions as chips
- "+X more" indicator
Hover Tooltip¶
- Shows complete permission list
- Permission name formatted (e.g., "Server Create")
- Permission description
- Dark theme with arrow pointer
- Scrollable for long lists
Dialogs¶
- Full-screen overlay
- Responsive design
- Category-grouped permissions
- Real-time validation
- Error handling with user feedback
🔒 Security Notes¶
-
Permissions from Database: All permissions are stored in and fetched from the database (not hardcoded)
-
Default Roles on Team Creation: When a new team is created, the backend automatically seeds Owner, Manager, and Developer roles
-
Session Security: Changing role permissions automatically revokes all sessions for affected users
-
Protected Roles: Owner role cannot be modified or deleted
-
In-Use Protection: Roles assigned to members cannot be deleted
📁 Files Modified/Created¶
Created:¶
- ✅
frontend/src/features/teams/components/RoleManagement.tsx- Main component - ✅
frontend/src/features/teams/components/index.ts- Export barrel - ✅
frontend/src/app/team-settings/roles/page.example.tsx- Usage example - ✅ This summary file
Modified:¶
- ✅
frontend/src/features/teams/types/team.types.ts- Added Permission interface - ✅
frontend/src/features/teams/services/teamService.ts- Added RBAC methods - ✅
docs/architecture/team_management.md- Updated TDD with implementation guide
Already Existed (Backend):¶
- ✅
backend/app/infrastructure/database/models/rbac.py- Models - ✅
backend/app/modules/rbac/router.py- API endpoints - ✅
backend/app/modules/rbac/service.py- Business logic - ✅
backend/app/modules/rbac/schemas.py- Pydantic schemas - ✅
backend/app/infrastructure/database/migrations/versions/2025_12_17_0002_seed_permissions_catalog.py- Permission seeding
🚀 Next Steps¶
-
Integrate into Team Settings Page:
-
Add to Navigation: Add a "Roles & Permissions" link in your team settings sidebar
-
Customize Styling: The component uses Tailwind classes - adjust colors to match your design system
-
Add More Permissions: Update the migration file to add new permissions as your app grows
❓ FAQ¶
Q: Where are permissions stored?
A: In the permissions database table, seeded via Alembic migration.
Q: Can I add more permissions later? A: Yes! Create a new Alembic migration to insert additional permissions.
Q: How do I show default permissions on hover? A: The component automatically shows all permissions in a tooltip when you hover over any role card.
Q: Can users create completely custom roles?
A: Yes! Users with team.manage permission can create custom roles with any combination of permissions (except the wildcard *).
Q: What happens to users when I change role permissions? A: Their sessions are automatically revoked, forcing them to re-authenticate with the new permissions.
Q: Can I edit the Owner role? A: No, the Owner role is system-protected and cannot be edited or deleted.