feat: RBAC Phase 3 - LegacyRole-Enum, RolesGuard und @Roles vollstaendig entfernt

Letzte Phase des RBAC-Umbaus: die transitionale Rollen-Infrastruktur,
die seit Phase 1 parallel zum neuen Role/Permission-System mitlief,
ist jetzt komplett weg.

- Prisma-Migration: User.legacyRole-Spalte und LegacyRole-Enum
  gedroppt (nichts liest die Spalte mehr, seit Phase 2 jeder Controller
  auf @RequirePermission laeuft).
- roles.guard.ts, roles.guard.spec.ts, roles.decorator.ts geloescht;
  RolesGuard aus den APP_GUARD-Providern entfernt.
- AuthenticatedUser/JWT-Payload verlieren das role-Feld (permissions
  werden ohnehin frisch pro Request aus der DB aufgeloest, nicht aus
  dem Claim).
- Users-API: CreateUserDto/UpdateUserDto akzeptieren jetzt roleId
  (eine echte Role.id) statt der alten role-Enum-Werte; UsersService
  validiert, dass die Rolle existiert und aktiv ist, bevor sie
  zugewiesen wird.
- Alle 34 e2e-Fixtures und der Seed-Script folgen dem neuen Schema.

Verifiziert: tsc, lint, build, unit (220/220), volle e2e-Suite
159/159 gruen - keine uebersprungenen Tests.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
Nick SzaunigandClaude Sonnet 5 committed 2026-08-26 09:01:13 +02:00
1 parent 0284077d3b
commit ae53f7889e
51 files changed
+125 -224

No files matched your search

@@ -13,18 +13,25 @@ describe('UsersService', () => {
update: jest.Mock;
};
role: {
findUniqueOrThrow: jest.Mock;
findUnique: jest.Mock;
};
};
let auditLog: { record: jest.Mock };
const staffRole = {
id: 'role-staff',
key: 'STAFF',
name: 'Mitarbeiter',
status: 'ACTIVE',
};
const existingUser = {
id: 'user-1',
email: '[email protected]',
passwordHash: 'hashed',
name: 'Existing User',
legacyRole: 'STAFF',
roleId: 'role-staff',
roleId: staffRole.id,
role: staffRole,
isActive: true,
createdAt: new Date(),
deactivatedAt: null,
@@ -39,9 +46,7 @@ describe('UsersService', () => {
update: jest.fn(),
},
role: {
findUniqueOrThrow: jest
.fn()
.mockResolvedValue({ id: 'role-staff', key: 'STAFF' }),
findUnique: jest.fn().mockResolvedValue(staffRole),
},
};
auditLog = { record: jest.fn().mockResolvedValue(undefined) };
@@ -61,7 +66,9 @@ describe('UsersService', () => {
id: existingUser.id,
email: existingUser.email,
name: existingUser.name,
role: existingUser.legacyRole,
roleId: staffRole.id,
roleKey: staffRole.key,
roleName: staffRole.name,
isActive: existingUser.isActive,
createdAt: existingUser.createdAt,
deactivatedAt: existingUser.deactivatedAt,
@@ -84,7 +91,36 @@ describe('UsersService', () => {
email: existingUser.email,
password: 'password123',
name: 'New',
role: 'STAFF',
roleId: staffRole.id,
}),
).rejects.toBeInstanceOf(ConflictException);
});
it('create throws NotFoundException when the role does not exist', async () => {
prisma.user.findUnique.mockResolvedValue(null);
prisma.role.findUnique.mockResolvedValue(null);
await expect(
usersService.create({
email: '[email protected]',
password: 'password123',
name: 'New User',
roleId: 'missing-role',
}),
).rejects.toBeInstanceOf(NotFoundException);
});
it('create throws ConflictException when the role is not active', async () => {
prisma.user.findUnique.mockResolvedValue(null);
prisma.role.findUnique.mockResolvedValue({
...staffRole,
status: 'INACTIVE',
});
await expect(
usersService.create({
email: '[email protected]',
password: 'password123',
name: 'New User',
roleId: staffRole.id,
}),
).rejects.toBeInstanceOf(ConflictException);
});
@@ -101,7 +137,7 @@ describe('UsersService', () => {
email: '[email protected]',
password: 'password123',
name: 'New User',
role: 'STAFF',
roleId: staffRole.id,
});
expect(result.id).toBe('user-2');