feat: RBAC Phase 2e - Verwaltung auf @RequirePermission umgestellt, Coverage-Test aktiviert
Users, Webhooks, Automation, Import, AuditLog: die klassenweiten @Roles(Role.ADMIN)-Blankets (die gefaehrlichsten der Migration, da sie JEDE Route der Klasse abdecken) durch pro-Route @RequirePermission ersetzt. Effektiver Zugriff unveraendert: ADMIN besitzt weiterhin alle betroffenen Permission-Keys, jede andere Rolle bleibt ausgeschlossen. Damit ist kein @Roles(...) mehr in der Codebase in Benutzung - alle 23 Controller laufen jetzt vollstaendig ueber @RequirePermission. test/authorization-coverage.e2e-spec.ts (bisher it.skip mit TODO fuer "nach Phase 2") ist jetzt scharf geschaltet und bestaetigt: 0 Routen ohne Rechte-Pruefung, 0 ungueltige Permission-Keys. Verifiziert: tsc, lint, build, unit (222/222), volle e2e-Suite 159/159 gruen - keine uebersprungenen Tests mehr. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
1 parent
8832081973
commit
0284077d3b
6 files changed
+19
-21
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { LegacyRole as Role } from '../../generated/prisma';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||
import { AuditLogService } from './audit-log.service';
|
||||
|
||||
@ApiTags('audit-log')
|
||||
@@ -10,7 +9,7 @@ import { AuditLogService } from './audit-log.service';
|
||||
export class AuditController {
|
||||
constructor(private readonly auditLogService: AuditLogService) {}
|
||||
|
||||
@Roles(Role.ADMIN)
|
||||
@RequirePermission('audit:read')
|
||||
@Get()
|
||||
findAll(
|
||||
@Query('entityType') entityType?: string,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Body, Controller, Get, Param, Patch } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { LegacyRole as Role } from '../../generated/prisma';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||
import { AutomationService } from './automation.service';
|
||||
@@ -9,16 +8,17 @@ import { UpdateAutomationRuleDto } from './dto/update-automation-rule.dto';
|
||||
|
||||
@ApiTags('automation-rules')
|
||||
@ApiBearerAuth()
|
||||
@Roles(Role.ADMIN)
|
||||
@Controller('automation-rules')
|
||||
export class AutomationController {
|
||||
constructor(private readonly automationService: AutomationService) {}
|
||||
|
||||
@RequirePermission('automation:read')
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.automationService.findAll();
|
||||
}
|
||||
|
||||
@RequirePermission('automation:update')
|
||||
@Patch(':id')
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||
import { LegacyRole as Role } from '../../generated/prisma';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||
import { ImportService } from './import.service';
|
||||
@@ -18,11 +17,11 @@ const MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
|
||||
|
||||
@ApiTags('import')
|
||||
@ApiBearerAuth()
|
||||
@Roles(Role.ADMIN)
|
||||
@Controller('import')
|
||||
export class ImportController {
|
||||
constructor(private readonly importService: ImportService) {}
|
||||
|
||||
@RequirePermission('import:execute')
|
||||
@Post(':entity')
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@UseInterceptors(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { LegacyRole as Role } from '../../generated/prisma';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
@@ -11,25 +10,28 @@ import { UsersService } from './users.service';
|
||||
@ApiTags('users')
|
||||
@ApiBearerAuth()
|
||||
@Controller('users')
|
||||
@Roles(Role.ADMIN)
|
||||
export class UsersController {
|
||||
constructor(private readonly usersService: UsersService) {}
|
||||
|
||||
@RequirePermission('users:read')
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.usersService.findAll();
|
||||
}
|
||||
|
||||
@RequirePermission('users:create')
|
||||
@Post()
|
||||
create(@Body() dto: CreateUserDto, @CurrentUser() actor: AuthenticatedUser) {
|
||||
return this.usersService.create(dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('users:read')
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.usersService.findSummaryById(id);
|
||||
}
|
||||
|
||||
@RequirePermission('users:update')
|
||||
@Patch(':id')
|
||||
update(
|
||||
@Param('id') id: string,
|
||||
@@ -39,11 +41,13 @@ export class UsersController {
|
||||
return this.usersService.update(id, dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('users:deactivate')
|
||||
@Post(':id/deactivate')
|
||||
deactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
||||
return this.usersService.deactivate(id, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('users:deactivate')
|
||||
@Post(':id/activate')
|
||||
activate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
||||
return this.usersService.activate(id, actor.id);
|
||||
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
Post,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { LegacyRole as Role } from '../../generated/prisma';
|
||||
import { Roles } from '../auth/decorators/roles.decorator';
|
||||
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||
import { CreateWebhookDto } from './dto/create-webhook.dto';
|
||||
@@ -17,16 +16,17 @@ import { WebhooksService } from './webhooks.service';
|
||||
|
||||
@ApiTags('webhooks')
|
||||
@ApiBearerAuth()
|
||||
@Roles(Role.ADMIN)
|
||||
@Controller('webhooks')
|
||||
export class WebhooksController {
|
||||
constructor(private readonly webhooksService: WebhooksService) {}
|
||||
|
||||
@RequirePermission('webhooks:read')
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.webhooksService.findAll();
|
||||
}
|
||||
|
||||
@RequirePermission('webhooks:create')
|
||||
@Post()
|
||||
create(
|
||||
@Body() dto: CreateWebhookDto,
|
||||
@@ -35,6 +35,7 @@ export class WebhooksController {
|
||||
return this.webhooksService.create(dto, actor.id);
|
||||
}
|
||||
|
||||
@RequirePermission('webhooks:delete')
|
||||
@Delete(':id')
|
||||
@HttpCode(204)
|
||||
delete(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
||||
|
||||
@@ -22,12 +22,7 @@ const ALLOWLIST = new Set([
|
||||
]);
|
||||
|
||||
describe('Authorization coverage (e2e)', () => {
|
||||
// TODO(RBAC migration): re-enable once every controller carries
|
||||
// @RequirePermission (Phase 2 of the RBAC rollout). Right now most GET
|
||||
// routes have no @Roles/@RequirePermission at all (authenticated-only),
|
||||
// which this test correctly flags — that's the known, tracked starting
|
||||
// state, not a regression to fix here.
|
||||
it.skip('every non-public route requires a role or a catalog-valid permission', async () => {
|
||||
it('every non-public route requires a role or a catalog-valid permission', async () => {
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
imports: [AppModule, DiscoveryModule],
|
||||
}).compile();
|
||||
|
||||
Reference in new issue
Block a user