Skip to content

Commit

Permalink
feat: ORV2-2543 Credit Account Granularity based on Roles (#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
praju-aot authored Jul 17, 2024
1 parent ca2375d commit 4706ef4
Show file tree
Hide file tree
Showing 11 changed files with 339 additions and 64 deletions.
27 changes: 27 additions & 0 deletions database/mssql/scripts/versions/revert/v_33_ddl_revert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET NOCOUNT ON
GO

SET XACT_ABORT ON

BEGIN TRY
BEGIN TRANSACTION

DELETE FROM [access].[ORBC_GROUP_ROLE] WHERE ROLE_TYPE ='ORBC-READ-CREDIT-ACCOUNT' AND USER_AUTH_GROUP_TYPE IN ('PPCCLERK', 'CTPO', 'HQADMIN')

COMMIT
END TRY

BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK;
THROW
END CATCH

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Reverting mapping of ORBC-READ-CREDIT-ACCOUNT from PPCCLERK, CTPO, and HQADMIN.'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (32, @VersionDescription, getutcdate())
48 changes: 48 additions & 0 deletions database/mssql/scripts/versions/v_33_ddl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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_GROUP_ROLE] ([USER_AUTH_GROUP_TYPE], [ROLE_TYPE]) VALUES (N'PPCCLERK', N'ORBC-READ-CREDIT-ACCOUNT')
INSERT [access].[ORBC_GROUP_ROLE] ([USER_AUTH_GROUP_TYPE], [ROLE_TYPE]) VALUES (N'CTPO', N'ORBC-READ-CREDIT-ACCOUNT')
INSERT [access].[ORBC_GROUP_ROLE] ([USER_AUTH_GROUP_TYPE], [ROLE_TYPE]) VALUES (N'HQADMIN', N'ORBC-READ-CREDIT-ACCOUNT')
GO

DECLARE @VersionDescription VARCHAR(255)
SET @VersionDescription = 'Add ORBC-READ-CREDIT-ACCOUNT to PPCCLERK, CTPO, and HQADMIN'

INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (33, @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
5 changes: 5 additions & 0 deletions database/mssql/test/versions/v_33_1_test.sql
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 ='ORBC-READ-CREDIT-ACCOUNT' AND USER_AUTH_GROUP_TYPE IN ('PPCCLERK', 'CTPO', 'HQADMIN')
16 changes: 16 additions & 0 deletions database/mssql/test/versions/v_33_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/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 33 are run from this shell script.
# TESTS_DIR variable set by the calling test-runner script.

TEST_33_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_33_1_test.sql | xargs)
if [[ $TEST_33_1_RESULT -eq 3 ]]; then
echo "Test 33.1 passed: Role types inserted correctly"
else
echo "******** Test 33.1 failed: Role types not inserted correctly"
fi
1 change: 0 additions & 1 deletion vehicles/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class AppService {

@LogAsyncMethodExecution({ printMemoryStats: true })
async initializeCache() {

const startDateTime = new Date();
const countries = await this.commonService.findAllCountries();
await addToCache(
Expand Down
2 changes: 1 addition & 1 deletion vehicles/src/common/enum/roles.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export enum Role {
WRITE_SUSPEND = 'ORBC-WRITE-SUSPEND',
SEND_NOTIFICATION = 'ORBC-SEND-NOTIFICATION',
WRITE_CREDIT_ACCOUNT = 'ORBC-WRITE-CREDIT-ACCOUNT',
READ_CREDIT_ACCOUNT = 'ORBC-READ-CREDIT-ACCOUNT',
READ_CREDIT_ACCOUNT = 'ORBC-READ-CREDIT-ACCOUNT',
READ_POLICY_CONFIG = 'ORBC-READ-POLICY-CONFIG',
WRITE_POLICY_CONFIG = 'ORBC-WRITE-POLICY-CONFIG',
}
21 changes: 21 additions & 0 deletions vehicles/src/common/helper/common.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Evaluates the given predicate and returns the value if the predicate is true or the value is not null, otherwise returns undefined.
*
* @param {T} value - The value to be returned if the predicate evaluates to true or the value is not null.
* @param {() => boolean} [predicate] - An optional function that returns a boolean indicating whether the value should be substituted.
* @returns {T | undefined} - The value if predicate evaluates to true or the value is not null, otherwise undefined.
*/
export const undefinedSubstitution = <T>(
value: T,
predicate?: () => boolean,
): T | undefined => {
let result: T | undefined;

if (predicate) {
result = predicate() ? value : undefined;
} else {
result = value ?? undefined;
}

return result;
};
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@ export class CreditAccountUserController {
@Get()
@Roles(Role.READ_CREDIT_ACCOUNT)
async getCreditAccountUsers(
@Req() request: Request,
@Param() { companyId, creditAccountId }: CreditAccountIdPathParamDto,
@Query() { includeAccountHolder }: GetCreditAccountUserQueryParamsDto,
): Promise<ReadCreditAccountUserDto[]> {
return await this.creditAccountService.getCreditAccountUsers(
const currentUser = request.user as IUserJWT;
return await this.creditAccountService.getCreditAccountUsers({
companyId,
creditAccountId,
currentUser,
includeAccountHolder,
);
});
}
}
Loading

0 comments on commit 4706ef4

Please sign in to comment.