forked from freeipa/freeipa-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The option 6 on revokation reasons refers to the 'Certificate hold' one. When selecting this option, the 'Remove hold' option should be enabled in the UI to allow users to enable again the given certificate. Signed-off-by: Carla Martinez <[email protected]>
- Loading branch information
Showing
3 changed files
with
152 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React from "react"; | ||
// PatternFly | ||
import { Button } from "@patternfly/react-core"; | ||
// Modals | ||
import InformationModalLayout from "../layouts/InformationModalLayout"; | ||
// Components | ||
import TextLayout from "../layouts/TextLayout"; | ||
// Hooks | ||
import useAlerts from "src/hooks/useAlerts"; | ||
// Data types | ||
import { CertificateData } from "../Form/IpaCertificates"; | ||
// Utils | ||
import { parseDn } from "src/utils/utils"; | ||
// RPC | ||
import { | ||
ErrorResult, | ||
useRemoveHoldCertificateMutation, | ||
} from "src/services/rpc"; | ||
|
||
interface PropsToRemoveHoldCertificate { | ||
certificate: CertificateData; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
onRefresh: () => void; | ||
} | ||
|
||
const RemoveHoldCertificate = (props: PropsToRemoveHoldCertificate) => { | ||
// Alerts to show in the UI | ||
const alerts = useAlerts(); | ||
|
||
// Prepare "cert_remove_hold" API call | ||
const [certRemoveHold] = useRemoveHoldCertificateMutation(); | ||
|
||
const onRemoveHold = () => { | ||
// Prepare payload | ||
const serialNumber = props.certificate.certInfo.serial_number; | ||
const cacn = props.certificate.certInfo.cacn; | ||
const payload = [serialNumber, cacn]; | ||
|
||
// Perform the API call | ||
certRemoveHold(payload).then((response) => { | ||
if ("data" in response) { | ||
if (response.data.result) { | ||
// Close modal | ||
props.onClose(); | ||
// Set alert: success | ||
alerts.addAlert( | ||
"remove-hold-certificate-success", | ||
"Certificate hold removed", | ||
"success" | ||
); | ||
} else if (response.data.error) { | ||
// Set alert: error | ||
const errorMessage = response.data.error as ErrorResult; | ||
alerts.addAlert( | ||
"remove-hold-certificate-error", | ||
errorMessage.message, | ||
"danger" | ||
); | ||
} | ||
// Refresh data to show new changes in the UI | ||
props.onRefresh(); | ||
} | ||
}); | ||
}; | ||
|
||
const infoModalActions = [ | ||
<Button key="remove-hold" variant="danger" onClick={onRemoveHold}> | ||
Remove hold | ||
</Button>, | ||
<Button key="close" variant="link" onClick={props.onClose}> | ||
Close | ||
</Button>, | ||
]; | ||
|
||
const contentMessage = ( | ||
<TextLayout>Do you want to remove the certificate hold?</TextLayout> | ||
); | ||
|
||
return ( | ||
<> | ||
<alerts.ManagedAlerts /> | ||
<InformationModalLayout | ||
title={ | ||
"Certificate for " + parseDn(props.certificate.certInfo.issuer).cn | ||
} | ||
variant="medium" | ||
actions={infoModalActions} | ||
isOpen={props.isOpen} | ||
onClose={props.onClose} | ||
content={contentMessage} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default RemoveHoldCertificate; |
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