Repository navigation
User Roles & Permissions
- Introduction
- Workspace Role Hierarchy
- Educational Role Mapping
- Authorization Middleware
- Permissions Mapping
- Architecture Overview
- Conclusion
PersonalLearningPro uses a multi-layered permission system. Access is controlled by both a user's System Role (e.g., Student, Teacher) and their Workspace Role (e.g., Owner, Admin). This ensures that while a teacher has access to educational tools, their actions are scoped to the specific workspaces they belong to.
Roles are defined per workspace and stored in the workspace_memberships table.
| Role | Access Level | Responsibilities |
|---|---|---|
| Owner | Full Control | Billing, workspace settings, deleting workspace, managing admins. |
| Admin | Management | Inviting members/students, content moderation, analytics. |
| Member | Standard | Accessing channels, participating in tests, using AI tutor. |
Every user also has a system-wide role which determines their default UI and educational capabilities.
- Admin/Owner: Typically used for school principals or business managers.
- Teacher: Used for instructors; grants permission to create tests and manage classrooms.
- Student: Default role for learners; grants permission to attempt tests and view results.
The server uses specialized middleware to enforce these roles:
-
authenticateToken: Verifies the JWT and injectsreq.userandreq.workspace. -
requireWorkspaceRole('owner', 'admin'): Restricts access to workspace management features. -
requireActiveWorkspace: Ensures the user is acting within a valid workspace context.
Permissions are dynamically calculated based on the user's role in their active workspace.
// server/lib/auth-workspace.ts
export function permissionsForWorkspaceRole(role?: WorkspaceRole): string[] {
if (role === "owner") {
return [
"workspace:read",
"workspace:update",
"workspace:billing",
"workspace:invite",
"workspace:members:manage",
];
}
// ...
}Permissions flow from the database into the JWT session and are then enforced by the server and reflected in the UI.
graph TD
DB[(PostgreSQL)] --> Auth["Auth Service<br/>(Issue JWT)"]
Auth --> JWT["JWT Session<br/>(userId, workspaceRole)"]
JWT --> MW["Server Middleware<br/>(RBAC Guard)"]
JWT --> UI["Frontend Context<br/>(Feature Gating)"]
The unified role system provides granular control over both institutional management and educational workflows. By combining relational workspace memberships with stateless JWT claims, the platform achieves high performance and strict security boundaries.