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 { Controller, Get, Query } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { LegacyRole as Role } from '../../generated/prisma';
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||||
import { Roles } from '../auth/decorators/roles.decorator';
|
|
||||||
import { AuditLogService } from './audit-log.service';
|
import { AuditLogService } from './audit-log.service';
|
||||||
|
|
||||||
@ApiTags('audit-log')
|
@ApiTags('audit-log')
|
||||||
@@ -10,7 +9,7 @@ import { AuditLogService } from './audit-log.service';
|
|||||||
export class AuditController {
|
export class AuditController {
|
||||||
constructor(private readonly auditLogService: AuditLogService) {}
|
constructor(private readonly auditLogService: AuditLogService) {}
|
||||||
|
|
||||||
@Roles(Role.ADMIN)
|
@RequirePermission('audit:read')
|
||||||
@Get()
|
@Get()
|
||||||
findAll(
|
findAll(
|
||||||
@Query('entityType') entityType?: string,
|
@Query('entityType') entityType?: string,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Body, Controller, Get, Param, Patch } from '@nestjs/common';
|
import { Body, Controller, Get, Param, Patch } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { LegacyRole as Role } from '../../generated/prisma';
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||||
import { Roles } from '../auth/decorators/roles.decorator';
|
|
||||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||||
import { AutomationService } from './automation.service';
|
import { AutomationService } from './automation.service';
|
||||||
@@ -9,16 +8,17 @@ import { UpdateAutomationRuleDto } from './dto/update-automation-rule.dto';
|
|||||||
|
|
||||||
@ApiTags('automation-rules')
|
@ApiTags('automation-rules')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Roles(Role.ADMIN)
|
|
||||||
@Controller('automation-rules')
|
@Controller('automation-rules')
|
||||||
export class AutomationController {
|
export class AutomationController {
|
||||||
constructor(private readonly automationService: AutomationService) {}
|
constructor(private readonly automationService: AutomationService) {}
|
||||||
|
|
||||||
|
@RequirePermission('automation:read')
|
||||||
@Get()
|
@Get()
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.automationService.findAll();
|
return this.automationService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('automation:update')
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(
|
update(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
|
||||||
import { LegacyRole as Role } from '../../generated/prisma';
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||||
import { Roles } from '../auth/decorators/roles.decorator';
|
|
||||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||||
import { ImportService } from './import.service';
|
import { ImportService } from './import.service';
|
||||||
@@ -18,11 +17,11 @@ const MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
|
|||||||
|
|
||||||
@ApiTags('import')
|
@ApiTags('import')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Roles(Role.ADMIN)
|
|
||||||
@Controller('import')
|
@Controller('import')
|
||||||
export class ImportController {
|
export class ImportController {
|
||||||
constructor(private readonly importService: ImportService) {}
|
constructor(private readonly importService: ImportService) {}
|
||||||
|
|
||||||
|
@RequirePermission('import:execute')
|
||||||
@Post(':entity')
|
@Post(':entity')
|
||||||
@ApiConsumes('multipart/form-data')
|
@ApiConsumes('multipart/form-data')
|
||||||
@UseInterceptors(
|
@UseInterceptors(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { LegacyRole as Role } from '../../generated/prisma';
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||||
import { Roles } from '../auth/decorators/roles.decorator';
|
|
||||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
@@ -11,25 +10,28 @@ import { UsersService } from './users.service';
|
|||||||
@ApiTags('users')
|
@ApiTags('users')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Controller('users')
|
@Controller('users')
|
||||||
@Roles(Role.ADMIN)
|
|
||||||
export class UsersController {
|
export class UsersController {
|
||||||
constructor(private readonly usersService: UsersService) {}
|
constructor(private readonly usersService: UsersService) {}
|
||||||
|
|
||||||
|
@RequirePermission('users:read')
|
||||||
@Get()
|
@Get()
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.usersService.findAll();
|
return this.usersService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('users:create')
|
||||||
@Post()
|
@Post()
|
||||||
create(@Body() dto: CreateUserDto, @CurrentUser() actor: AuthenticatedUser) {
|
create(@Body() dto: CreateUserDto, @CurrentUser() actor: AuthenticatedUser) {
|
||||||
return this.usersService.create(dto, actor.id);
|
return this.usersService.create(dto, actor.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('users:read')
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
findOne(@Param('id') id: string) {
|
findOne(@Param('id') id: string) {
|
||||||
return this.usersService.findSummaryById(id);
|
return this.usersService.findSummaryById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('users:update')
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(
|
update(
|
||||||
@Param('id') id: string,
|
@Param('id') id: string,
|
||||||
@@ -39,11 +41,13 @@ export class UsersController {
|
|||||||
return this.usersService.update(id, dto, actor.id);
|
return this.usersService.update(id, dto, actor.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('users:deactivate')
|
||||||
@Post(':id/deactivate')
|
@Post(':id/deactivate')
|
||||||
deactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
deactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
||||||
return this.usersService.deactivate(id, actor.id);
|
return this.usersService.deactivate(id, actor.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('users:deactivate')
|
||||||
@Post(':id/activate')
|
@Post(':id/activate')
|
||||||
activate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
activate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
||||||
return this.usersService.activate(id, actor.id);
|
return this.usersService.activate(id, actor.id);
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
import { LegacyRole as Role } from '../../generated/prisma';
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
||||||
import { Roles } from '../auth/decorators/roles.decorator';
|
|
||||||
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
||||||
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
||||||
import { CreateWebhookDto } from './dto/create-webhook.dto';
|
import { CreateWebhookDto } from './dto/create-webhook.dto';
|
||||||
@@ -17,16 +16,17 @@ import { WebhooksService } from './webhooks.service';
|
|||||||
|
|
||||||
@ApiTags('webhooks')
|
@ApiTags('webhooks')
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Roles(Role.ADMIN)
|
|
||||||
@Controller('webhooks')
|
@Controller('webhooks')
|
||||||
export class WebhooksController {
|
export class WebhooksController {
|
||||||
constructor(private readonly webhooksService: WebhooksService) {}
|
constructor(private readonly webhooksService: WebhooksService) {}
|
||||||
|
|
||||||
|
@RequirePermission('webhooks:read')
|
||||||
@Get()
|
@Get()
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.webhooksService.findAll();
|
return this.webhooksService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('webhooks:create')
|
||||||
@Post()
|
@Post()
|
||||||
create(
|
create(
|
||||||
@Body() dto: CreateWebhookDto,
|
@Body() dto: CreateWebhookDto,
|
||||||
@@ -35,6 +35,7 @@ export class WebhooksController {
|
|||||||
return this.webhooksService.create(dto, actor.id);
|
return this.webhooksService.create(dto, actor.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequirePermission('webhooks:delete')
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
delete(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
delete(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) {
|
||||||
|
|||||||
@@ -22,12 +22,7 @@ const ALLOWLIST = new Set([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
describe('Authorization coverage (e2e)', () => {
|
describe('Authorization coverage (e2e)', () => {
|
||||||
// TODO(RBAC migration): re-enable once every controller carries
|
it('every non-public route requires a role or a catalog-valid permission', async () => {
|
||||||
// @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 () => {
|
|
||||||
const moduleRef = await Test.createTestingModule({
|
const moduleRef = await Test.createTestingModule({
|
||||||
imports: [AppModule, DiscoveryModule],
|
imports: [AppModule, DiscoveryModule],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|||||||
Reference in new issue
Block a user