From 5626c2a34fe237b7b36759ec7f6862066a4bbbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Mon, 18 Nov 2024 16:21:07 +0000 Subject: [PATCH] fix(j-s): String Length Validation (#16924) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/app/modules/case/dto/createCase.dto.ts | 8 ++++++++ .../src/app/modules/case/dto/updateCase.dto.ts | 13 +++++++++++++ .../modules/defendant/dto/createDefendant.dto.ts | 16 +++++++++++++++- .../defendant/dto/updateCivilClaimant.dto.ts | 8 +++++++- .../modules/defendant/dto/updateDefendant.dto.ts | 11 +++++++++++ .../src/app/modules/file/dto/createFile.dto.ts | 6 ++++++ .../modules/file/dto/createPresignedPost.dto.ts | 4 +++- .../src/app/modules/file/dto/updateFile.dto.ts | 2 ++ .../dto/updateIndictmentCount.dto.ts | 3 +++ .../modules/subpoena/dto/updateSubpoena.dto.ts | 9 ++++++++- .../src/app/modules/user/dto/createUser.dto.ts | 6 ++++++ .../src/app/modules/user/dto/updateUser.dto.ts | 5 +++++ .../InvestigationCase/Defendant/Defendant.tsx | 1 + 13 files changed, 88 insertions(+), 4 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/dto/createCase.dto.ts b/apps/judicial-system/backend/src/app/modules/case/dto/createCase.dto.ts index f3f920723a31..32bf0f7589d1 100644 --- a/apps/judicial-system/backend/src/app/modules/case/dto/createCase.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/case/dto/createCase.dto.ts @@ -6,6 +6,7 @@ import { IsObject, IsOptional, IsString, + MaxLength, } from 'class-validator' import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' @@ -31,6 +32,7 @@ export class CreateCaseDto { readonly indictmentSubtypes?: IndictmentSubtypeMap @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly description?: string @@ -38,26 +40,31 @@ export class CreateCaseDto { @IsNotEmpty() @IsArray() @ArrayMinSize(1) + @MaxLength(255) @IsString({ each: true }) @ApiProperty({ type: String, isArray: true }) readonly policeCaseNumbers!: string[] @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderName?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderEmail?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderPhoneNumber?: string @@ -68,6 +75,7 @@ export class CreateCaseDto { readonly requestSharedWithDefender?: RequestSharedWithDefender @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly leadInvestigator?: string diff --git a/apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts b/apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts index 4930b0b976bb..a34a8a14d219 100644 --- a/apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/case/dto/updateCase.dto.ts @@ -9,6 +9,7 @@ import { IsOptional, IsString, IsUUID, + MaxLength, ValidateNested, } from 'class-validator' @@ -43,6 +44,7 @@ class UpdateDateLog { readonly date?: Date @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly location?: string @@ -60,6 +62,7 @@ export class UpdateCaseDto { readonly indictmentSubtypes?: IndictmentSubtypeMap @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly description?: string @@ -67,26 +70,31 @@ export class UpdateCaseDto { @IsOptional() @IsArray() @ArrayMinSize(1) + @MaxLength(255) @IsString({ each: true }) @ApiPropertyOptional({ type: String, isArray: true }) readonly policeCaseNumbers?: string[] @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderName?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderEmail?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderPhoneNumber?: string @@ -107,6 +115,7 @@ export class UpdateCaseDto { readonly courtId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly leadInvestigator?: string @@ -124,6 +133,7 @@ export class UpdateCaseDto { readonly requestedCourtDate?: Date @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly translator?: string @@ -207,6 +217,7 @@ export class UpdateCaseDto { readonly sharedWithProsecutorsOfficeId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly courtCaseNumber?: string @@ -229,6 +240,7 @@ export class UpdateCaseDto { readonly courtDate?: UpdateDateLog @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly courtLocation?: string @@ -407,6 +419,7 @@ export class UpdateCaseDto { readonly defendantStatementDate?: Date @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly appealCaseNumber?: string diff --git a/apps/judicial-system/backend/src/app/modules/defendant/dto/createDefendant.dto.ts b/apps/judicial-system/backend/src/app/modules/defendant/dto/createDefendant.dto.ts index eee5ea58da99..9c32a38660c7 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/dto/createDefendant.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/dto/createDefendant.dto.ts @@ -1,4 +1,10 @@ -import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator' +import { + IsBoolean, + IsEnum, + IsOptional, + IsString, + MaxLength, +} from 'class-validator' import { ApiPropertyOptional } from '@nestjs/swagger' @@ -11,11 +17,13 @@ export class CreateDefendantDto { readonly noNationalId?: boolean @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly nationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly name?: string @@ -26,31 +34,37 @@ export class CreateDefendantDto { readonly gender?: Gender @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly address?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly citizenship?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderName?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderEmail?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderPhoneNumber?: string diff --git a/apps/judicial-system/backend/src/app/modules/defendant/dto/updateCivilClaimant.dto.ts b/apps/judicial-system/backend/src/app/modules/defendant/dto/updateCivilClaimant.dto.ts index 3f85ec624a7f..44bcbed23e49 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/dto/updateCivilClaimant.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/dto/updateCivilClaimant.dto.ts @@ -1,4 +1,4 @@ -import { IsBoolean, IsOptional, IsString } from 'class-validator' +import { IsBoolean, IsOptional, IsString, MaxLength } from 'class-validator' import { ApiPropertyOptional } from '@nestjs/swagger' @@ -9,11 +9,13 @@ export class UpdateCivilClaimantDto { readonly noNationalId?: boolean @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly name?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly nationalId?: string @@ -29,21 +31,25 @@ export class UpdateCivilClaimantDto { readonly spokespersonIsLawyer?: boolean @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly spokespersonNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly spokespersonName?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly spokespersonEmail?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly spokespersonPhoneNumber?: string diff --git a/apps/judicial-system/backend/src/app/modules/defendant/dto/updateDefendant.dto.ts b/apps/judicial-system/backend/src/app/modules/defendant/dto/updateDefendant.dto.ts index 8e9321fbf730..c59f91dcaa0d 100644 --- a/apps/judicial-system/backend/src/app/modules/defendant/dto/updateDefendant.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/defendant/dto/updateDefendant.dto.ts @@ -5,6 +5,7 @@ import { IsEnum, IsOptional, IsString, + MaxLength, } from 'class-validator' import { ApiPropertyOptional } from '@nestjs/swagger' @@ -24,11 +25,13 @@ export class UpdateDefendantDto { readonly noNationalId?: boolean @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly nationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly name?: string @@ -39,31 +42,37 @@ export class UpdateDefendantDto { readonly gender?: Gender @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly address?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly citizenship?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderName?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderEmail?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderPhoneNumber?: string @@ -106,11 +115,13 @@ export class UpdateDefendantDto { readonly requestedDefenderChoice?: DefenderChoice @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly requestedDefenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly requestedDefenderName?: string diff --git a/apps/judicial-system/backend/src/app/modules/file/dto/createFile.dto.ts b/apps/judicial-system/backend/src/app/modules/file/dto/createFile.dto.ts index de31caf5e46b..b17cfaaacb6c 100644 --- a/apps/judicial-system/backend/src/app/modules/file/dto/createFile.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/file/dto/createFile.dto.ts @@ -6,6 +6,7 @@ import { IsNumber, IsOptional, IsString, + MaxLength, } from 'class-validator' import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger' @@ -14,6 +15,7 @@ import { CaseFileCategory } from '@island.is/judicial-system/types' export class CreateFileDto { @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly type!: string @@ -24,6 +26,7 @@ export class CreateFileDto { readonly category?: CaseFileCategory @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly key!: string @@ -34,6 +37,7 @@ export class CreateFileDto { readonly size!: number @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly policeCaseNumber?: string @@ -55,11 +59,13 @@ export class CreateFileDto { readonly displayDate?: Date @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly policeFileId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly userGeneratedFilename?: string diff --git a/apps/judicial-system/backend/src/app/modules/file/dto/createPresignedPost.dto.ts b/apps/judicial-system/backend/src/app/modules/file/dto/createPresignedPost.dto.ts index 1dc58cf5f6db..e9bdeb9d4a7a 100644 --- a/apps/judicial-system/backend/src/app/modules/file/dto/createPresignedPost.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/file/dto/createPresignedPost.dto.ts @@ -1,14 +1,16 @@ -import { IsNotEmpty, IsString } from 'class-validator' +import { IsNotEmpty, IsString, MaxLength } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' export class CreatePresignedPostDto { @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly fileName!: string @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly type!: string diff --git a/apps/judicial-system/backend/src/app/modules/file/dto/updateFile.dto.ts b/apps/judicial-system/backend/src/app/modules/file/dto/updateFile.dto.ts index f645b71bf9bb..a769eeda2ddb 100644 --- a/apps/judicial-system/backend/src/app/modules/file/dto/updateFile.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/file/dto/updateFile.dto.ts @@ -7,6 +7,7 @@ import { IsOptional, IsString, IsUUID, + MaxLength, Min, ValidateIf, ValidateNested, @@ -21,6 +22,7 @@ export class UpdateFileDto { readonly id!: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly userGeneratedFilename?: string diff --git a/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts b/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts index 103ce2051ea3..b1226cdc54e0 100644 --- a/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/indictment-count/dto/updateIndictmentCount.dto.ts @@ -4,6 +4,7 @@ import { IsObject, IsOptional, IsString, + MaxLength, } from 'class-validator' import { ApiPropertyOptional } from '@nestjs/swagger' @@ -13,11 +14,13 @@ import { IndictmentCountOffense } from '@island.is/judicial-system/types' export class UpdateIndictmentCountDto { @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly policeCaseNumber?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly vehicleRegistrationNumber?: string diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts b/apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts index 36a14e1be0ef..89e83477f4a2 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/dto/updateSubpoena.dto.ts @@ -1,4 +1,4 @@ -import { IsBoolean, IsEnum, IsOptional, IsString } from 'class-validator' +import { IsEnum, IsOptional, IsString, MaxLength } from 'class-validator' import { ApiPropertyOptional } from '@nestjs/swagger' @@ -11,6 +11,7 @@ export class UpdateSubpoenaDto { readonly serviceStatus?: ServiceStatus @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly servedBy?: string @@ -31,21 +32,25 @@ export class UpdateSubpoenaDto { readonly defenderChoice?: DefenderChoice @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderName?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderEmail?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly defenderPhoneNumber?: string @@ -56,11 +61,13 @@ export class UpdateSubpoenaDto { readonly requestedDefenderChoice?: DefenderChoice @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly requestedDefenderNationalId?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly requestedDefenderName?: string diff --git a/apps/judicial-system/backend/src/app/modules/user/dto/createUser.dto.ts b/apps/judicial-system/backend/src/app/modules/user/dto/createUser.dto.ts index 1460431b37f7..d6b8207fba4d 100644 --- a/apps/judicial-system/backend/src/app/modules/user/dto/createUser.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/user/dto/createUser.dto.ts @@ -4,6 +4,7 @@ import { IsNotEmpty, IsString, IsUUID, + MaxLength, } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' @@ -12,26 +13,31 @@ import { UserRole } from '@island.is/judicial-system/types' export class CreateUserDto { @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly nationalId!: string @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly name!: string @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly title!: string @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly mobileNumber!: string @IsNotEmpty() + @MaxLength(255) @IsString() @ApiProperty({ type: String }) readonly email!: string diff --git a/apps/judicial-system/backend/src/app/modules/user/dto/updateUser.dto.ts b/apps/judicial-system/backend/src/app/modules/user/dto/updateUser.dto.ts index fcebedbf7405..071bd218261b 100644 --- a/apps/judicial-system/backend/src/app/modules/user/dto/updateUser.dto.ts +++ b/apps/judicial-system/backend/src/app/modules/user/dto/updateUser.dto.ts @@ -4,6 +4,7 @@ import { IsOptional, IsString, IsUUID, + MaxLength, } from 'class-validator' import { ApiPropertyOptional } from '@nestjs/swagger' @@ -12,21 +13,25 @@ import { UserRole } from '@island.is/judicial-system/types' export class UpdateUserDto { @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly name?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly title?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly mobileNumber?: string @IsOptional() + @MaxLength(255) @IsString() @ApiPropertyOptional({ type: String }) readonly email?: string diff --git a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx index 58d28cb6146b..2470cb389ec4 100644 --- a/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx +++ b/apps/judicial-system/web/src/routes/Prosecutor/InvestigationCase/Defendant/Defendant.tsx @@ -336,6 +336,7 @@ const Defendant = () => { setWorkingCase, ) } + maxLength={255} />