Skip to content

Commit ae34637

Browse files
committed
fix: provide access to local units table for logged in users
Ensure only super users and country admins of particular country can validate local units.
1 parent 05f4e11 commit ae34637

File tree

3 files changed

+11
-5
lines changed
  • app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits

3 files changed

+11
-5
lines changed

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/LocalUnitTableActions/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useTranslation } from '@ifrc-go/ui/hooks';
44
import { resolveToString } from '@ifrc-go/ui/utils';
55

66
import DropdownMenuItem from '#components/DropdownMenuItem';
7+
import usePermissions from '#hooks/domain/usePermissions';
78
import useAlert from '#hooks/useAlert';
89
import {
910
type GoApiResponse,
@@ -14,6 +15,7 @@ import i18n from './i18n.json';
1415
import styles from './styles.module.css';
1516

1617
export interface Props {
18+
countryId: number;
1719
localUnitName: string | null | undefined;
1820
localUnitId: number;
1921
isValidated: boolean;
@@ -24,15 +26,18 @@ export type LocalUnitValidateResponsePostBody = GoApiResponse<'/api/v2/local-uni
2426

2527
function LocalUnitsTableActions(props: Props) {
2628
const {
29+
countryId,
2730
localUnitName,
2831
localUnitId,
2932
isValidated,
3033
onActionSuccess,
3134
} = props;
3235

36+
const { isCountryAdmin, isSuperUser } = usePermissions();
3337
const strings = useTranslation(i18n);
3438
const alert = useAlert();
3539

40+
const hasValidatePermission = isSuperUser || isCountryAdmin(countryId);
3641
const {
3742
pending: validateLocalUnitPending,
3843
trigger: validateLocalUnit,
@@ -77,7 +82,7 @@ function LocalUnitsTableActions(props: Props) {
7782
>
7883
{strings.localUnitsView}
7984
</DropdownMenuItem>
80-
{!(isValidated) && (
85+
{!(isValidated) && hasValidatePermission && (
8186
<DropdownMenuItem
8287
persist
8388
name={undefined}

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/LocalUnitsTable/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ function LocalUnitsTable() {
122122
'',
123123
LocalUnitsTableActions,
124124
(_, item) => ({
125+
countryId: item.id,
125126
localUnitId: item.id,
126127
isValidated: item.validated,
127128
localUnitName: item.local_branch_name ?? item.english_branch_name,

app/src/views/CountryNsOverviewContextAndStructure/NationalSocietyLocalUnits/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { _cs } from '@togglecorp/fujs';
1212

1313
import Link from '#components/Link';
1414
import { adminUrl } from '#config';
15-
import useUserMe from '#hooks/domain/useUserMe';
15+
import useAuth from '#hooks/domain/useAuth';
1616
import { type CountryOutletContext } from '#utils/outletContext';
1717
import { resolveUrl } from '#utils/resolveUrl';
1818

@@ -32,11 +32,11 @@ function NationalSocietyLocalUnits(props: Props) {
3232
} = props;
3333

3434
const [activeTab, setActiveTab] = useState<'map'| 'table'>('map');
35+
const { isAuthenticated } = useAuth();
3536

3637
const strings = useTranslation(i18n);
3738
const { countryId } = useOutletContext<CountryOutletContext>();
3839

39-
const meResponse = useUserMe();
4040
return (
4141
<Tabs
4242
onChange={setActiveTab}
@@ -49,13 +49,13 @@ function NationalSocietyLocalUnits(props: Props) {
4949
childrenContainerClassName={styles.content}
5050
withGridViewInFilter
5151
withHeaderBorder
52-
headerDescription={meResponse?.is_superuser && (
52+
headerDescription={isAuthenticated && (
5353
<TabList>
5454
<Tab name="map">{strings.localUnitsMapView}</Tab>
5555
<Tab name="table">{strings.localUnitsListView}</Tab>
5656
</TabList>
5757
)}
58-
actions={meResponse?.is_superuser && (
58+
actions={isAuthenticated && (
5959
<Link
6060
external
6161
href={resolveUrl(adminUrl, `local_units/localunit/?country=${countryId}`)}

0 commit comments

Comments
 (0)