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

feat(j-s): Allow district court assistant to act as registrar in R cases #17772

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class CaseController {
if (update.registrarId) {
await this.validateAssignedUser(
update.registrarId,
[UserRole.DISTRICT_COURT_REGISTRAR],
[UserRole.DISTRICT_COURT_REGISTRAR, UserRole.DISTRICT_COURT_ASSISTANT],
theCase.courtId,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,6 @@ const canPublicProsecutionUserAccessCase = (theCase: Case): boolean => {
}

const canDistrictCourtUserAccessCase = (theCase: Case, user: User): boolean => {
// Check case type access
if (
![
UserRole.DISTRICT_COURT_JUDGE,
UserRole.DISTRICT_COURT_REGISTRAR,
].includes(user.role)
) {
if (!isIndictmentCase(theCase.type)) {
return false
}
}

// Check case state access
if (isRequestCase(theCase.type)) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,52 +108,38 @@ const getDistrictCourtUserCasesQueryFilter = (user: User): WhereOptions => {
},
]

if (user.role === UserRole.DISTRICT_COURT_ASSISTANT) {
options.push(
{ type: indictmentCases },
options.push({
[Op.or]: [
{
state: [
CaseState.SUBMITTED,
CaseState.WAITING_FOR_CANCELLATION,
CaseState.RECEIVED,
CaseState.COMPLETED,
[Op.and]: [
{ type: [...restrictionCases, ...investigationCases] },
{
state: [
CaseState.DRAFT,
CaseState.SUBMITTED,
CaseState.RECEIVED,
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
],
},
],
},
)
} else {
options.push({
[Op.or]: [
{
[Op.and]: [
{ type: [...restrictionCases, ...investigationCases] },
{
state: [
CaseState.DRAFT,
CaseState.SUBMITTED,
CaseState.RECEIVED,
CaseState.ACCEPTED,
CaseState.REJECTED,
CaseState.DISMISSED,
],
},
],
},
{
[Op.and]: [
{ type: indictmentCases },
{
state: [
CaseState.SUBMITTED,
CaseState.WAITING_FOR_CANCELLATION,
CaseState.RECEIVED,
CaseState.COMPLETED,
],
},
],
},
],
})
}
{
[Op.and]: [
{ type: indictmentCases },
{
state: [
CaseState.SUBMITTED,
CaseState.WAITING_FOR_CANCELLATION,
CaseState.RECEIVED,
CaseState.COMPLETED,
],
},
],
},
],
})

return {
[Op.and]: options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ const continueFromIndictmentType = (user: User, type: string) => {
})
}

describe.each([
UserRole.DISTRICT_COURT_JUDGE,
UserRole.DISTRICT_COURT_REGISTRAR,
])('district court user %s', (role) => {
describe.each(districtCourtRoles)('district court user %s', (role) => {
const user = {
role,
institution: { id: uuid(), type: InstitutionType.DISTRICT_COURT },
Expand Down Expand Up @@ -109,31 +106,3 @@ describe.each([
continueFromIndictmentType(user, type)
})
})

describe.each(
districtCourtRoles.filter(
(role) =>
role !== UserRole.DISTRICT_COURT_JUDGE &&
role !== UserRole.DISTRICT_COURT_REGISTRAR,
),
)('district court user %s', (role) => {
const user = {
role,
institution: { id: uuid(), type: InstitutionType.DISTRICT_COURT },
} as User

describe.each([...restrictionCases, ...investigationCases])(
'inaccessible case type %s',
(type) => {
const theCase = {
type,
} as Case

verifyNoAccess(theCase, user)
},
)

describe.each(indictmentCases)('accessible case type %s', (type) => {
continueFromIndictmentType(user, type)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useContext } from 'react'
import { useIntl } from 'react-intl'

import { Box, Select, Tooltip } from '@island.is/island-ui/core'
import { isRequestCase } from '@island.is/judicial-system/types'
import {
BlueBox,
FormContext,
Expand Down Expand Up @@ -73,7 +74,9 @@ const SelectCourtOfficials = () => {
const registrars = (usersData?.users ?? [])
.filter(
(user: User) =>
user.role === UserRole.DISTRICT_COURT_REGISTRAR &&
(user.role === UserRole.DISTRICT_COURT_REGISTRAR ||
(isRequestCase(workingCase.type) &&
user.role === UserRole.DISTRICT_COURT_ASSISTANT)) &&
user.institution?.id === workingCase.court?.id,
)
.map((registrar: User) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ export const filterOptionsForUser = (
user?: User | undefined,
) => {
return options.filter((option) => {
if (
user?.role === UserRole.PROSECUTOR_REPRESENTATIVE ||
user?.role === UserRole.DISTRICT_COURT_ASSISTANT
) {
if (user?.role === UserRole.PROSECUTOR_REPRESENTATIVE) {
return option.value !== 'INVESTIGATION' && option.value !== 'INDICTMENT'
}

Expand Down
Loading