Skip to content

Commit

Permalink
Apply Carlas suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mreynolds389 committed Jun 4, 2024
1 parent f4a3afa commit 1123a5c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/components/modals/DeleteHBACRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ const DeleteHBACRule = (props: PropsToDeleteRules) => {
pfComponent: (
<TextContent>
<Text component={TextVariants.p}>
Are you sure you want to remove the selected entries from User
groups?
Are you sure you want to remove the selected rules?
</Text>
</TextContent>
),
},
{
id: "deleted-users-table",
id: "deleted-rules-table",
pfComponent: (
<DeletedElementsTable
mode="passing_full_data"
Expand Down
29 changes: 14 additions & 15 deletions src/components/modals/DisableEnableHBACRules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
ErrorResult,
} from "src/services/rpc";
import {
useEnableUserMutation,
useDisableUserMutation,
} from "src/services/rpcUsers";
useDisableHbacRuleMutation,
useEnableHbacRuleMutation,
} from "src/services/rpcHBAC";
// Errors
import { FetchBaseQueryError } from "@reduxjs/toolkit/dist/query";
import { SerializedError } from "@reduxjs/toolkit";
Expand Down Expand Up @@ -53,11 +53,11 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => {
// 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";
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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];
Expand All @@ -231,7 +230,7 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => {
"'",
"success"
);
// Reset selected users
// Reset selected rules
props.selectedRulesData.clearSelectedRules();
// Refresh data
if (props.onRefresh !== undefined) {
Expand Down Expand Up @@ -319,7 +318,7 @@ const DisableEnableHBACRules = (props: PropsToDisableEnableHBACRules) => {
/>
);

// Render 'DisableEnableUsers'
// Render 'DisableEnableHBACRules'
return (
<>
<alerts.ManagedAlerts />
Expand Down
37 changes: 37 additions & 0 deletions src/services/rpcHBAC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getBatchCommand,
getCommand,
BatchRPCResponse,
FindRPCResponse,
useGettingGenericQuery,
} from "./rpc";
import { apiToHBACRule } from "src/utils/hbacRulesUtils";
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -196,6 +201,36 @@ const extendedApi = api.injectEndpoints({
return getBatchCommand(membersToRemove, API_VERSION_BACKUP);
},
}),
enableHbacRule: build.mutation<FindRPCResponse, HBACRule>({
query: (rule) => {
const params = [
[rule.cn],
{
version: API_VERSION_BACKUP,
},
];

return getCommand({
method: "hbacrule_enable",
params: params,
});
},
}),
disableHbacRule: build.mutation<FindRPCResponse, HBACRule>({
query: (rule) => {
const params = [
[rule.cn],
{
version: API_VERSION_BACKUP,
},
];

return getCommand({
method: "hbacrule_disable",
params: params,
});
},
}),
}),
overrideExisting: false,
});
Expand All @@ -212,4 +247,6 @@ export const {
useGetHbacRulesInfoByNameQuery,
useAddToHbacRulesMutation,
useRemoveFromHbacRulesMutation,
useDisableHbacRuleMutation,
useEnableHbacRuleMutation,
} = extendedApi;

0 comments on commit 1123a5c

Please sign in to comment.