Skip to content

Commit 301e53a

Browse files
committed
feat: enforce auth and permissions for eru readiness
1 parent 90185c1 commit 301e53a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

app/src/App/routes/SurgeRoutes.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const eruReadinessForm = customWrapRoute({
132132
wrapperComponent: Auth,
133133
context: {
134134
title: 'ERU Readiness Update Form',
135-
visibility: 'anything',
135+
visibility: 'is-authenticated',
136136
},
137137
});
138138

app/src/views/ActiveSurgeDeployments/SurgeMap/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ function SurgeMap(props: Props) {
436436
rendererParams={rendererParams}
437437
/>
438438
)}
439-
label={strings.roleProfile}
439+
label={strings.eruType}
440440
strongLabel
441441
/>
442442
<TextOutput

app/src/views/EruReadinessForm/index.tsx

+22-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Link from '#components/Link';
3232
import NonFieldError from '#components/NonFieldError';
3333
import Page from '#components/Page';
3434
import useGlobalEnums from '#hooks/domain/useGlobalEnums';
35+
import usePermissions from '#hooks/domain/usePermissions';
3536
import useAlertContext from '#hooks/useAlert';
3637
import useRouting from '#hooks/useRouting';
3738
import {
@@ -76,7 +77,15 @@ const defaultFormValues: FormType = {};
7677
export function Component() {
7778
const strings = useTranslation(i18n);
7879

80+
const {
81+
isCountryAdmin,
82+
isRegionAdmin,
83+
isSuperUser,
84+
isIfrcAdmin,
85+
} = usePermissions();
86+
7987
const { goBack } = useRouting();
88+
8089
const alert = useAlertContext();
8190
const {
8291
deployments_eru_type: eruTypeOptions,
@@ -116,6 +125,7 @@ export function Component() {
116125
})),
117126
});
118127
};
128+
119129
const {
120130
trigger: updateEruReadiness,
121131
pending: updateEruReadinessPending,
@@ -290,9 +300,19 @@ export function Component() {
290300
fetchEruReadinessData(newValue);
291301
}
292302
},
293-
[fetchEruReadinessData, setValue],
303+
[
304+
fetchEruReadinessData,
305+
setValue,
306+
],
294307
);
295308

309+
const permittedEruOwners = eruOwnerResponse?.results?.filter((owner) => (
310+
isSuperUser
311+
|| isIfrcAdmin
312+
|| isCountryAdmin(owner.national_society_country_details.id)
313+
|| isRegionAdmin(owner.national_society_country_details.region ?? undefined)
314+
));
315+
296316
const eruTypes = useMemo(() => (
297317
value.eru_types?.map((eruType) => eruType.type).filter(isDefined)
298318
), [value.eru_types]);
@@ -359,7 +379,7 @@ export function Component() {
359379
>
360380
<SelectInput
361381
name="eru_owner"
362-
options={eruOwnerResponse?.results}
382+
options={permittedEruOwners}
363383
onChange={handleEruOwnerChange}
364384
value={value.eru_owner}
365385
keySelector={eruOwnerKeySelector}

app/src/views/SurgeOverview/EmergencyResponseUnit/EmergencyResponseUnitReadiness/index.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ function EmergencyResponseUnitReadiness() {
157157
<Container
158158
heading={resolveToString(
159159
strings.eruReadinessCount,
160-
{ count: eruReadinessResponse?.count ?? '-' },
160+
{
161+
count: (
162+
activeTab === 'eruType' ? groupedByEruType?.length
163+
: eruReadinessResponse?.count) ?? '-',
164+
},
161165
)}
162166
withHeaderBorder
163167
actions={(

0 commit comments

Comments
 (0)