mirror of
http://172.20.10.11:3000/gitadmin/INSIGHT-MVP.git
synced 2026-06-25 01:36:39 +02:00
- TenantGuard: remove PLATFORM_ADMIN bypass, require tenantId for all users - lexware-contacts.service: add defensive tenantId check in importAsCompany and importAsContact with clear BadRequestException message Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
723 B
TypeScript
25 lines
723 B
TypeScript
import {
|
|
Injectable,
|
|
CanActivate,
|
|
ExecutionContext,
|
|
ForbiddenException,
|
|
} from '@nestjs/common';
|
|
import { JwtPayload } from '../../common/decorators/current-user.decorator';
|
|
|
|
@Injectable()
|
|
export class TenantGuard implements CanActivate {
|
|
canActivate(context: ExecutionContext): boolean {
|
|
const request = context.switchToHttp().getRequest();
|
|
const user = request.user as JwtPayload;
|
|
|
|
// Alle User (auch PLATFORM_ADMIN) muessen eine tenantId haben
|
|
// um auf tenant-spezifische CRM-Ressourcen zuzugreifen.
|
|
if (!user?.tenantId) {
|
|
throw new ForbiddenException(
|
|
'Kein Mandant zugeordnet. Bitte mit einem mandanten-gebundenen Account anmelden.',
|
|
);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|