From f31c3c4531197f4204b40e1ae37b68720c3e3de1 Mon Sep 17 00:00:00 2001 From: Peter Muriuki Date: Thu, 7 Nov 2024 15:51:05 +0300 Subject: [PATCH] Permission the fhir-flag module --- app/src/App/fhir-apps.tsx | 2 +- .../src/components/BaseComponent/index.tsx | 19 ++++++++++++++---- .../src/components/CloseFlagForm/index.tsx | 20 +++++++++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/app/src/App/fhir-apps.tsx b/app/src/App/fhir-apps.tsx index b993a866e..2db3c804e 100644 --- a/app/src/App/fhir-apps.tsx +++ b/app/src/App/fhir-apps.tsx @@ -583,7 +583,7 @@ const FHIRApps = () => { disableLoginProtection={DISABLE_LOGIN_PROTECTION} exact path={`${URL_CLOSE_FLAGS}/:id`} - // permissions={['Flag.update']} + permissions={['Flag.read']} component={CloseFlag} /> { enabled: !!user_id, staleTime: thatiMinutes, select: (response) => { - return getResourcesFromBundle(response)?.[0]; + return getResourcesFromBundle(response)[0]; }, } ); @@ -80,10 +81,20 @@ export const CloseFlag = (props: CloseFlagProps) => { return ( - {flag.data?.subject?.reference?.includes('Location') ? ( - + {flag.data?.subject.reference?.includes('Location') ? ( + + + ) : ( - + + + )} diff --git a/packages/fhir-flag/src/components/CloseFlagForm/index.tsx b/packages/fhir-flag/src/components/CloseFlagForm/index.tsx index bca00e60e..a0920b844 100644 --- a/packages/fhir-flag/src/components/CloseFlagForm/index.tsx +++ b/packages/fhir-flag/src/components/CloseFlagForm/index.tsx @@ -8,6 +8,7 @@ import { sendErrorNotification, sendSuccessNotification } from '@opensrp/notific import { useTranslation } from '../../mls'; import { comments, locationName, productName, status } from '../../constants'; import { IFlag } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IFlag'; +import { useUserRole } from '@opensrp/rbac'; const { Item: FormItem } = Form; const { TextArea } = Input; @@ -36,6 +37,7 @@ const headerProps = { const CloseFlagForm = (props: CloseFlagFormProps) => { const { initialValues, flag, mutationEffect } = props; + const userRole = useUserRole(); const { t } = useTranslation(); const stableInitialValues = useMemo(() => initialValues, [initialValues]); @@ -63,6 +65,15 @@ const CloseFlagForm = (props: CloseFlagFormProps) => { mutate(values); }; + const saveBtnDisabled = userRole.hasPermissions([ + 'Flag.update', + 'Encounter.update', + 'Observation.update', + ]); + const saveBtnDisabledReason = saveBtnDisabled + ? t('Missing Required permissions to perform this action') + : undefined; + return ( @@ -89,8 +100,13 @@ const CloseFlagForm = (props: CloseFlagFormProps) => {