Skip to content

Commit

Permalink
fix(j-s): Ruling signatures (#15487)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and oskarjs committed Aug 20, 2024
1 parent 35cdbfb commit 6d45ecb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ import {
courtOfAppealsRegistrarUpdateRule,
districtCourtAssistantTransitionRule,
districtCourtAssistantUpdateRule,
districtCourtJudgeSignRulingRule,
districtCourtJudgeTransitionRule,
districtCourtJudgeUpdateRule,
districtCourtRegistrarTransitionRule,
Expand Down Expand Up @@ -765,7 +764,7 @@ export class CaseController {
new CaseTypeGuard([...restrictionCases, ...investigationCases]),
CaseWriteGuard,
)
@RolesRules(districtCourtJudgeSignRulingRule)
@RolesRules(districtCourtJudgeRule)
@Post('case/:caseId/ruling/signature')
@ApiCreatedResponse({
type: SigningServiceResponse,
Expand All @@ -778,6 +777,12 @@ export class CaseController {
): Promise<SigningServiceResponse> {
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(
Expand All @@ -802,7 +807,7 @@ export class CaseController {
new CaseTypeGuard([...restrictionCases, ...investigationCases]),
CaseWriteGuard,
)
@RolesRules(districtCourtJudgeSignRulingRule)
@RolesRules(districtCourtJudgeRule)
@Get('case/:caseId/ruling/signature')
@ApiOkResponse({
type: SignatureConfirmationResponse,
Expand All @@ -817,6 +822,12 @@ export class CaseController {
): Promise<SignatureConfirmationResponse> {
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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[]
Expand All @@ -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)
})
})
Original file line number Diff line number Diff line change
@@ -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[]
Expand All @@ -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)
})
})

0 comments on commit 6d45ecb

Please sign in to comment.