generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ORV2-2223 Policy Config Api - Phase 2 (#1488)
- Loading branch information
Showing
20 changed files
with
577 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
database/mssql/scripts/versions/revert/v_32_ddl_revert.sql
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,31 @@ | ||
SET ANSI_NULLS ON | ||
GO | ||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
SET NOCOUNT ON | ||
GO | ||
|
||
SET XACT_ABORT ON | ||
|
||
BEGIN TRY | ||
BEGIN TRANSACTION | ||
|
||
DROP CONSTRAINT [DF_ORBC_POLICY_CONFIGURATION_IS_DRAFT] | ||
ALTER TABLE [dbo].[ORBC_POLICY_CONFIGURATION] DROP COLUMN [APP_LAST_UPDATE_USERID]; | ||
|
||
DELETE FROM [access].[ORBC_GROUP_ROLE] WHERE ROLE_TYPE IN ('ORBC-WRITE-POLICY-CONFIG','ORBC-READ-POLICY-CONFIG') | ||
DELETE FROM [access].[ORBC_ROLE_TYPE] WHERE ROLE_TYPE IN ('ORBC-WRITE-POLICY-CONFIG','ORBC-READ-POLICY-CONFIG') | ||
|
||
COMMIT | ||
END TRY | ||
|
||
BEGIN CATCH | ||
IF @@TRANCOUNT > 0 | ||
ROLLBACK; | ||
THROW | ||
END CATCH | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Reverting addition of APP_CREATE_USERID and APP_LAST_UPDATE_USERID to ORBC_POLICY_CONFIGURATION.' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (31, @VersionDescription, getutcdate()) |
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,58 @@ | ||
SET ANSI_NULLS ON | ||
GO | ||
|
||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
|
||
SET NOCOUNT ON | ||
GO | ||
|
||
SET XACT_ABORT ON | ||
GO | ||
|
||
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE | ||
GO | ||
|
||
BEGIN TRANSACTION | ||
GO | ||
|
||
IF @@ERROR <> 0 | ||
SET NOEXEC ON | ||
GO | ||
|
||
INSERT [access].[ORBC_ROLE_TYPE] ([ROLE_TYPE], [ROLE_DESCRIPTION]) VALUES (N'ORBC-WRITE-POLICY-CONFIG', NULL) | ||
INSERT [access].[ORBC_ROLE_TYPE] ([ROLE_TYPE], [ROLE_DESCRIPTION]) VALUES (N'ORBC-READ-POLICY-CONFIG', NULL) | ||
GO | ||
|
||
INSERT [access].[ORBC_GROUP_ROLE] ([USER_AUTH_GROUP_TYPE], [ROLE_TYPE]) VALUES (N'SYSADMIN', N'ORBC-WRITE-POLICY-CONFIG') | ||
INSERT [access].[ORBC_GROUP_ROLE] ([USER_AUTH_GROUP_TYPE], [ROLE_TYPE]) VALUES (N'SYSADMIN', N'ORBC-READ-POLICY-CONFIG') | ||
|
||
ALTER TABLE [dbo].[ORBC_POLICY_CONFIGURATION] ADD [APP_LAST_UPDATE_USERID] [nvarchar](30) NULL | ||
GO | ||
|
||
ALTER TABLE [dbo].[ORBC_POLICY_CONFIGURATION] ADD CONSTRAINT [DF_ORBC_POLICY_CONFIGURATION_IS_DRAFT] DEFAULT ('Y') FOR [IS_DRAFT] | ||
GO | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Add APP_LAST_UPDATE_USERID cols to ORBC_POLICY_CONFIGURATION' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (32, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
COMMIT TRANSACTION | ||
GO | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
DECLARE @Success AS BIT | ||
SET @Success = 1 | ||
SET NOEXEC OFF | ||
IF (@Success = 1) PRINT 'The database update succeeded' | ||
ELSE BEGIN | ||
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION | ||
PRINT 'The database update failed' | ||
END | ||
GO |
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 @@ | ||
-- Test that the APP_LAST_UPDATE_USERID column has been added correctly | ||
SET NOCOUNT ON | ||
|
||
select COL_LENGTH('$(DB_NAME).[dbo].[ORBC_POLICY_CONFIGURATION]', 'APP_LAST_UPDATE_USERID') |
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,5 @@ | ||
-- Test that the role types have been inserted correctly | ||
SET NOCOUNT ON | ||
|
||
SELECT COUNT(*) FROM $(DB_NAME).[access].[ORBC_ROLE_TYPE] | ||
WHERE ROLE_TYPE IN ('ORBC-WRITE-POLICY-CONFIG','ORBC-READ-POLICY-CONFIG') |
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,5 @@ | ||
-- Test that the role types have been inserted correctly against user auth groups | ||
SET NOCOUNT ON | ||
|
||
SELECT COUNT(*) FROM $(DB_NAME).[access].[ORBC_GROUP_ROLE] | ||
WHERE ROLE_TYPE IN ('ORBC-WRITE-POLICY-CONFIG','ORBC-READ-POLICY-CONFIG') |
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,30 @@ | ||
#!/bin/bash | ||
|
||
# Retrieve arguments | ||
source ${SCRIPT_DIR}/utility/getopt.sh | ||
USAGE="-u USER -p PASS -s SERVER -d DATABASE" | ||
parse_options "${USAGE}" ${@} | ||
|
||
# All database tests for database version 32 are run from this shell script. | ||
# TESTS_DIR variable set by the calling test-runner script. | ||
|
||
TEST_32_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_32_1_test.sql | xargs) | ||
if [[ $TEST_32_1_RESULT -eq 30 ]]; then | ||
echo "Test 32.1 passed: APP_LAST_UPDATE_USERID column created in ORBC_POLICY_CONFIGURATION" | ||
else | ||
echo "******** Test 32.1 failed: APP_LAST_UPDATE_USERID column missing in ORBC_POLICY_CONFIGURATION" | ||
fi | ||
|
||
TEST_32_2_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_32_2_test.sql | xargs) | ||
if [[ $TEST_32_2_RESULT -eq 2 ]]; then | ||
echo "Test 32.2 passed: Role types inserted correctly" | ||
else | ||
echo "******** Test 32.2 failed: Role types not inserted correctly" | ||
fi | ||
|
||
TEST_32_3_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_32_3_test.sql | xargs) | ||
if [[ $TEST_32_3_RESULT -eq 2 ]]; then | ||
echo "Test 32.3 passed: Correct number of role mappings inserted" | ||
else | ||
echo "******** Test 32.3 failed: Incorrect number of role mappings inserted" | ||
fi |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Reflector } from '@nestjs/core'; | ||
|
||
/** | ||
* Decorator to check if a specific feature flag is enabled. | ||
* | ||
* The feature flag can be used to conditionally enable or disable parts of the application | ||
* depending on the current configuration or environment setup. | ||
* | ||
* Usage: | ||
* | ||
* ```typescript | ||
* @IsFeatureFlagEnabled('featureName') | ||
* async someFunction() { | ||
* // function implementation | ||
* } | ||
* ``` | ||
* | ||
* @param {string} flagName - The name of the feature flag to check. | ||
* @returns {MethodDecorator} The method decorator to be applied. | ||
*/ | ||
|
||
export const IsFeatureFlagEnabled = Reflector.createDecorator<string>(); |
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
16 changes: 16 additions & 0 deletions
16
policy/src/modules/policy-config/dto/request/pathParam/policy-config.path-params.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,16 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsInt, IsPositive } from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
|
||
export class PolicyConfigIdPathParamDto { | ||
@ApiProperty({ | ||
example: 1, | ||
description: | ||
'The unique identifier of the policy configuration. This field is required.', | ||
required: true, | ||
}) | ||
@IsInt() | ||
@IsPositive() | ||
@Type(() => Number) | ||
policyConfigId: number; | ||
} |
19 changes: 19 additions & 0 deletions
19
...cy/src/modules/policy-config/dto/request/queryParam/get-policy-config.query-params.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,19 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsBoolean, IsOptional } from 'class-validator'; | ||
import { Transform } from 'class-transformer'; | ||
|
||
export class GetPolicyConfigQueryParamsDto { | ||
@ApiProperty({ | ||
description: | ||
'A flag indicating to fetch only the current policy configuration.', | ||
example: true, | ||
default: false, | ||
required: false, | ||
}) | ||
@IsOptional() | ||
@Transform(({ obj, key }: { obj: Record<string, unknown>; key: string }) => { | ||
return obj[key] === 'true' ? true : obj[key] === 'false' ? false : obj[key]; | ||
}) | ||
@IsBoolean() | ||
isCurrent?: boolean = false; | ||
} |
53 changes: 53 additions & 0 deletions
53
policy/src/modules/policy-config/dto/response/read-policy-config.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,53 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class ReadPolicyConfigDto { | ||
/** | ||
* Unique identifier for the policy configuration. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: '1', | ||
description: 'Unique identifier for the policy configuration.', | ||
}) | ||
policyConfigId: number; | ||
|
||
/** | ||
* JSON data representing the policy configuration. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
description: 'Policy configuration in JSON format.', | ||
}) | ||
policy: JSON; | ||
|
||
/** | ||
* Configuration effective date. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: '2023-07-13T17:31:17.470Z', | ||
description: 'Policy Configuration effective date.', | ||
}) | ||
effectiveDate: string; | ||
|
||
/** | ||
* Indicates if the configuration is currently a draft version. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: true, | ||
description: 'Indicates if the configuration is currently a draft.', | ||
}) | ||
isDraft: boolean; | ||
|
||
/** | ||
* Description of changes made in the configuration. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: 'Initial release of policy configuration with updated rules', | ||
description: 'Description of changes made in the configuration.', | ||
}) | ||
changeDescription: string; | ||
} |
72 changes: 72 additions & 0 deletions
72
policy/src/modules/policy-config/entities/policy-config.entity.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,72 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { Base } from '../../common/entities/base.entity'; | ||
import { AutoMap } from '@automapper/classes'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
@Entity({ name: 'ORBC_POLICY_CONFIGURATION', schema: 'dbo' }) | ||
export class PolicyConfig extends Base { | ||
/** | ||
* Unique identifier for the policy configuration. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: '1', | ||
description: 'Unique identifier for the policy configuration.', | ||
}) | ||
@PrimaryGeneratedColumn({ type: 'int', name: 'POLICY_CONFIGURATION_ID' }) | ||
policyConfigId: number; | ||
|
||
/** | ||
* JSON data representing the policy configuration. | ||
*/ | ||
@AutoMap() | ||
@Column({ name: 'POLICY_JSON', nullable: true, type: 'simple-json' }) //Full text search capabilities is not required on the field | ||
policy: JSON; | ||
|
||
/** | ||
* configuration effective date. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: '2023-07-13T17:31:17.470Z', | ||
description: 'Configuration effective date.', | ||
}) | ||
@Column({ | ||
name: 'EFFECTIVE_DATE', | ||
nullable: true, | ||
type: 'datetime2', | ||
}) | ||
effectiveDate: Date; | ||
|
||
/** | ||
* Specifies whether the config is currently active. 'Y' for yes, 'N' for no. | ||
*/ | ||
@AutoMap() | ||
@Column({ | ||
type: 'char', | ||
name: 'IS_DRAFT', | ||
default: true, | ||
nullable: false, | ||
transformer: { | ||
to: (value: boolean): string => (value ? 'Y' : 'N'), // Converts the boolean value to 'Y' or 'N' for storage. | ||
from: (value: string): boolean => value === 'Y', // Converts the stored string back to a boolean. | ||
}, | ||
}) | ||
isDraft: boolean; | ||
|
||
/** | ||
* Description of changes made in the configuration. | ||
*/ | ||
@AutoMap() | ||
@ApiProperty({ | ||
example: 'Initial release of policy configuration with updated rules', | ||
description: 'Description of changes made in the configuration.', | ||
}) | ||
@Column({ | ||
name: 'CHANGE_DESCRIPTION', | ||
nullable: true, | ||
type: 'nvarchar', | ||
length: 2000, | ||
}) | ||
changeDescription: string; | ||
} |
Oops, something went wrong.