Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user friendly message of ecosystem roles if user does not have access #529

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions apps/api-gateway/src/authz/guards/ecosystem-roles.guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BadRequestException, CanActivate, ExecutionContext, Logger } from '@nestjs/common';
import { BadRequestException, CanActivate, ExecutionContext, ForbiddenException, Logger } from '@nestjs/common';

import { HttpException } from '@nestjs/common';
import { HttpStatus } from '@nestjs/common';
Expand Down Expand Up @@ -69,7 +69,12 @@ export class EcosystemRolesGuard implements CanActivate {
throw new HttpException('organization & ecosystem is required', HttpStatus.BAD_REQUEST);
}

return requiredRoles.some((role) => user.ecosystemOrgRole === role);

// Sending user friendly message if a user attempts to access an API that is inaccessible to their role
const roleAccess = requiredRoles.some((role) => user.ecosystemOrgRole === role);
if (!roleAccess) {
throw new ForbiddenException(ResponseMessages.organisation.error.roleNotMatch, { cause: new Error(), description: ResponseMessages.errorMessages.forbidden });
}

return roleAccess;
}
}