Skip to content

Commit df1c820

Browse files
committed
fix: correct permissions for unit actions
users with admin role should see all options now
1 parent 14faede commit df1c820

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/features/userSettings/UserSettingsContent/ContextSection/contextActions/DeleteUnitListItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { useQueryClient } from "@tanstack/react-query";
1313

1414
import { WarningDeleteButton } from "../../../../../components/WarningDeleteButton";
1515
import { useEnqueueError } from "../../../../../hooks/useEnqueueStackError";
16-
import { useKeycloakUser } from "../../../../../hooks/useKeycloakUser";
1716
import { useSelectedOrganisation } from "../../../../../state/organisationSelection";
1817

1918
export interface DeleteUnitListItem {
@@ -25,7 +24,6 @@ export interface DeleteUnitListItem {
2524
}
2625

2726
export const DeleteUnitListItem = ({ unit, onDelete }: DeleteUnitListItem) => {
28-
const { user } = useKeycloakUser();
2927
const [organisation] = useSelectedOrganisation();
3028
const queryClient = useQueryClient();
3129
const { mutateAsync: deleteDefaultUnit, isPending: isDefaultDeleting } = useDeleteDefaultUnit();
@@ -41,7 +39,7 @@ export const DeleteUnitListItem = ({ unit, onDelete }: DeleteUnitListItem) => {
4139
tooltipText="Delete selected unit"
4240
onDelete={async () => {
4341
try {
44-
await (unit.name === user.username
42+
await (unit.name === unit.owner_id
4543
? deleteDefaultUnit()
4644
: deleteUnit({ unitId: unit.id }));
4745
enqueueSnackbar("Unit deleted", { variant: "success" });

src/features/userSettings/UserSettingsContent/ContextSection/contextActions/UnitActions.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { List } from "@mui/material";
22

33
import { CreateProjectListItem } from "../../../../../components/projects/CreateProject/CreateProjectListItem";
44
import { useGetPersonalUnit } from "../../../../../hooks/useGetPersonalUnit";
5+
import { useASAuthorizationStatus } from "../../../../../hooks/useIsAuthorized";
56
import { useKeycloakUser } from "../../../../../hooks/useKeycloakUser";
67
import { useSelectedOrganisation } from "../../../../../state/organisationSelection";
78
import { useSelectedUnit } from "../../../../../state/unitSelection";
@@ -24,20 +25,20 @@ export const UnitActions = () => {
2425

2526
const { data: personalUnit, isLoading, error } = useGetPersonalUnit();
2627

28+
const isAdminUser = useASAuthorizationStatus() === process.env.NEXT_PUBLIC_KEYCLOAK_AS_ADMIN_ROLE;
29+
30+
const organisationIsDefault = organisation?.name === process.env.NEXT_PUBLIC_DEFAULT_ORG_NAME;
31+
2732
return (
2833
<List sx={{ width: "100%" }}>
29-
{!!(isOrganisationOwner || organisation?.caller_is_member) &&
30-
organisation?.name !== process.env.NEXT_PUBLIC_DEFAULT_ORG_NAME && <CreateUnitListItem />}
31-
{personalUnit === undefined &&
32-
!isLoading &&
33-
!error &&
34-
organisation?.name === process.env.NEXT_PUBLIC_DEFAULT_ORG_NAME && (
35-
<CreateDefaultUnitListItem />
36-
)}
37-
{!!isUnitOwner && !!unit && (
34+
{!!(isAdminUser || isOrganisationOwner || !!organisation?.caller_is_member) &&
35+
!organisationIsDefault && <CreateUnitListItem />}
36+
{personalUnit === undefined && !isLoading && !error && !!organisationIsDefault && (
37+
<CreateDefaultUnitListItem />
38+
)}
39+
{!!(isAdminUser || isUnitOwner) && !!unit && (
3840
<DeleteUnitListItem unit={unit} onDelete={() => setUnit(undefined)} />
3941
)}
40-
4142
{!!unit && <EditUnitListItem unit={unit} />}
4243
{!!unit && !!(unit.caller_is_member || unit.owner_id === user.username) && (
4344
<CreateProjectListItem unit={unit} />

0 commit comments

Comments
 (0)