-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #857 from bcgov/utopia-769
[Utopia 769] Updated pia-intake entity and associated JSONB classes and dtos
- Loading branch information
Showing
40 changed files
with
1,465 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export enum UserTypesEnum { | ||
DRAFTER = 'DRAFTER', | ||
MPO = 'MPO', | ||
} |
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,4 @@ | ||
export enum YesNoInput { | ||
YES = 'YES', | ||
NO = 'NO', | ||
} |
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,8 @@ | ||
import { UserTypesEnum } from '../enums/users.enum'; | ||
|
||
export interface IFormField<T> { | ||
key: keyof T; | ||
type: 'text'; // add ORs for future support if needed | ||
isRichText: boolean; | ||
allowedUserTypesEdit: Array<UserTypesEnum>; // null if no role restrictions apply | ||
} |
37 changes: 37 additions & 0 deletions
37
src/backend/src/common/validators/form-field-role.validator.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,37 @@ | ||
import { ForbiddenException } from '@nestjs/common'; | ||
import { UserTypesEnum } from '../enums/users.enum'; | ||
import { IFormField } from '../interfaces/form-field.interface'; | ||
|
||
/** | ||
* @method validateRoleForFormField | ||
* | ||
* @description | ||
* This method validates role access to Form Fields values | ||
*/ | ||
export const validateRoleForFormField = <T>( | ||
metadata: IFormField<T>, | ||
updatedValue: any, | ||
storedValue: any, | ||
userType: UserTypesEnum, | ||
path: string, | ||
) => { | ||
if (!updatedValue) return; // if value not edited - no need to validate permissions | ||
|
||
if (typeof updatedValue === 'string' && updatedValue === storedValue) return; // if value is not updated by the current user; | ||
|
||
if (!metadata?.allowedUserTypesEdit) return; // if allowedUserTypesEdit is null, all roles can edit this field/key | ||
|
||
if ( | ||
metadata.allowedUserTypesEdit.includes(UserTypesEnum.MPO) && | ||
userType !== UserTypesEnum.MPO | ||
) { | ||
// if allowed user types is MPO and the user is not an MPO user, throw error | ||
throw new ForbiddenException({ | ||
path: path, | ||
message: `You do not have permissions to edit certain section of this document. Please reach out to your MPO to proceed.`, | ||
}); | ||
} | ||
|
||
// allow otherwise | ||
return; | ||
}; |
49 changes: 49 additions & 0 deletions
49
src/backend/src/migrations/1676414798877-piaIntakeAddJsonbColumns.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,49 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class PiaIntakeAddJsonbColumns1676414798877 | ||
implements MigrationInterface | ||
{ | ||
name = 'piaIntakeAddJsonbColumns1676414798877'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" ADD "collection_use_and_disclosure" jsonb`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" ADD "storing_personal_information" jsonb`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" ADD "security_personal_information" jsonb`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" ADD "accuracy_correction_and_retention" jsonb`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" ADD "personal_information_banks" jsonb`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" ADD "additional_risks" jsonb`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" DROP COLUMN "additional_risks"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" DROP COLUMN "personal_information_banks"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" DROP COLUMN "accuracy_correction_and_retention"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" DROP COLUMN "security_personal_information"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" DROP COLUMN "storing_personal_information"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "pia-intake" DROP COLUMN "collection_use_and_disclosure"`, | ||
); | ||
} | ||
} |
11 changes: 6 additions & 5 deletions
11
src/backend/src/modules/pia-intake/constants/pia-intake-allowed-sort-fields.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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { PiaIntakeEntity } from '../entities/pia-intake.entity'; | ||
export type PiaIntakeAllowedSortFieldsType = | ||
| 'drafterName' | ||
| 'updatedAt' | ||
| 'createdAt'; | ||
|
||
export const PiaIntakeAllowedSortFields: Array<keyof PiaIntakeEntity> = [ | ||
'drafterName', | ||
'updatedAt', | ||
]; | ||
export const PiaIntakeAllowedSortFields: Array<PiaIntakeAllowedSortFieldsType> = | ||
['drafterName', 'updatedAt', 'createdAt']; |
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
7 changes: 7 additions & 0 deletions
7
...ackend/src/modules/pia-intake/jsonb-classes/accuracy-correction-and-retention/accuracy.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,7 @@ | ||
import { IsOptional, IsString } from '@nestjs/class-validator'; | ||
|
||
export class Accuracy { | ||
@IsString() | ||
@IsOptional() | ||
description?: string; | ||
} |
16 changes: 16 additions & 0 deletions
16
...kend/src/modules/pia-intake/jsonb-classes/accuracy-correction-and-retention/correction.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,16 @@ | ||
import { IsEnum, IsOptional } from '@nestjs/class-validator'; | ||
import { YesNoInput } from 'src/common/enums/yes-no-input.enum'; | ||
|
||
export class Correction { | ||
@IsEnum(YesNoInput) | ||
@IsOptional() | ||
haveProcessInPlace?: YesNoInput; | ||
|
||
@IsEnum(YesNoInput) | ||
@IsOptional() | ||
willDocument?: YesNoInput; | ||
|
||
@IsEnum(YesNoInput) | ||
@IsOptional() | ||
willConductNotifications?: YesNoInput; | ||
} |
29 changes: 29 additions & 0 deletions
29
src/backend/src/modules/pia-intake/jsonb-classes/accuracy-correction-and-retention/index.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,29 @@ | ||
import { | ||
IsNotEmptyObject, | ||
IsObject, | ||
ValidateNested, | ||
} from '@nestjs/class-validator'; | ||
import { Type } from 'class-transformer'; | ||
import { Accuracy } from './accuracy'; | ||
import { Correction } from './correction'; | ||
import { Retention } from './retention'; | ||
|
||
export class AccuracyCorrectionAndRetention { | ||
@IsObject() | ||
@IsNotEmptyObject() | ||
@ValidateNested() | ||
@Type(() => Accuracy) | ||
accuracy: Accuracy; | ||
|
||
@IsObject() | ||
@IsNotEmptyObject() | ||
@ValidateNested() | ||
@Type(() => Correction) | ||
correction: Correction; | ||
|
||
@IsObject() | ||
@IsNotEmptyObject() | ||
@ValidateNested() | ||
@Type(() => Retention) | ||
retention: Retention; | ||
} |
Oops, something went wrong.