From 6d45ecb58feb2f94f4e3cdf30aad4159127f0f65 Mon Sep 17 00:00:00 2001 From: unakb Date: Tue, 9 Jul 2024 15:35:44 +0000 Subject: [PATCH] fix(j-s): Ruling signatures (#15487) * fix(j-s): Ruling signatures * Update rolesRules.ts * Update case.controller.ts * test(j-s): Fix --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/app/modules/case/case.controller.ts | 17 ++++++++++++++--- ...ulingSignatureConfirmationRolesRules.spec.ts | 5 ++--- .../requestRulingSignatureRolesRules.spec.ts | 5 ++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/case.controller.ts b/apps/judicial-system/backend/src/app/modules/case/case.controller.ts index e73b47b71811..ab71f5d339ec 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.controller.ts @@ -84,7 +84,6 @@ import { courtOfAppealsRegistrarUpdateRule, districtCourtAssistantTransitionRule, districtCourtAssistantUpdateRule, - districtCourtJudgeSignRulingRule, districtCourtJudgeTransitionRule, districtCourtJudgeUpdateRule, districtCourtRegistrarTransitionRule, @@ -765,7 +764,7 @@ export class CaseController { new CaseTypeGuard([...restrictionCases, ...investigationCases]), CaseWriteGuard, ) - @RolesRules(districtCourtJudgeSignRulingRule) + @RolesRules(districtCourtJudgeRule) @Post('case/:caseId/ruling/signature') @ApiCreatedResponse({ type: SigningServiceResponse, @@ -778,6 +777,12 @@ export class CaseController { ): Promise { this.logger.debug(`Requesting a signature for the ruling of case ${caseId}`) + if (user.id !== theCase.judgeId) { + throw new ForbiddenException( + 'A ruling must be signed by the assigned judge', + ) + } + return this.caseService.requestRulingSignature(theCase).catch((error) => { if (error instanceof DokobitError) { throw new HttpException( @@ -802,7 +807,7 @@ export class CaseController { new CaseTypeGuard([...restrictionCases, ...investigationCases]), CaseWriteGuard, ) - @RolesRules(districtCourtJudgeSignRulingRule) + @RolesRules(districtCourtJudgeRule) @Get('case/:caseId/ruling/signature') @ApiOkResponse({ type: SignatureConfirmationResponse, @@ -817,6 +822,12 @@ export class CaseController { ): Promise { this.logger.debug(`Confirming a signature for the ruling of case ${caseId}`) + if (user.id !== theCase.judgeId) { + throw new ForbiddenException( + 'A ruling must be signed by the assigned judge', + ) + } + return this.caseService.getRulingSignatureConfirmation( theCase, user, diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmationRolesRules.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmationRolesRules.spec.ts index e41962b38178..a7899946e2e3 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmationRolesRules.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/getRulingSignatureConfirmationRolesRules.spec.ts @@ -1,6 +1,5 @@ +import { districtCourtJudgeRule } from '../../../../guards' import { CaseController } from '../../case.controller' -import { districtCourtJudgeSignRulingRule } from '../../guards/rolesRules' - describe('CaseController - Get ruling signature confirmation rules', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let rules: any[] @@ -14,6 +13,6 @@ describe('CaseController - Get ruling signature confirmation rules', () => { it('should give permission to one roles', () => { expect(rules).toHaveLength(1) - expect(rules).toContain(districtCourtJudgeSignRulingRule) + expect(rules).toContain(districtCourtJudgeRule) }) }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/requestRulingSignatureRolesRules.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/requestRulingSignatureRolesRules.spec.ts index 81f956445bfd..400de1843470 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/requestRulingSignatureRolesRules.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/requestRulingSignatureRolesRules.spec.ts @@ -1,6 +1,5 @@ +import { districtCourtJudgeRule } from '../../../../guards' import { CaseController } from '../../case.controller' -import { districtCourtJudgeSignRulingRule } from '../../guards/rolesRules' - describe('CaseController - Request ruling signature rules', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let rules: any[] @@ -14,6 +13,6 @@ describe('CaseController - Request ruling signature rules', () => { it('should give permission to one roles', () => { expect(rules).toHaveLength(1) - expect(rules).toContain(districtCourtJudgeSignRulingRule) + expect(rules).toContain(districtCourtJudgeRule) }) })