Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(j-s): Allow public prosecutor user to open case files #15852

Merged
merged 11 commits into from
Sep 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ export class CaseController {
@RolesRules(
prosecutorRule,
prosecutorRepresentativeRule,
publicProsecutorStaffRule,
unakb marked this conversation as resolved.
Show resolved Hide resolved
districtCourtJudgeRule,
districtCourtRegistrarRule,
districtCourtAssistantRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
districtCourtRegistrarRule,
prosecutorRepresentativeRule,
prosecutorRule,
publicProsecutorStaffRule,
} from '../../../../guards'
import { CaseController } from '../../case.controller'

Expand All @@ -19,9 +20,10 @@ describe('CaseController - Get case files record pdf rules', () => {
})

it('should give permission to roles', () => {
expect(rules).toHaveLength(5)
expect(rules).toHaveLength(6)
expect(rules).toContain(prosecutorRule)
expect(rules).toContain(prosecutorRepresentativeRule)
expect(rules).toContain(publicProsecutorStaffRule)
expect(rules).toContain(districtCourtJudgeRule)
expect(rules).toContain(districtCourtRegistrarRule)
expect(rules).toContain(districtCourtAssistantRule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
prisonSystemStaffRule,
prosecutorRepresentativeRule,
prosecutorRule,
publicProsecutorStaffRule,
} from '../../guards'
import {
Case,
Expand Down Expand Up @@ -133,6 +134,7 @@ export class FileController {
@RolesRules(
prosecutorRule,
prosecutorRepresentativeRule,
publicProsecutorStaffRule,
districtCourtJudgeRule,
districtCourtRegistrarRule,
districtCourtAssistantRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
districtCourtRoles,
InstitutionType,
prosecutionRoles,
publicProsecutorRoles,
User,
UserRole,
} from '@island.is/judicial-system/types'
Expand Down Expand Up @@ -210,6 +211,59 @@ describe('View Case File Guard', () => {
})
})

describe.each(publicProsecutorRoles)('role %s', (role) => {
describe.each(completedCaseStates)('%s cases', (state) => {
let then: Then

beforeEach(() => {
mockRequest.mockImplementationOnce(() => ({
user: {
role,
institution: {
type: InstitutionType.PROSECUTORS_OFFICE,
id: '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e',
},
},
case: { state },
}))

then = givenWhenThen()
})

it('should activate', () => {
expect(then.result).toBe(true)
})
})

describe.each(
Object.values(CaseState).filter(
(state) => !completedCaseStates.includes(state),
),
)('%s cases', (state) => {
let then: Then

beforeEach(() => {
mockRequest.mockImplementationOnce(() => ({
user: {
role,
institution: {
type: InstitutionType.PROSECUTORS_OFFICE,
id: '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e',
},
},
case: { state },
}))

then = givenWhenThen()
})

it('should throw ForbiddenException', () => {
expect(then.error).toBeInstanceOf(ForbiddenException)
expect(then.error.message).toBe(`Forbidden for ${role}`)
})
})
})
gudjong marked this conversation as resolved.
Show resolved Hide resolved

describe.each(Object.keys(CaseState))('in state %s', (state) => {
describe.each(
Object.keys(UserRole).filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isDistrictCourtUser,
isPrisonSystemUser,
isProsecutionUser,
isPublicProsecutorUser,
User,
} from '@island.is/judicial-system/types'

Expand Down Expand Up @@ -44,6 +45,10 @@ export class ViewCaseFileGuard implements CanActivate {
return true
}

if (isPublicProsecutorUser(user) && isCompletedCase(theCase.state)) {
return true
}

if (
isDistrictCourtUser(user) &&
([CaseState.SUBMITTED, CaseState.RECEIVED].includes(theCase.state) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
prisonSystemStaffRule,
prosecutorRepresentativeRule,
prosecutorRule,
publicProsecutorStaffRule,
} from '../../../../guards'
import { FileController } from '../../file.controller'

Expand All @@ -23,9 +24,10 @@ describe('FileController - Get case file signed url rules', () => {
})

it('should give permission to roles', () => {
expect(rules).toHaveLength(9)
expect(rules).toHaveLength(10)
expect(rules).toContain(prosecutorRule)
expect(rules).toContain(prosecutorRepresentativeRule)
expect(rules).toContain(publicProsecutorStaffRule)
expect(rules).toContain(districtCourtJudgeRule)
expect(rules).toContain(districtCourtRegistrarRule)
expect(rules).toContain(districtCourtAssistantRule)
Expand Down
Loading