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 Jan 16, 2024
1 parent d15db9a commit 3c8039a
Show file tree
Hide file tree
Showing 4 changed files with 87 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 @@ -43,6 +43,7 @@ import {
ErrorResult,
useSaveUserMutation,
useSaveStageUserMutation,
useGenerateSubIdsMutation,
} from "src/services/rpc";
// Hooks
import useAlerts from "src/hooks/useAlerts";
Expand All @@ -53,6 +54,8 @@ import RebuildAutoMembership from "./modals/RebuildAutoMembership";
import UnlockUser from "./modals/UnlockUser";
import ResetPassword from "./modals/ResetPassword";
import IssueNewCertificate from "./modals/IssueNewCertificate";
// Utils
import { API_VERSION_BACKUP } from "src/utils/utils";

export interface PropsToUserSettings {
originalUser: Partial<User>;
Expand Down Expand Up @@ -173,6 +176,56 @@ const UserSettings = (props: PropsToUserSettings) => {
setIsNewCertificateModalOpen(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 @@ -220,6 +273,13 @@ const UserSettings = (props: PropsToUserSettings) => {
>
New certificate
</DropdownItem>,
<DropdownItem
key="auto assign subordinate ids"
isDisabled={isDisabledAutoAssignSubIds}
onClick={onClickAutoAssignSubIds}
>
Auto assign subordinate IDs
</DropdownItem>,
];

const stageDropdownItems = [
Expand Down
12 changes: 12 additions & 0 deletions src/services/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,17 @@ export const api = createApi({
response.result.result as unknown as CertProfile[],
providesTags: ["CertProfile"],
}),
generateSubIds: build.mutation<FindRPCResponse, any[]>({
query: (payload) => {
const params = [[], payload[0]];

return getCommand({
method: "subid_generate",
params: params,
});
},
invalidatesTags: ["FullUser"],
}),
}),
});

Expand Down Expand Up @@ -819,4 +830,5 @@ export const {
useUnlockUserMutation,
useChangePasswordMutation,
useGetCertProfileQuery,
useGenerateSubIdsMutation,
} = api;
13 changes: 13 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 @@ -319,3 +320,15 @@ export interface CertProfile {
ipacertprofilestoreissued: boolean;
dn: string;
}

export interface SubId {
ipauniqueid: string;
objectclass: string[];
ipaowner: string;
ipasubgidnumber: string;
ipasubuidnumber: string;
description: string;
ipasubuidcount: string;
ipasubgidcount: string;
dn: string;
}
2 changes: 2 additions & 0 deletions src/utils/userUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ export const objectToUser = (
// 'Member of' data
memberof_group:
partialUser.memberof_group || oldUserObject?.memberof_group || [],
memberof_subid:
partialUser.memberof_subid || oldUserObject?.memberof_subid || [],
// 'Managed by' data
mepmanagedentry:
partialUser.mepmanagedentry || oldUserObject?.mepmanagedentry || [],
Expand Down

0 comments on commit 3c8039a

Please sign in to comment.