-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [WD-15753] Delete OIDC User (#972)
## Done - Created API(s) to delete OIDC identities. - Created DeleteIdentitiesBtn - Added an inline delete identity button. Fixes [list issues/bugs if needed] ## QA 1. Run the LXD-UI: - On the demo server via the link posted by @webteam-app below. This is only available for PRs created by collaborators of the repo. Ask @mas-who or @edlerd for access. - With a local copy of this branch, [build and run as described in the docs](../CONTRIBUTING.md#setting-up-for-development). 2. Perform the following QA steps: - Navigate to Permissions -> Identities and attempt to delete one or many identities through the inline delete button or the bulk delete button. ## Screenshots ![image](https://github.com/user-attachments/assets/89afb1d7-04c6-47e0-a0e5-1cb8560ff023)
- Loading branch information
Showing
6 changed files
with
225 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { FC } from "react"; | ||
import { | ||
ButtonProps, | ||
ConfirmationButton, | ||
useNotify, | ||
} from "@canonical/react-components"; | ||
import { LxdIdentity } from "types/permissions"; | ||
import { deleteOIDCIdentities } from "api/auth-identities"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useToastNotification } from "context/toastNotificationProvider"; | ||
import { queryKeys } from "util/queryKeys"; | ||
import { pluralize } from "util/instanceBulkActions"; | ||
|
||
interface Props { | ||
identities: LxdIdentity[]; | ||
className?: string; | ||
} | ||
|
||
const BulkDeleteIdentitiesBtn: FC<Props & ButtonProps> = ({ | ||
identities, | ||
className, | ||
}) => { | ||
const queryClient = useQueryClient(); | ||
const notify = useNotify(); | ||
const toastNotify = useToastNotification(); | ||
const buttonText = `Delete ${pluralize("identity", identities.length)}`; | ||
const successMessage = `${identities.length} ${pluralize("identity", identities.length)} successfully deleted`; | ||
|
||
const handleDelete = () => { | ||
deleteOIDCIdentities(identities) | ||
.then(() => { | ||
void queryClient.invalidateQueries({ | ||
predicate: (query) => { | ||
return [queryKeys.identities, queryKeys.authGroups].includes( | ||
query.queryKey[0] as string, | ||
); | ||
}, | ||
}); | ||
toastNotify.success(successMessage); | ||
close(); | ||
}) | ||
.catch((e) => { | ||
notify.failure(`Identity deletion failed`, e); | ||
}); | ||
}; | ||
|
||
return ( | ||
<ConfirmationButton | ||
onHoverText={buttonText} | ||
appearance="" | ||
aria-label="Delete identities" | ||
className={className} | ||
confirmationModalProps={{ | ||
title: "Confirm delete", | ||
children: ( | ||
<p> | ||
This will permanently delete the following identities: | ||
<ul> | ||
{identities.map((identity) => ( | ||
<li key={identity.name}>{identity.name}</li> | ||
))} | ||
</ul> | ||
This action cannot be undone, and can result in data loss. | ||
</p> | ||
), | ||
confirmButtonLabel: "Delete", | ||
onConfirm: handleDelete, | ||
}} | ||
disabled={!identities.length} | ||
shiftClickEnabled | ||
showShiftClickHint | ||
> | ||
{buttonText} | ||
</ConfirmationButton> | ||
); | ||
}; | ||
|
||
export default BulkDeleteIdentitiesBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FC } from "react"; | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { queryKeys } from "util/queryKeys"; | ||
import { | ||
ConfirmationButton, | ||
Icon, | ||
useNotify, | ||
} from "@canonical/react-components"; | ||
import { useToastNotification } from "context/toastNotificationProvider"; | ||
import { LxdIdentity } from "types/permissions"; | ||
import ItemName from "components/ItemName"; | ||
import { deleteOIDCIdentity } from "api/auth-identities"; | ||
import ResourceLabel from "components/ResourceLabel"; | ||
|
||
interface Props { | ||
identity: LxdIdentity; | ||
} | ||
|
||
const DeleteIdentityBtn: FC<Props> = ({ identity }) => { | ||
const queryClient = useQueryClient(); | ||
const notify = useNotify(); | ||
const toastNotify = useToastNotification(); | ||
|
||
const handleDelete = () => { | ||
deleteOIDCIdentity(identity) | ||
.then(() => { | ||
void queryClient.invalidateQueries({ | ||
predicate: (query) => { | ||
return [queryKeys.identities, queryKeys.authGroups].includes( | ||
query.queryKey[0] as string, | ||
); | ||
}, | ||
}); | ||
toastNotify.success( | ||
<> | ||
Identity <ResourceLabel type={"idp-group"} value={identity.name} />{" "} | ||
deleted. | ||
</>, | ||
); | ||
close(); | ||
}) | ||
.catch((e) => { | ||
notify.failure( | ||
`Identity deletion failed`, | ||
e, | ||
<ResourceLabel type={"idp-group"} value={identity.name} />, | ||
); | ||
}); | ||
}; | ||
|
||
return ( | ||
<ConfirmationButton | ||
onHoverText={"Delete identity"} | ||
appearance="base" | ||
aria-label="Delete identity" | ||
className={"has-icon"} | ||
confirmationModalProps={{ | ||
title: "Confirm delete", | ||
children: ( | ||
<p> | ||
This will permanently delete <ItemName item={identity} bold />. | ||
<br /> | ||
This action cannot be undone, and can result in data loss. | ||
</p> | ||
), | ||
confirmButtonLabel: "Delete", | ||
onConfirm: handleDelete, | ||
}} | ||
shiftClickEnabled | ||
showShiftClickHint | ||
> | ||
<Icon name="delete" /> | ||
</ConfirmationButton> | ||
); | ||
}; | ||
|
||
export default DeleteIdentityBtn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters