From 9313e8a48658174c954d832dda3b91bb8bcd67a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Fri, 10 May 2024 13:42:20 +0000 Subject: [PATCH] fix(j-s): User Admin (#14718) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../case/filters/test/cases.filter.spec.ts | 3 +- .../src/routes/Admin/UserForm/UserForm.tsx | 52 ++++++++++++++----- libs/judicial-system/types/src/lib/user.ts | 20 ++++--- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts b/apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts index 3ed4f2cb16b5..aeac70720590 100644 --- a/apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts @@ -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, }, } diff --git a/apps/judicial-system/web/src/routes/Admin/UserForm/UserForm.tsx b/apps/judicial-system/web/src/routes/Admin/UserForm/UserForm.tsx index 3ec69d1f1169..64d619aedb9b 100644 --- a/apps/judicial-system/web/src/routes/Admin/UserForm/UserForm.tsx +++ b/apps/judicial-system/web/src/routes/Admin/UserForm/UserForm.tsx @@ -119,6 +119,15 @@ export const UserForm: React.FC> = (props) => { } } + const saveUser = () => { + props.onSave({ + ...user, + // Make sure only prosecutors can confirm indictments + canConfirmIndictment: + user.role === UserRole.PROSECUTOR && user.canConfirmIndictment, + }) + } + return (
@@ -228,6 +237,20 @@ export const UserForm: React.FC> = (props) => { large /> + {user.institution.id === '8f9e2f6d-6a00-4a5e-b39b-95fd110d762e' && ( + + + setUser({ ...user, role: UserRole.PUBLIC_PROSECUTOR_STAFF }) + } + large + /> + + )} ) : user.institution?.type === InstitutionType.DISTRICT_COURT ? ( @@ -330,6 +353,21 @@ export const UserForm: React.FC> = (props) => { ) : null} + {user.institution?.type === InstitutionType.PROSECUTORS_OFFICE && + user.role === UserRole.PROSECUTOR && ( + + + setUser({ ...user, canConfirmIndictment: target.checked }) + } + large + filled + /> + + )} > = (props) => { filled /> - - - setUser({ ...user, canConfirmIndictment: target.checked }) - } - large - filled - /> - props.onSave(user)} + onNextButtonClick={saveUser} nextIsDisabled={!isValid()} nextIsLoading={props.loading} nextButtonText="Vista" diff --git a/libs/judicial-system/types/src/lib/user.ts b/libs/judicial-system/types/src/lib/user.ts index 7a79f7f2658e..ab6f80dd286c 100644 --- a/libs/judicial-system/types/src/lib/user.ts +++ b/libs/judicial-system/types/src/lib/user.ts @@ -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 { @@ -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[] = [ @@ -54,7 +58,7 @@ 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 ) } @@ -62,13 +66,12 @@ 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 ) } @@ -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)