-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/credebl/credebl-platform …
…into endorser-request-and-submit Signed-off-by: tipusinghaw <tipu.singh@ayanworks.com>
- Loading branch information
Showing
18 changed files
with
671 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { CustomDecorator } from '@nestjs/common'; | ||
import { OrgRoles } from 'libs/org-roles/enums'; | ||
import { SetMetadata } from '@nestjs/common'; | ||
import { EcosystemRoles } from '@credebl/enum/enum'; | ||
|
||
export const ROLES_KEY = 'roles'; | ||
export const ECOSYSTEM_ROLES_KEY = 'ecosystem_roles'; | ||
export const Roles = (...roles: OrgRoles[]): CustomDecorator<string> => SetMetadata(ROLES_KEY, roles); | ||
export const EcosystemsRoles = (...roles: EcosystemRoles[]): CustomDecorator<string> => SetMetadata(ECOSYSTEM_ROLES_KEY, roles); | ||
export const Permissions = (...permissions: string[]): CustomDecorator<string> => SetMetadata('permissions', permissions); | ||
export const Subscriptions = (...subscriptions: string[]): CustomDecorator<string> => SetMetadata('subscriptions', subscriptions); | ||
|
64 changes: 64 additions & 0 deletions
64
apps/api-gateway/src/authz/guards/ecosystem-roles.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { CanActivate, ExecutionContext, Logger } from '@nestjs/common'; | ||
|
||
import { HttpException } from '@nestjs/common'; | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { ECOSYSTEM_ROLES_KEY } from '../decorators/roles.decorator'; | ||
import { Reflector } from '@nestjs/core'; | ||
import { EcosystemService } from '../../ecosystem/ecosystem.service'; | ||
import { EcosystemRoles } from '@credebl/enum/enum'; | ||
|
||
@Injectable() | ||
export class EcosystemRolesGuard implements CanActivate { | ||
constructor( | ||
private reflector: Reflector, | ||
private readonly ecosystemService: EcosystemService // Inject the service | ||
) { } | ||
|
||
|
||
private logger = new Logger('Ecosystem Role Guard'); | ||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const requiredRoles = this.reflector.getAllAndOverride<EcosystemRoles[]>(ECOSYSTEM_ROLES_KEY, [ | ||
context.getHandler(), | ||
context.getClass() | ||
]); | ||
const requiredRolesNames = Object.values(requiredRoles) as string[]; | ||
|
||
if (!requiredRolesNames) { | ||
return true; | ||
} | ||
|
||
// Request requires org check, proceed with it | ||
const req = context.switchToHttp().getRequest(); | ||
|
||
const { user } = req; | ||
|
||
if ((req.params.orgId || req.query.orgId || req.body.orgId) | ||
&& (req.params.ecosystemId || req.query.ecosystemId || req.body.ecosystemId)) { | ||
|
||
const orgId = req.params.orgId || req.query.orgId || req.body.orgId; | ||
const ecosystemId = req.params.ecosystemId || req.query.ecosystemId || req.body.ecosystemId; | ||
|
||
|
||
const ecosystemOrgData = await this.ecosystemService.fetchEcosystemOrg(ecosystemId, orgId); | ||
|
||
if (!ecosystemOrgData) { | ||
throw new HttpException('Organization does not match', HttpStatus.FORBIDDEN); | ||
} | ||
|
||
const {response} = ecosystemOrgData; | ||
|
||
user.ecosystemOrgRole = response['ecosystemRole']['name']; | ||
|
||
if (!user.ecosystemOrgRole) { | ||
throw new HttpException('Ecosystem role not match', HttpStatus.FORBIDDEN); | ||
} | ||
|
||
} else { | ||
throw new HttpException('organization & ecosystem is required', HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
return requiredRoles.some((role) => user.ecosystemOrgRole === role); | ||
|
||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/api-gateway/src/ecosystem/dtos/accept-reject-ecosysteminvitation-dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { IsEnum, IsNotEmpty} from 'class-validator'; | ||
|
||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Invitation } from '@credebl/enum/enum'; | ||
import { Transform } from 'class-transformer'; | ||
import { trim } from '@credebl/common/cast.helper'; | ||
|
||
export class AcceptRejectEcosystemInvitationDto { | ||
|
||
ecosystemId: string; | ||
invitationId: string; | ||
orgId: string; | ||
|
||
@ApiProperty({ | ||
enum: [Invitation.ACCEPTED, Invitation.REJECTED] | ||
}) | ||
@Transform(({ value }) => trim(value)) | ||
@IsNotEmpty({ message: 'Please provide valid status' }) | ||
@IsEnum(Invitation) | ||
status: Invitation.ACCEPTED | Invitation.REJECTED; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/api-gateway/src/ecosystem/dtos/get-all-sent-invitations.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Transform, Type } from 'class-transformer'; | ||
import { toNumber } from '@credebl/common/cast.helper'; | ||
|
||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsOptional } from 'class-validator'; | ||
|
||
export class GetAllEcosystemInvitationsDto { | ||
@ApiProperty({ required: false, default: 1 }) | ||
@IsOptional() | ||
@Type(() => Number) | ||
@Transform(({ value }) => toNumber(value)) | ||
pageNumber = 1; | ||
|
||
@ApiProperty({ required: false }) | ||
@IsOptional() | ||
@Type(() => String) | ||
search = ''; | ||
|
||
@ApiProperty({ required: false }) | ||
@IsOptional() | ||
@Type(() => Number) | ||
@Transform(({ value }) => toNumber(value)) | ||
pageSize = 10; | ||
|
||
} |
Oops, something went wrong.