From ec206f1685877dec93a85617d3275e2c557dd03e Mon Sep 17 00:00:00 2001 From: samuel Date: Tue, 13 Feb 2024 16:23:33 +0100 Subject: [PATCH] fixes --- apps/authz/src/app/evaluation-request.dto.ts | 2 +- .../dto/base-admin-request-payload.dto.ts | 4 +-- .../dto/create-organization-request.dto.ts | 8 ++--- .../http/rest/dto/create-user-request.dto.ts | 34 ++++++++----------- .../set-policy-rules-request.dto.ts | 6 ++-- .../set-policy-rules-response.dto.ts | 2 +- .../validate-criterion.decorator.ts | 4 +-- 7 files changed, 26 insertions(+), 34 deletions(-) diff --git a/apps/authz/src/app/evaluation-request.dto.ts b/apps/authz/src/app/evaluation-request.dto.ts index 171442e28..2fbcae332 100644 --- a/apps/authz/src/app/evaluation-request.dto.ts +++ b/apps/authz/src/app/evaluation-request.dto.ts @@ -131,7 +131,7 @@ export class EvaluationRequestDto { @IsOptional() @ValidateNested() @ApiProperty({ - type: () => RequestSignatureDto, + type: RequestSignatureDto, isArray: true }) approvals?: RequestSignatureDto[] diff --git a/apps/authz/src/app/http/rest/dto/base-admin-request-payload.dto.ts b/apps/authz/src/app/http/rest/dto/base-admin-request-payload.dto.ts index cc56b51ef..d3caeb654 100644 --- a/apps/authz/src/app/http/rest/dto/base-admin-request-payload.dto.ts +++ b/apps/authz/src/app/http/rest/dto/base-admin-request-payload.dto.ts @@ -8,14 +8,14 @@ export class BaseAdminRequestPayloadDto { @IsDefined() @ValidateNested() @Type(() => RequestSignatureDto) - @ApiProperty({ type: () => RequestSignatureDto }) + @ApiProperty({ type: RequestSignatureDto }) authentication: RequestSignatureDto @ArrayNotEmpty() @ValidateNested({ each: true }) @Type(() => RequestSignatureDto) @ApiProperty({ - type: () => RequestSignatureDto, + type: RequestSignatureDto, isArray: true }) approvals: RequestSignatureDto[] diff --git a/apps/authz/src/app/http/rest/dto/create-organization-request.dto.ts b/apps/authz/src/app/http/rest/dto/create-organization-request.dto.ts index 58f2290de..2ea29bf35 100644 --- a/apps/authz/src/app/http/rest/dto/create-organization-request.dto.ts +++ b/apps/authz/src/app/http/rest/dto/create-organization-request.dto.ts @@ -15,13 +15,11 @@ class CreateOrganizationDataDto { @IsDefined() @ValidateNested() @Type(() => AuthCredentialDto) - @ApiProperty({ type: String }) + @ApiProperty({ type: AuthCredentialDto }) credential: AuthCredentialDto } class CreateOrganizationActionDto extends BaseActionDto { - @IsString() - @IsNotEmpty() @Matches(Action.CREATE_ORGANIZATION) @ApiProperty({ default: Action.CREATE_ORGANIZATION }) action: typeof Action.CREATE_ORGANIZATION @@ -29,7 +27,7 @@ class CreateOrganizationActionDto extends BaseActionDto { @IsDefined() @ValidateNested() @Type(() => CreateOrganizationDataDto) - @ApiProperty({ type: () => CreateOrganizationDataDto }) + @ApiProperty({ type: CreateOrganizationDataDto }) organization: CreateOrganizationDataDto } @@ -37,6 +35,6 @@ export class CreateOrganizationRequestDto extends BaseAdminRequestPayloadDto { @IsDefined() @ValidateNested() @Type(() => CreateOrganizationActionDto) - @ApiProperty({ type: () => CreateOrganizationActionDto }) + @ApiProperty({ type: CreateOrganizationActionDto }) request: CreateOrganizationActionDto } diff --git a/apps/authz/src/app/http/rest/dto/create-user-request.dto.ts b/apps/authz/src/app/http/rest/dto/create-user-request.dto.ts index a6230b8b3..efa24841c 100644 --- a/apps/authz/src/app/http/rest/dto/create-user-request.dto.ts +++ b/apps/authz/src/app/http/rest/dto/create-user-request.dto.ts @@ -1,42 +1,37 @@ import { Action, UserRole } from '@narval/authz-shared' import { ApiExtraModels, ApiProperty } from '@nestjs/swagger' -import { IsDefined, IsIn, IsOptional, IsString, ValidateNested } from 'class-validator' +import { Type } from 'class-transformer' +import { IsDefined, IsEnum, IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator' import { AuthCredentialDto } from './auth-credential.dto' import { BaseActionDto } from './base-action.dto' import { BaseAdminRequestPayloadDto } from './base-admin-request-payload.dto' class CreateUserDataDto { @IsString() - @IsDefined() - @ApiProperty() + @IsNotEmpty() + @ApiProperty({ type: String }) uid: string - @IsIn(Object.values(UserRole)) - @IsDefined() - @ApiProperty({ - enum: Object.values(UserRole) - }) + @IsEnum(UserRole) + @ApiProperty({ enum: UserRole }) role: UserRole - @IsString() - @IsOptional() - @ApiProperty() + @IsDefined() @ValidateNested() + @Type(() => AuthCredentialDto) + @ApiProperty({ type: AuthCredentialDto }) credential?: AuthCredentialDto } class CreateUserActionDto extends BaseActionDto { - @IsIn(Object.values(Action)) - @IsDefined() - @ApiProperty({ - enum: Object.values(Action), - default: Action.CREATE_USER - }) + @Matches(Action.CREATE_USER) + @ApiProperty({ default: Action.CREATE_USER }) action: typeof Action.CREATE_USER @IsDefined() @ValidateNested() - @ApiProperty() + @Type(() => CreateUserDataDto) + @ApiProperty({ type: CreateUserDataDto }) user: CreateUserDataDto } @@ -44,6 +39,7 @@ class CreateUserActionDto extends BaseActionDto { export class CreateUserRequestDto extends BaseAdminRequestPayloadDto { @IsDefined() @ValidateNested() - @ApiProperty() + @Type(() => CreateUserActionDto) + @ApiProperty({ type: CreateUserActionDto }) request: CreateUserActionDto } diff --git a/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts b/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts index 3a0fe523c..a5b0c0058 100644 --- a/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts +++ b/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-request.dto.ts @@ -1,14 +1,12 @@ import { Action } from '@narval/authz-shared' import { ApiProperty } from '@nestjs/swagger' import { Type } from 'class-transformer' -import { ArrayNotEmpty, IsDefined, IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator' +import { ArrayNotEmpty, IsDefined, Matches, ValidateNested } from 'class-validator' import { Policy } from '../../../../../shared/types/policy.type' import { BaseActionDto } from '../base-action.dto' import { BaseAdminRequestPayloadDto } from '../base-admin-request-payload.dto' export class SetPolicyRulesDto extends BaseActionDto { - @IsString() - @IsNotEmpty() @Matches(Action.SET_POLICY_RULES) @ApiProperty({ default: Action.SET_POLICY_RULES }) action: typeof Action.SET_POLICY_RULES @@ -24,6 +22,6 @@ export class SetPolicyRulesRequestDto extends BaseAdminRequestPayloadDto { @IsDefined() @ValidateNested() @Type(() => SetPolicyRulesDto) - @ApiProperty({ type: () => SetPolicyRulesDto }) + @ApiProperty({ type: SetPolicyRulesDto }) request: SetPolicyRulesDto } diff --git a/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-response.dto.ts b/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-response.dto.ts index 26cd19ab5..5d59a5ba5 100644 --- a/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-response.dto.ts +++ b/apps/authz/src/app/http/rest/dto/policy-rules/set-policy-rules-response.dto.ts @@ -11,7 +11,7 @@ export class SetPolicyRulesResponseDto { @IsDefined() @Type(() => Policy) @ValidateNested() - @ApiProperty({ type: () => Policy, isArray: true }) + @ApiProperty({ type: Policy, isArray: true }) policies: Policy[] constructor(partial: Partial) { diff --git a/apps/authz/src/shared/decorators/validate-criterion.decorator.ts b/apps/authz/src/shared/decorators/validate-criterion.decorator.ts index 7d2caccb0..101a78c92 100644 --- a/apps/authz/src/shared/decorators/validate-criterion.decorator.ts +++ b/apps/authz/src/shared/decorators/validate-criterion.decorator.ts @@ -1,8 +1,8 @@ import { applyDecorators } from '@nestjs/common' import { ApiProperty } from '@nestjs/swagger' -import { IsDefined, IsString, Matches } from 'class-validator' +import { Matches } from 'class-validator' import { Criterion } from '../types/policy.type' export function ValidateCriterion(name: string) { - return applyDecorators(IsDefined(), IsString(), Matches(name), ApiProperty({ type: () => Criterion, default: name })) + return applyDecorators(Matches(name), ApiProperty({ type: Criterion, default: name })) }