Apply RBAC permissions across admin and tasks

Enforce page access and action-level permissions across admin and task views, including exports and record actions. Move user creation to a client component behind server-side permission checks, standardize data fetching, and remove the deprecated user-role route.
This commit is contained in:
Ichsan Kurniawan
2026-11-09 17:32:31 +07:00
parent 1b37ff65f5
commit 279b642a7a
69 changed files with 1070 additions and 1167 deletions
+22 -8
View File
@@ -44,24 +44,38 @@ export const getAccessData = cache(async () => {
});
export async function getAccessPagePermission(path: string, action: string = "view") {
export async function getAccessPagePermission(path: string | string[], action: string = "view") {
const accessData = await getAccessData();
const normalize = (p: string) => (p || '').trim().replace(/^\/+|\/+$/g, '').toLowerCase();
const targetPaths = (Array.isArray(path) ? path : [path]).map(normalize);
// Check whether the current page is registered
const menu = accessData?.role_detail?.find((item: any) => item.menu?.path_url === path);
const menu = accessData?.role_detail?.find((item: any) => {
const itemPath = normalize(item.menu?.path_url || '');
if (!itemPath) return false;
if (targetPaths.includes(itemPath)) return true;
if (targetPaths.includes('rbac/action-permissions') && itemPath === 'rbac/action-pemission') return true;
if (targetPaths.includes('rbac/action-pemission') && itemPath === 'rbac/action-permissions') return true;
return false;
});
if (!menu?.menu) {
// redirect(redirectPage);
forbidden()
forbidden();
}
// Role-specific assigned actions take precedence; fallback to menu actions if role actions are absent
const permittedActions: string[] = (Array.isArray(menu?.action) && menu.action.length > 0)
? menu.action
: (Array.isArray(menu?.menu?.action) ? menu.menu.action : []);
// Check whether the user has permission
if (!menu?.menu?.action?.includes(action.toUpperCase())) {
// redirect(redirectPage);
forbidden()
const hasPermission = permittedActions.some((act: string) => act.toUpperCase() === action.toUpperCase());
if (!hasPermission) {
forbidden();
}
return menu?.menu?.action;
return permittedActions;
}