Skip to content

Commit

Permalink
fix: remove unnecessary check for guest user permission
Browse files Browse the repository at this point in the history
  • Loading branch information
samshara committed Sep 12, 2024
1 parent e2cb0d3 commit 30b65f6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
11 changes: 5 additions & 6 deletions app/src/App/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ const allFlashUpdates = customWrapRoute({
context: {
title: 'All Flash Updates',
visibility: 'is-authenticated',
permissions: ({ isIfrcAdmin, isGuestUser }) => !isGuestUser && isIfrcAdmin,
permissions: ({ isIfrcAdmin }) => isIfrcAdmin,
},
});

Expand All @@ -838,7 +838,7 @@ const flashUpdateFormNew = customWrapRoute({
context: {
title: 'New Flash Update',
visibility: 'is-authenticated',
permissions: ({ isIfrcAdmin, isGuestUser }) => !isGuestUser && isIfrcAdmin,
permissions: ({ isIfrcAdmin }) => isIfrcAdmin,
},
});

Expand All @@ -853,7 +853,7 @@ const flashUpdateFormEdit = customWrapRoute({
context: {
title: 'Edit Flash Update',
visibility: 'is-authenticated',
permissions: ({ isIfrcAdmin, isGuestUser }) => !isGuestUser && isIfrcAdmin,
permissions: ({ isIfrcAdmin }) => isIfrcAdmin,
},
});

Expand All @@ -869,7 +869,7 @@ const flashUpdateFormDetails = customWrapRoute({
context: {
title: 'Flash Update Details',
visibility: 'anything',
permissions: ({ isIfrcAdmin, isGuestUser }) => !isGuestUser && isIfrcAdmin,
permissions: ({ isIfrcAdmin }) => isIfrcAdmin,
},
});

Expand Down Expand Up @@ -1083,8 +1083,7 @@ const newPerOverviewForm = customWrapRoute({
permissions: ({
isSuperUser,
isPerAdmin,
isGuestUser,
}) => !isGuestUser && (isSuperUser || isPerAdmin),
}) => isSuperUser || isPerAdmin,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ function LocalUnitsTableActions(props: Props) {
onActionSuccess,
} = props;

const { isCountryAdmin, isSuperUser, isGuestUser } = usePermissions();
const { isCountryAdmin, isSuperUser } = usePermissions();
const strings = useTranslation(i18n);

const hasValidatePermission = !isGuestUser && (isSuperUser || isCountryAdmin(countryId));
const hasValidatePermission = isSuperUser || isCountryAdmin(countryId);

const [readOnlyLocalUnitModal, setReadOnlyLocalUnitModal] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ function NationalSocietyLocalUnits(props: Props) {

const strings = useTranslation(i18n);

const hasAddLocalUnitPermission = !isGuestUser
&& (isCountryAdmin(countryResponse?.id) || isSuperUser);
const hasAddLocalUnitPermission = isCountryAdmin(countryResponse?.id) || isSuperUser;

useEffect(() => {
document.addEventListener('fullscreenchange', handleFullScreenChange);
Expand Down
5 changes: 2 additions & 3 deletions app/src/views/CountryNsOverviewStrategicPriorities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ export function Component() {
isCountryPerAdmin,
isSuperUser,
isRegionPerAdmin,
isGuestUser,
} = usePermissions();

const countryDetails = useCountry({ id: Number(countryId) });
const regionId = isDefined(countryDetails) ? Number(countryDetails?.region) : undefined;

const isPerAdmin = isSuperUser
|| (!isGuestUser && isCountryPerAdmin(Number(countryId)))
|| (!isGuestUser && isRegionPerAdmin(regionId));
|| isCountryPerAdmin(Number(countryId))
|| isRegionPerAdmin(regionId);

const {
pending: publicPerStatsPending,
Expand Down
8 changes: 3 additions & 5 deletions app/src/views/CountryPreparedness/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ export function Component() {
isCountryPerAdmin,
isSuperUser,
isRegionPerAdmin,
isGuestUser,
} = usePermissions();

const countryDetails = useCountry({ id: Number(countryId) });

const hasPermission = !isGuestUser && (
isSuperUser
const hasPermission = isSuperUser
|| isCountryPerAdmin(Number(countryId))
|| isRegionPerAdmin(Number(countryDetails?.region))
);
|| isRegionPerAdmin(Number(countryDetails?.region));

if (hasPermission) {
return (
<PrivateCountryPreparedness />
Expand Down

0 comments on commit 30b65f6

Please sign in to comment.