diff --git a/src/components/modals/DeleteHBACRule.tsx b/src/components/modals/DeleteHBACRule.tsx index e7549901..cfcac749 100644 --- a/src/components/modals/DeleteHBACRule.tsx +++ b/src/components/modals/DeleteHBACRule.tsx @@ -59,14 +59,13 @@ const DeleteHBACRule = (props: PropsToDeleteRules) => { pfComponent: ( - Are you sure you want to remove the selected entries from User - groups? + Are you sure you want to remove the selected rules? ), }, { - id: "deleted-users-table", + id: "deleted-rules-table", pfComponent: ( { // Alerts to show in the UI const alerts = useAlerts(); - // Define 'executeEnableDisableCommand' to add user data to IPA server + // Define 'executeEnableDisableCommand' to add rules to IPA server const [executeEnableDisableCommand] = useBatchMutCommandMutation(); - // Single user operations - const [enableSingleUser] = useEnableUserMutation(); - const [disableSingleUser] = useDisableUserMutation(); + // Single rule operations + const [enableSingleRule] = useEnableHbacRuleMutation(); + const [disableSingleRule] = useDisableHbacRuleMutation(); // Define which action (enable | disable) based on 'optionSelected' const action = !props.optionSelected ? "enable" : "disable"; @@ -120,17 +120,16 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => { setIsModalErrorOpen(true); }; - // Modify user status using IPA commands - // TODO: Better Adapt this function to several use-cases + // Modify rule status using IPA commands const modifyStatus = (newStatus: boolean, selectedRules: HBACRule[]) => { - // Prepare users params + // Prepare rule params const idsToChangeStatusPayload: Command[] = []; const changeStatusParams = {}; const option = props.optionSelected ? "hbacrule_disable" : "hbacrule_enable"; - // Make the API call (depending on 'singleUser' value) + // Make the API call (depending on 'singleRule' value) if (props.singleRule === undefined || !props.singleRule) { selectedRules.map((rule) => { const payloadItem = { @@ -211,9 +210,9 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => { // Single rule operation let command; if (option === "hbacrule_disable") { - command = disableSingleUser; + command = disableSingleRule; } else { - command = enableSingleUser; + command = enableSingleRule; } const payload = props.selectedRulesData.selectedRules[0]; @@ -231,7 +230,7 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => { "'", "success" ); - // Reset selected users + // Reset selected rules props.selectedRulesData.clearSelectedRules(); // Refresh data if (props.onRefresh !== undefined) { @@ -319,7 +318,7 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => { /> ); - // Render 'DisableEnableUsers' + // Render 'DisableEnableHBACRules' return ( <> diff --git a/src/services/rpcHBAC.ts b/src/services/rpcHBAC.ts index 196878a8..23a83f74 100644 --- a/src/services/rpcHBAC.ts +++ b/src/services/rpcHBAC.ts @@ -4,6 +4,7 @@ import { getBatchCommand, getCommand, BatchRPCResponse, + FindRPCResponse, useGettingGenericQuery, } from "./rpc"; import { apiToHBACRule } from "src/utils/hbacRulesUtils"; @@ -17,6 +18,8 @@ import { HBACRule } from "../utils/datatypes/globalDataTypes"; * - removeHbacRules * - addToHbacRules * - removeFromHbacRules + * - disableHbacRule + * - enableHbacRule * * API commands: * - hbacrule_show: https://freeipa.readthedocs.io/en/latest/api/hbacrule_show.html @@ -30,6 +33,8 @@ import { HBACRule } from "../utils/datatypes/globalDataTypes"; * - hbacrule_remove_host: https://freeipa.readthedocs.io/en/latest/api/hbacrule_remove_host.html * - hbacrule_remove_service: https://freeipa.readthedocs.io/en/latest/api/hbacrule_remove_service.html * - hbacrule_remove_sourcehost: https://freeipa.readthedocs.io/en/latest/api/hbacrule_remove_sourcehost.html + * - hbacrule_disable: https://freeipa.readthedocs.io/en/latest/api/hbacrule_disable.html + * - hbacrule_enable: https://freeipa.readthedocs.io/en/latest/api/hbacrule_enable.html */ export interface HbacRulesShowPayload { @@ -196,6 +201,36 @@ const extendedApi = api.injectEndpoints({ return getBatchCommand(membersToRemove, API_VERSION_BACKUP); }, }), + enableHbacRule: build.mutation({ + query: (rule) => { + const params = [ + [rule.cn], + { + version: API_VERSION_BACKUP, + }, + ]; + + return getCommand({ + method: "hbacrule_enable", + params: params, + }); + }, + }), + disableHbacRule: build.mutation({ + query: (rule) => { + const params = [ + [rule.cn], + { + version: API_VERSION_BACKUP, + }, + ]; + + return getCommand({ + method: "hbacrule_disable", + params: params, + }); + }, + }), }), overrideExisting: false, }); @@ -212,4 +247,6 @@ export const { useGetHbacRulesInfoByNameQuery, useAddToHbacRulesMutation, useRemoveFromHbacRulesMutation, + useDisableHbacRuleMutation, + useEnableHbacRuleMutation, } = extendedApi;