2.8 KiB
2.8 KiB
User Management IT Admin Only Review
1. Summary
Updated User Management access so the พนักงาน menu and related /dashboard/users + /api/users* endpoints are available only to IT admin access (IT business role and super_admin via existing role mapping). HRD/Admin keeps access to รายชื่อพนักงานทั้งหมด and the rest of the master-data menu.
2. Files Changed
src/config/nav-config.tssrc/types/index.tssrc/hooks/use-nav.tssrc/lib/auth/roles.tssrc/lib/auth/session.tssrc/lib/auth/page-guards.tssrc/app/dashboard/users/page.tsxsrc/app/api/users/route.tssrc/app/api/users/[id]/route.tssrc/features/users/server/user-data.tssrc/features/users/info-content.ts
3. Navigation Changes
- Added support for
businessRolesin nav access rules. - Changed
พนักงานunderข้อมูลหลักto visible only forIT. - Kept
รายชื่อพนักงานทั้งหมด,หลักสูตร,นโยบาย, andประกาศvisible for bothHRDandIT. - Updated nav filtering so parent items with no visible children are hidden instead of leaving a stray direct link.
4. Permission Rules
- Added
requireUserManagementAccess()as the shared access gate for user-management features. - Changed
canManageUsers()to allow only IT user-management access instead of any organizer admin. - Existing
super_adminbehavior is preserved because the current business-role mapping resolvessuper_admintoIT.
5. Route Protection
/dashboard/usersnow usesrequireUserManagementDashboardAccess().- Unauthorized users are redirected using the existing dashboard guard behavior.
6. API Protection
/api/users/api/users/[id]
Both routes now require requireUserManagementAccess() before any list, options, create, update, or deactivate action.
7. Manual Test Checklist
- Admin IT sees
พนักงานmenu. - HRD/Admin does not see
พนักงานmenu. - Employee does not see
พนักงานmenu. - HRD/Admin still sees
รายชื่อพนักงานทั้งหมด. - Admin IT can open
/dashboard/users. - HRD/Admin cannot open
/dashboard/usersby direct URL. - Employee cannot open
/dashboard/usersby direct URL. - User management APIs reject HRD/Admin.
- Employee Directory is not affected.
- Other menus still work.
8. Known Limitations
- This change assumes the current role mapping remains:
super_admin=>IT, organizer admin =>HRD, member =>EMPLOYEE. - There is no dedicated
admin_itdatabase field yet; access still relies on the existing derived business-role model. - Only the current
/dashboard/userspage exists in App Router right now, so no additional/dashboard/users/[id]page update was needed.