Skip to content

Commit

Permalink
Add 'Auto assign subordinate ids' option
Browse files Browse the repository at this point in the history
The 'Auto assign subordinate ids' option
should assign a range of IDs to a given
user.

Signed-off-by: Carla Martinez <carlmart@redhat.com>
  • Loading branch information
carma12 committed Dec 18, 2023
1 parent d6f59a1 commit 29fa1bf
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/components/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ import {
ErrorResult,
useSaveUserMutation,
useSaveStageUserMutation,
useGenerateSubIdsMutation,
} from "src/services/rpc";
// Hooks
import useAlerts from "src/hooks/useAlerts";
// Modals
import DisableEnableUsers from "./modals/DisableEnableUsers";
import DeleteUsers from "./modals/DeleteUsers";
// Utils
import { API_VERSION_BACKUP } from "src/utils/utils";

export interface PropsToUserSettings {
originalUser: Partial<User>;
Expand Down Expand Up @@ -122,6 +125,56 @@ const UserSettings = (props: PropsToUserSettings) => {
setIsDeleteModalOpen(false);
};

// RTK hook: 'Auto assign subordinate IDs'
const [generateSubIds] = useGenerateSubIdsMutation();

// Data is updated on 'props.user' changes
React.useEffect(() => {
if (
props.user.memberof_subid !== undefined &&
props.user.memberof_subid.length > 0
) {
setIsDisabledAutoAssignSubIds(true);
}
}, [props.user]);

// 'Auto assign subordinate IDs' option
const [isDisabledAutoAssignSubIds, setIsDisabledAutoAssignSubIds] =
useState(false);

// 'Auto assign subordinate IDs' handler method
const onClickAutoAssignSubIds = () => {
// Prepare payload (params)
const payload = [
{
ipaowner: props.user.uid,
version: API_VERSION_BACKUP,
},
];

// Make API call
generateSubIds(payload).then((response) => {
if ("data" in response) {
if (response.data.result) {
// Disable kebab option
setIsDisabledAutoAssignSubIds(true);
// Refresh page
props.onRefresh();
// Show toast notification: success
alerts.addAlert(
"auto-assign-success",
response.data.result.summary,
"success"
);
} else if (response.data.error) {
// Show toast notification: error
const errorMessage = response.data.error as ErrorResult;
alerts.addAlert("auto-assign-error", errorMessage.message, "danger");
}
}
});
};

// Kebab
const [isKebabOpen, setIsKebabOpen] = useState(false);

Expand Down Expand Up @@ -152,6 +205,13 @@ const UserSettings = (props: PropsToUserSettings) => {
Rebuild auto membership
</DropdownItem>,
<DropdownItem key="new certificate">New certificate</DropdownItem>,
<DropdownItem
key="auto assign subordinate ids"
isDisabled={isDisabledAutoAssignSubIds}
onClick={onClickAutoAssignSubIds}
>
Auto assign subordinate IDs
</DropdownItem>,
];

const stageDropdownItems = [
Expand Down
11 changes: 11 additions & 0 deletions src/services/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,16 @@ export const api = createApi({
});
},
}),
generateSubIds: build.mutation<FindRPCResponse, any[]>({
query: (payload) => {
const params = [[], payload[0]];

return getCommand({
method: "subid_generate",
params: params,
});
},
}),
}),
});

Expand Down Expand Up @@ -767,4 +777,5 @@ export const {
useAutoMemberRebuildUsersMutation,
useEnableUserMutation,
useDisableUserMutation,
useGenerateSubIdsMutation,
} = api;
12 changes: 12 additions & 0 deletions src/utils/datatypes/globalDataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface User {
ipanthomedirectorydrive: string;
// 'Member of' data
memberof_group: string[]; // multivalue
memberof_subid?: string[]; // multivalue
// 'Managed by' data
mepmanagedentry: string[];
// other
Expand Down Expand Up @@ -312,3 +313,14 @@ export interface fqdnType {
dn: string;
fqdn: string[];
}
export interface SubId {
ipauniqueid: string;
objectclass: string[];
ipaowner: string;
ipasubgidnumber: string;
ipasubuidnumber: string;
description: string;
ipasubuidcount: string;
ipasubgidcount: string;
dn: string;
}

0 comments on commit 29fa1bf

Please sign in to comment.