Skip to content

Commit

Permalink
fix(j-s): User Admin (#14718)
Browse files Browse the repository at this point in the history
* Fixes issues with user admin

* Fixes hiding of the can confirm indictment flag

* Update apps/judicial-system/web/src/routes/Admin/UserForm/UserForm.tsx

* Fixes unit tests

---------

Co-authored-by: Ívar Oddsson <ivaroddsson@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 10, 2024
1 parent 2963cc8 commit 9313e8a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ describe('getCasesQueryFilter', () => {
it('should get public prosecutor filter', () => {
// Arrange
const user = {
id: 'Public Prosecutor Office Id',
role,
institution: {
id: 'Prosecutors Office Id',
id: '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e',
type: InstitutionType.PROSECUTORS_OFFICE,
},
}
Expand Down
52 changes: 39 additions & 13 deletions apps/judicial-system/web/src/routes/Admin/UserForm/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ export const UserForm: React.FC<React.PropsWithChildren<Props>> = (props) => {
}
}

const saveUser = () => {
props.onSave({
...user,
// Make sure only prosecutors can confirm indictments
canConfirmIndictment:
user.role === UserRole.PROSECUTOR && user.canConfirmIndictment,
})
}

return (
<div className={styles.userFormContainer}>
<FormContentContainer>
Expand Down Expand Up @@ -228,6 +237,20 @@ export const UserForm: React.FC<React.PropsWithChildren<Props>> = (props) => {
large
/>
</Box>
{user.institution.id === '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e' && (
<Box className={styles.roleColumn}>
<RadioButton
name="role"
id="rolePublicProsecutorStaff"
label="Skrifstofa"
checked={user.role === UserRole.PUBLIC_PROSECUTOR_STAFF}
onChange={() =>
setUser({ ...user, role: UserRole.PUBLIC_PROSECUTOR_STAFF })
}
large
/>
</Box>
)}
</Box>
) : user.institution?.type === InstitutionType.DISTRICT_COURT ? (
<Box display="flex" marginBottom={2}>
Expand Down Expand Up @@ -330,6 +353,21 @@ export const UserForm: React.FC<React.PropsWithChildren<Props>> = (props) => {
</Box>
</Box>
) : null}
{user.institution?.type === InstitutionType.PROSECUTORS_OFFICE &&
user.role === UserRole.PROSECUTOR && (
<Box marginBottom={2}>
<Checkbox
name="canConfirmIndictment"
label="Notandi getur staðfest kærur"
checked={Boolean(user.canConfirmIndictment)}
onChange={({ target }) =>
setUser({ ...user, canConfirmIndictment: target.checked })
}
large
filled
/>
</Box>
)}
<Box marginBottom={2}>
<Input
name="title"
Expand Down Expand Up @@ -428,23 +466,11 @@ export const UserForm: React.FC<React.PropsWithChildren<Props>> = (props) => {
filled
/>
</Box>
<Box marginBottom={2}>
<Checkbox
name="canConfirmIndictment"
label="Notandi getur staðfest kærur"
checked={Boolean(user.canConfirmIndictment)}
onChange={({ target }) =>
setUser({ ...user, canConfirmIndictment: target.checked })
}
large
filled
/>
</Box>
</FormContentContainer>
<FormContentContainer isFooter>
<FormFooter
nextButtonIcon="arrowForward"
onNextButtonClick={() => props.onSave(user)}
onNextButtonClick={saveUser}
nextIsDisabled={!isValid()}
nextIsLoading={props.loading}
nextButtonText="Vista"
Expand Down
20 changes: 12 additions & 8 deletions libs/judicial-system/types/src/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { Institution, InstitutionType } from './institution'
export enum UserRole {
PROSECUTOR = 'PROSECUTOR', // sækjandi
PROSECUTOR_REPRESENTATIVE = 'PROSECUTOR_REPRESENTATIVE', // fulltrúi
PUBLIC_PROSECUTOR_STAFF = 'PUBLIC_PROSECUTOR_STAFF', // skrifstofufólk hjá ríkissaksóknara
DISTRICT_COURT_JUDGE = 'DISTRICT_COURT_JUDGE', // dómari
DISTRICT_COURT_REGISTRAR = 'DISTRICT_COURT_REGISTRAR', // dómritari
DISTRICT_COURT_ASSISTANT = 'DISTRICT_COURT_ASSISTANT', // aðstoðarmaður dómara
COURT_OF_APPEALS_JUDGE = 'COURT_OF_APPEALS_JUDGE', // dómari
COURT_OF_APPEALS_REGISTRAR = 'COURT_OF_APPEALS_REGISTRAR', // dómritari
COURT_OF_APPEALS_ASSISTANT = 'COURT_OF_APPEALS_ASSISTANT', // aðstoðarmaður dómara
ADMIN = 'ADMIN', // Does not exist in the database // notendaumsjón
PRISON_SYSTEM_STAFF = 'PRISON_SYSTEM_STAFF', // fangelsismálastarfsmaður
ADMIN = 'ADMIN', // Does not exist in the database // notendaumsjón
DEFENDER = 'DEFENDER', // Does not exist in the database // verjandi
PUBLIC_PROSECUTOR_STAFF = 'PUBLIC_PROSECUTOR_STAFF', // skrifstofufólk hjá ríkissaksóknara
}

export interface User {
Expand All @@ -33,8 +33,12 @@ export interface User {
}

interface InstitutionUser {
id?: string | null
role?: string | null
institution?: { type?: string | null; name?: string | null } | null
institution?: {
id?: string | null
type?: string | null
} | null
}

export const prosecutionRoles: string[] = [
Expand All @@ -54,21 +58,20 @@ export const isPublicProsecutor = (user?: InstitutionUser): boolean => {
return Boolean(
user?.role &&
user?.role === UserRole.PROSECUTOR &&
user?.institution?.name === 'Ríkissaksóknari', // TODO: Find better way to handle this
user?.institution?.id === '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e', // TODO: Create a new institution type to avoid hardcoding
)
}

export const publicProsecutorRoles: string[] = [
UserRole.PUBLIC_PROSECUTOR_STAFF,
]

export const isPublicProsecutorUser = function (
user?: InstitutionUser,
): boolean {
export const isPublicProsecutorUser = (user?: InstitutionUser): boolean => {
return Boolean(
user?.role &&
publicProsecutorRoles.includes(user.role) &&
user?.institution?.type === InstitutionType.PROSECUTORS_OFFICE,
user?.institution?.type === InstitutionType.PROSECUTORS_OFFICE &&
user?.institution?.id === '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e', // TODO: Create a new institution type to avoid hardcoding
)
}

Expand Down Expand Up @@ -126,6 +129,7 @@ export const isAdminUser = (user?: InstitutionUser): boolean => {
export const isCoreUser = (user?: InstitutionUser): boolean => {
return (
isProsecutionUser(user) ||
isPublicProsecutorUser(user) ||
isDistrictCourtUser(user) ||
isCourtOfAppealsUser(user) ||
isPrisonSystemUser(user)
Expand Down

0 comments on commit 9313e8a

Please sign in to comment.