fix: align permission navigation and page access

This commit is contained in:
2026-07-11 14:55:49 +08:00
parent 1e1c476bc3
commit b6fca99390
27 changed files with 434 additions and 49 deletions

View File

@@ -1,12 +1,17 @@
import { PRESET_ROLES } from './rbac.service';
function permissionsFor(roleCode: string): { groups: string[]; extras: string[] } {
const role = PRESET_ROLES.find((item) => item.code === roleCode);
if (!role) throw new Error(`missing role ${roleCode}`);
return { groups: role.permissionGroups, extras: role.extraPermissions ?? [] };
}
describe('preset role permissions', () => {
it('gives teachers explicit workspace permissions without class/schedule delete privileges', () => {
const teacher = PRESET_ROLES.find((role) => role.code === 'teacher');
const teacher = permissionsFor('teacher');
expect(teacher).toBeDefined();
expect(teacher?.permissionGroups).toEqual(['notification', 'profile']);
expect(teacher?.extraPermissions).toEqual(
expect(teacher.groups).toEqual(['notification', 'profile']);
expect(teacher.extras).toEqual(
expect.arrayContaining([
'student:view',
'class:view',
@@ -16,8 +21,18 @@ describe('preset role permissions', () => {
'attendance:export',
]),
);
expect(teacher?.extraPermissions).not.toEqual(
expect(teacher.extras).not.toEqual(
expect.arrayContaining(['class:delete', 'schedule:delete']),
);
});
it('gives institution heads every read permission required by the classroom rental pages', () => {
const role = permissionsFor('institution_head');
expect(role.groups).toEqual(expect.arrayContaining(['classroom', 'rental', 'organization']));
});
it('keeps roles without dashboard access off the dashboard', () => {
expect(permissionsFor('teacher').groups).not.toContain('dashboard');
expect(permissionsFor('institution_head').groups).not.toContain('dashboard');
});
});