Skip to content

Commit

Permalink
feat: disable delete idp group button for restricted permissions
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <[email protected]>
  • Loading branch information
MasWho committed Feb 19, 2025
1 parent 7dcc0b7 commit 9f5e30b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/pages/permissions/PermissionIdpGroups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ const PermissionIdpGroups: FC = () => {
title: idpGroup.name,
},
{
content: (
content: canEditGroup(idpGroup) ? (
<Button
appearance="link"
dense
onClick={() => panelParams.openEditIdpGroup(idpGroup.name)}
>
{idpGroup.groups.length}
</Button>
) : (
idpGroup.groups.length
),
role: "cell",
className: "u-align--right",
Expand Down
9 changes: 8 additions & 1 deletion src/pages/permissions/actions/DeleteIdpGroupBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Button, Icon } from "@canonical/react-components";
import type { IdpGroup } from "types/permissions";
import DeleteIdpGroupsModal from "./DeleteIdpGroupsModal";
import { usePortal } from "@canonical/react-components";
import { useIdpGroupEntitlements } from "util/entitlements/idp-groups";

interface Props {
idpGroup: IdpGroup;
}

const DeleteIdpGroupBtn: FC<Props> = ({ idpGroup }) => {
const { openPortal, closePortal, isOpen, Portal } = usePortal();
const { canDeleteGroup } = useIdpGroupEntitlements();

return (
<>
Expand All @@ -20,7 +22,12 @@ const DeleteIdpGroupBtn: FC<Props> = ({ idpGroup }) => {
onClick={openPortal}
type="button"
aria-label="Delete IDP group"
title="Delete IDP group"
title={
canDeleteGroup()
? "Delete IDP group"
: "You do not have permission to delete this IDP group"
}
disabled={!canDeleteGroup(idpGroup)}
>
<Icon name="delete" />
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/permissions/panels/PermissionSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const PermissionSelector: FC<Props> = ({ onAddPermission, disableReason }) => {
} = useQuery({
queryKey: [queryKeys.permissions, resourceType],
queryFn: () => fetchPermissions({ resourceType }),
enabled: !!resourceType && !!disableReason,
enabled: !!resourceType && !disableReason,
});

const { data: images = [] } = useImagesInAllProjects();
Expand Down

0 comments on commit 9f5e30b

Please sign in to comment.