Roles và permission
LMS có bốn role chính: ADMIN, ORG_ADMIN, TEACHER, STUDENT. Frontend dùng role.guard.ts, backend dùng @PreAuthorize và kiểm tra ownership theo use case/controller.
Matrix nhanh
| Role | Portal | Quyền chính | Không nên nói nhầm |
|---|---|---|---|
ADMIN |
/admin và có thể inspect teacher authoring |
Toàn hệ thống, settings, logs, gateway status, duyệt/xóa theo quyền hệ thống | Đây là role system-level |
ORG_ADMIN |
/org-admin hoặc admin operations |
Quản lý vận hành trong tổ chức, course review, user/course ops theo org | Không vào teacher authoring flow; teacherGuard hiện không cho ORG_ADMIN |
TEACHER |
/teacher |
Tạo khóa học, editor, lớp học, quiz, assignment, grading, revenue | Không có quyền system settings |
STUDENT |
/student |
Học, ghi danh, thanh toán, làm quiz/assignment, offline learning | Không được mutate course authoring |
Guard frontend
| Guard | Role được phép | Dùng cho |
|---|---|---|
studentGuard |
STUDENT |
Student-only pages |
teacherOnlyGuard |
TEACHER |
Teacher dashboard/courses/revenue |
teacherGuard |
TEACHER, ADMIN |
Course editor/authoring route, admin có thể inspect |
adminGuard |
ADMIN, ORG_ADMIN |
Admin operations portal |
systemAdminGuard |
ADMIN |
Settings/logs/system-only |
systemAdminPortalGuard |
ADMIN |
Điều hướng admin path cho đúng role |
orgAdminPortalGuard |
ORG_ADMIN |
Org admin portal |
Nguồn chính: fe/src/app/core/guards/role.guard.ts.
Auth session
| Thành phần | File | Ý nghĩa |
|---|---|---|
| JWT login/register/refresh | AuthControllerV3, AuthService |
Tạo và lưu session |
| Google OAuth redirect | GoogleOAuthRedirectController, AuthService.hydrateFromOAuthRedirect |
Login qua Google theo redirect |
| Multi-org | V119__multi_org_foundation.sql |
Gắn user/course vào organization |
| External identities | V114__user_external_identities.sql |
Lưu Google/external identity |
| Must change password | AuthService.applyAuthenticatedSession |
Nếu mustChangePassword thì chuyển sang /auth/change-password |
| Offline soft logout | AuthService.softLogout |
Khi offline chỉ clear UI session, giữ token/cache để resume |
Backend ownership
- Course authoring không chỉ dựa vào role. Controller/use case còn kiểm tra teacher có sở hữu course hoặc được gán dạy lớp.
- ORG_ADMIN thường được coi là admin trong operations, nhưng với teacher authoring frontend thì không đi vào flow chỉnh bài như teacher.
- Payment/admin queries của ORG_ADMIN lọc theo organization, không xem bừa giao dịch tổ chức khác.
Khi bảo vệ, trả lời ngắn: “Role mở cửa trước, ownership/use case mới quyết định có được sửa entity cụ thể hay không.”