121 lines
4.5 KiB
JavaScript
121 lines
4.5 KiB
JavaScript
export const ACL_MODULES = [
|
|
{ key: 'users', label: 'Users' },
|
|
{ key: 'roles', label: 'Roles' },
|
|
{ key: 'patients', label: 'Master Patients' },
|
|
{ key: 'sessions', label: 'Sessions' },
|
|
{ key: 'onboarding', label: 'Patients' },
|
|
{ key: 'cohorts', label: 'Cohorts' },
|
|
{ key: 'prt_cohorts', label: 'Add PRT cohorts' },
|
|
{ key: 'holidays', label: 'Holidays' },
|
|
{ key: 'leaves', label: 'Leave' },
|
|
{ key: 'matching', label: 'Matching' },
|
|
{ key: 'reports', label: 'Reports' },
|
|
{ key: 'program_sessions', label: 'Program Sessions' },
|
|
{ key: 'whatsapp', label: 'WhatsApp' },
|
|
];
|
|
|
|
export const ACL_ACTIONS = ['view', 'add', 'edit', 'delete', 'import'];
|
|
|
|
export const SYSTEM_ROLE_KEYS = ['super_admin', 'admin', 'educator', 'physical_prt'];
|
|
|
|
function perm(module, actions, scope = 'all') {
|
|
return { module, actions: [...actions], scope };
|
|
}
|
|
|
|
export const SYSTEM_ROLE_PERMISSIONS = {
|
|
super_admin: [
|
|
perm('users', ['view', 'add', 'edit', 'delete']),
|
|
perm('roles', ['view', 'add', 'edit', 'delete']),
|
|
perm('patients', ['view', 'add', 'edit', 'delete', 'import']),
|
|
perm('sessions', ['view', 'add', 'edit', 'delete']),
|
|
perm('onboarding', ['view', 'add', 'edit', 'delete']),
|
|
perm('cohorts', ['view', 'add', 'edit', 'delete']),
|
|
perm('prt_cohorts', ['view', 'add', 'edit', 'delete']),
|
|
perm('holidays', ['view', 'add', 'edit', 'delete']),
|
|
perm('leaves', ['view', 'add', 'edit', 'delete']),
|
|
perm('matching', ['view', 'add', 'edit', 'delete']),
|
|
perm('reports', ['view']),
|
|
perm('program_sessions', ['view', 'add', 'edit']),
|
|
perm('whatsapp', ['view', 'edit']),
|
|
],
|
|
admin: [
|
|
perm('users', ['view', 'add', 'edit', 'delete']),
|
|
perm('roles', ['view']),
|
|
perm('patients', ['view', 'add', 'edit', 'delete', 'import']),
|
|
perm('sessions', ['view', 'add', 'edit', 'delete']),
|
|
perm('onboarding', ['view', 'add', 'edit', 'delete']),
|
|
perm('cohorts', ['view', 'add', 'edit', 'delete']),
|
|
perm('prt_cohorts', ['view', 'add', 'edit', 'delete']),
|
|
perm('holidays', ['view', 'add', 'edit', 'delete']),
|
|
perm('leaves', ['view', 'add', 'edit', 'delete']),
|
|
perm('matching', ['view', 'add', 'edit', 'delete']),
|
|
perm('reports', ['view']),
|
|
perm('program_sessions', ['view', 'edit']),
|
|
perm('whatsapp', ['view', 'edit']),
|
|
],
|
|
educator: [
|
|
perm('onboarding', ['view', 'add', 'edit', 'delete'], 'assigned'),
|
|
perm('cohorts', ['view'], 'assigned'),
|
|
perm('prt_cohorts', ['view', 'add', 'edit', 'delete'], 'assigned'),
|
|
perm('holidays', ['view']),
|
|
perm('leaves', ['view', 'add', 'edit'], 'assigned'),
|
|
perm('program_sessions', ['view', 'edit'], 'assigned'),
|
|
perm('reports', ['view'], 'assigned'),
|
|
],
|
|
physical_prt: [
|
|
perm('onboarding', ['view', 'add', 'edit', 'delete'], 'assigned'),
|
|
perm('holidays', ['view']),
|
|
perm('leaves', ['view', 'add', 'edit'], 'assigned'),
|
|
],
|
|
};
|
|
|
|
export const SYSTEM_ROLE_META = {
|
|
super_admin: {
|
|
name: 'Super Admin',
|
|
description: 'Full access to all modules, including role permissions.',
|
|
},
|
|
admin: {
|
|
name: 'Admin',
|
|
description: 'Manage users, patients, master patients, and sessions. Cannot change ACL or Super Admin accounts.',
|
|
},
|
|
educator: {
|
|
name: 'PRT',
|
|
description: 'Pulmonary Rehab Therapist. Manage assigned patients and cohorts, and view holidays and leave.',
|
|
},
|
|
physical_prt: {
|
|
name: 'Physical PRT',
|
|
description: 'Physical Pulmonary Rehab Therapist. Manage assigned patients, and view holidays and leave.',
|
|
},
|
|
};
|
|
|
|
export function actionsInclude(entryActions, action) {
|
|
if (!Array.isArray(entryActions)) return false;
|
|
if (entryActions.includes(action)) return true;
|
|
if (action === 'view' && (entryActions.includes('edit') || entryActions.includes('add') || entryActions.includes('delete'))) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function normalizePermissions(permissions) {
|
|
const byModule = new Map();
|
|
for (const p of permissions || []) {
|
|
if (!p?.module) continue;
|
|
const existing = byModule.get(p.module) || { module: p.module, actions: [], scope: 'all' };
|
|
existing.actions = [...new Set([...existing.actions, ...(p.actions || [])])];
|
|
existing.scope = p.scope === 'assigned' ? 'assigned' : existing.scope === 'assigned' ? 'assigned' : 'all';
|
|
byModule.set(p.module, existing);
|
|
}
|
|
return [...byModule.values()];
|
|
}
|
|
|
|
export function permissionsToMaps(permissions) {
|
|
const modules = {};
|
|
const scopes = {};
|
|
for (const p of normalizePermissions(permissions)) {
|
|
modules[p.module] = p.actions;
|
|
scopes[p.module] = p.scope || 'all';
|
|
}
|
|
return { modules, scopes };
|
|
}
|