Skip to content

Commit

Permalink
Merge branch 'fix/dld-entry-requirements' of github.com:/island-is/is…
Browse files Browse the repository at this point in the history
…land.is into fix/dld-entry-requirements
  • Loading branch information
kksteini committed Jul 4, 2024
2 parents 58dddf6 + 9445d74 commit 97fa5eb
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 138 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ updates:
labels:
- automerge
- dependencies

- package-ecosystem: npm
directory: /scripts/ci/cache
schedule:
interval: daily
labels:
- automerge
- dependencies
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ jobs:

- name: Comment on PR
if: needs.pre-checks.outputs.PRE_CHECK == 'feature-deploy' && !(needs.pre-checks.outputs.PRE_RELEASE == 'true')
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {
courtOfAppealsRegistrarUpdateRule,
districtCourtAssistantTransitionRule,
districtCourtAssistantUpdateRule,
districtCourtJudgeSignRulingRule,
districtCourtJudgeTransitionRule,
districtCourtJudgeUpdateRule,
districtCourtRegistrarTransitionRule,
Expand Down Expand Up @@ -297,12 +298,6 @@ export class CaseController {
break
case CaseTransition.SUBMIT:
if (isIndictmentCase(theCase.type)) {
if (!user.canConfirmIndictment) {
throw new ForbiddenException(
`User ${user.id} does not have permission to confirm indictments`,
)
}

update.indictmentDeniedExplanation = null
}
break
Expand Down Expand Up @@ -387,13 +382,6 @@ export class CaseController {
update.appealRulingDecision = CaseAppealRulingDecision.DISCONTINUED
}
break
case CaseTransition.DENY_INDICTMENT:
if (!user.canConfirmIndictment) {
throw new ForbiddenException(
`User ${user.id} does not have permission to reject indictments`,
)
}
break
case CaseTransition.ASK_FOR_CONFIRMATION:
update.indictmentReturnedExplanation = null
break
Expand Down Expand Up @@ -777,7 +765,7 @@ export class CaseController {
new CaseTypeGuard([...restrictionCases, ...investigationCases]),
CaseWriteGuard,
)
@RolesRules(districtCourtJudgeRule)
@RolesRules(districtCourtJudgeSignRulingRule)
@Post('case/:caseId/ruling/signature')
@ApiCreatedResponse({
type: SigningServiceResponse,
Expand All @@ -790,12 +778,6 @@ 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 @@ -820,7 +802,7 @@ export class CaseController {
new CaseTypeGuard([...restrictionCases, ...investigationCases]),
CaseWriteGuard,
)
@RolesRules(districtCourtJudgeRule)
@RolesRules(districtCourtJudgeSignRulingRule)
@Get('case/:caseId/ruling/signature')
@ApiOkResponse({
type: SignatureConfirmationResponse,
Expand All @@ -835,12 +817,6 @@ 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
17 changes: 10 additions & 7 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
EventType,
isCompletedCase,
isIndictmentCase,
isRequestCase,
isRestrictionCase,
isTrafficViolationCase,
NotificationType,
Expand Down Expand Up @@ -448,9 +449,9 @@ export class CaseService {
const theCase = await this.caseModel.create(
{
...caseToCreate,
state: isIndictmentCase(caseToCreate.type)
? CaseState.DRAFT
: CaseState.NEW,
state: isRequestCase(caseToCreate.type)
? CaseState.NEW
: CaseState.DRAFT,
},
{ transaction },
)
Expand Down Expand Up @@ -1207,7 +1208,7 @@ export class CaseService {
if (updatedCase.courtCaseNumber) {
if (updatedCase.courtCaseNumber !== theCase.courtCaseNumber) {
// New court case number
if (isIndictmentCase(updatedCase.type)) {
if (isIndictment) {
await this.addMessagesForIndictmentCourtCaseConnectionToQueue(
updatedCase,
user,
Expand All @@ -1222,7 +1223,7 @@ export class CaseService {
}

if (
!isIndictmentCase(updatedCase.type) &&
!isIndictment &&
updatedCase.defenderEmail !== theCase.defenderEmail
) {
// New defender email
Expand All @@ -1232,7 +1233,7 @@ export class CaseService {
}

if (
isIndictmentCase(updatedCase.type) &&
isIndictment &&
![
CaseState.DRAFT,
CaseState.SUBMITTED,
Expand Down Expand Up @@ -1326,7 +1327,9 @@ export class CaseService {
creatingProsecutorId: user.id,
prosecutorId:
user.role === UserRole.PROSECUTOR ? user.id : undefined,
courtId: user.institution?.defaultCourtId,
courtId: isRequestCase(caseToCreate.type)
? user.institution?.defaultCourtId
: undefined,
prosecutorsOfficeId: user.institution?.id,
} as CreateCaseDto,
transaction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { RolesRule, RulesType } from '@island.is/judicial-system/auth'
import { CaseTransition, UserRole } from '@island.is/judicial-system/types'
import {
CaseTransition,
CaseType,
User,
UserRole,
} from '@island.is/judicial-system/types'

import { TransitionCaseDto } from '../dto/transitionCase.dto'
import { UpdateCaseDto } from '../dto/updateCase.dto'
import { Case } from '../models/case.model'

Expand Down Expand Up @@ -189,29 +195,39 @@ export const prosecutorTransitionRule: RolesRule = {
dtoFieldValues: [
CaseTransition.OPEN,
CaseTransition.ASK_FOR_CONFIRMATION,
CaseTransition.DENY_INDICTMENT,
CaseTransition.SUBMIT,
CaseTransition.ASK_FOR_CANCELLATION,
CaseTransition.DELETE,
CaseTransition.APPEAL,
CaseTransition.WITHDRAW_APPEAL,
CaseTransition.DENY_INDICTMENT,
],
canActivate: (request) => {
const user: User = request.user
const dto: TransitionCaseDto = request.body
const theCase: Case = request.case

// Deny if the case is missing - shuould never happen
if (!theCase) {
// Deny if something is missing - shuould never happen
if (!user || !dto || !theCase) {
return false
}

// Deny transition if prosecutor did not appeal the case
if (
request.body.transition === CaseTransition.WITHDRAW_APPEAL &&
dto.transition === CaseTransition.WITHDRAW_APPEAL &&
!theCase.prosecutorPostponedAppealDate
) {
return false
}

if (
(dto.transition === CaseTransition.SUBMIT &&
theCase.type === CaseType.INDICTMENT) ||
dto.transition === CaseTransition.DENY_INDICTMENT
) {
return user.canConfirmIndictment
}

return true
},
}
Expand All @@ -221,7 +237,11 @@ export const prosecutorRepresentativeTransitionRule: RolesRule = {
role: UserRole.PROSECUTOR_REPRESENTATIVE,
type: RulesType.FIELD_VALUES,
dtoField: 'transition',
dtoFieldValues: [CaseTransition.ASK_FOR_CONFIRMATION, CaseTransition.DELETE],
dtoFieldValues: [
CaseTransition.ASK_FOR_CONFIRMATION,
CaseTransition.ASK_FOR_CANCELLATION,
CaseTransition.DELETE,
],
}

// Allows defenders to transition cases
Expand All @@ -231,16 +251,17 @@ export const defenderTransitionRule: RolesRule = {
dtoField: 'transition',
dtoFieldValues: [CaseTransition.APPEAL, CaseTransition.WITHDRAW_APPEAL],
canActivate: (request) => {
const dto: TransitionCaseDto = request.body
const theCase: Case = request.case

// Deny if the case is missing - should never happen
if (!theCase) {
// Deny if something is missing - shuould never happen
if (!dto || !theCase) {
return false
}

// Deny withdrawal if defender did not appeal the case
if (
request.body.transition === CaseTransition.WITHDRAW_APPEAL &&
dto.transition === CaseTransition.WITHDRAW_APPEAL &&
!theCase.accusedPostponedAppealDate
) {
return false
Expand Down Expand Up @@ -283,15 +304,15 @@ export const districtCourtRegistrarTransitionRule: RolesRule = {
],
}

// Allows district court assistants to transition cases.
// Allows district court assistants to transition cases
export const districtCourtAssistantTransitionRule: RolesRule = {
role: UserRole.DISTRICT_COURT_ASSISTANT,
type: RulesType.FIELD_VALUES,
dtoField: 'transition',
dtoFieldValues: [CaseTransition.RECEIVE, CaseTransition.COMPLETE],
}

// Allows court of appeals judges to transition cases.
// Allows court of appeals judges to transition cases
export const courtOfAppealsJudgeTransitionRule: RolesRule = {
role: UserRole.COURT_OF_APPEALS_JUDGE,
type: RulesType.FIELD_VALUES,
Expand All @@ -302,7 +323,7 @@ export const courtOfAppealsJudgeTransitionRule: RolesRule = {
],
}

// Allows court of appeals registrars to transition cases.
// Allows court of appeals registrars to transition cases
export const courtOfAppealsRegistrarTransitionRule: RolesRule = {
role: UserRole.COURT_OF_APPEALS_REGISTRAR,
type: RulesType.FIELD_VALUES,
Expand All @@ -313,7 +334,7 @@ export const courtOfAppealsRegistrarTransitionRule: RolesRule = {
],
}

// Allows court of appeals assistants to transition cases.
// Allows court of appeals assistants to transition cases
export const courtOfAppealsAssistantTransitionRule: RolesRule = {
role: UserRole.COURT_OF_APPEALS_ASSISTANT,
type: RulesType.FIELD_VALUES,
Expand All @@ -323,3 +344,20 @@ export const courtOfAppealsAssistantTransitionRule: RolesRule = {
CaseTransition.REOPEN_APPEAL,
],
}

// Allows district court judges to sign a ruling
export const districtCourtJudgeSignRulingRule: RolesRule = {
role: UserRole.DISTRICT_COURT_JUDGE,
type: RulesType.BASIC,
canActivate: (request) => {
const user: User = request.user
const theCase: Case = request.case

// Deny if something is missing - shuould never happen
if (!user || !theCase) {
return false
}

return user.id === theCase.judgeId
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
EventType,
isIndictmentCase,
isProsecutionUser,
isRequestCase,
isRestrictionCase,
isTrafficViolationCase,
NotificationType,
Expand Down Expand Up @@ -353,14 +354,16 @@ export class InternalCaseService {
.create(
{
...caseToCreate,
state: isIndictmentCase(caseToCreate.type)
? CaseState.DRAFT
: CaseState.NEW,
state: isRequestCase(caseToCreate.type)
? CaseState.NEW
: CaseState.DRAFT,
origin: CaseOrigin.LOKE,
creatingProsecutorId: creator.id,
prosecutorId:
creator.role === UserRole.PROSECUTOR ? creator.id : undefined,
courtId: creator.institution?.defaultCourtId,
courtId: isRequestCase(caseToCreate.type)
? creator.institution?.defaultCourtId
: undefined,
prosecutorsOfficeId: creator.institution?.id,
},
{ transaction },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ describe('CaseController - Create', () => {
origin: CaseOrigin.RVG,
creatingProsecutorId: userId,
prosecutorId: userId,
courtId,
prosecutorsOfficeId,
},
{ transaction },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Transaction } from 'sequelize/types'
import { uuid } from 'uuidv4'

import { ForbiddenException } from '@nestjs/common'

import { MessageService, MessageType } from '@island.is/judicial-system/message'
import {
CaseFileState,
Expand Down Expand Up @@ -212,25 +210,6 @@ describe('CaseController - Get ruling signature confirmation', () => {
])
})
})

describe('user is not the assigned judge', () => {
const caseId = uuid()
const theCase = { id: caseId, judgeId: uuid() } as Case
const documentToken = uuid()
let then: Then

beforeEach(async () => {
then = await givenWhenThen(caseId, user, theCase, documentToken)
})

it('should throw ForbiddenException', () => {
expect(then.error).toBeInstanceOf(ForbiddenException)
expect(then.error.message).toBe(
'A ruling must be signed by the assigned judge',
)
})
})

describe('database update fails', () => {
const caseId = uuid()
const theCase = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +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
Expand All @@ -14,6 +14,6 @@ describe('CaseController - Get ruling signature confirmation rules', () => {

it('should give permission to one roles', () => {
expect(rules).toHaveLength(1)
expect(rules).toContain(districtCourtJudgeRule)
expect(rules).toContain(districtCourtJudgeSignRulingRule)
})
})
Loading

0 comments on commit 97fa5eb

Please sign in to comment.