Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Active users][Settings][Kebab] Add 'Auto assign subordinate ids' option #224

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -54,6 +55,8 @@ import UnlockUser from "./modals/UnlockUser";
import ResetPassword from "./modals/ResetPassword";
import IssueNewCertificate from "./modals/IssueNewCertificate";
import AddOtpToken from "./modals/AddOtpToken";
// Utils
import { API_VERSION_BACKUP } from "src/utils/utils";

export interface PropsToUserSettings {
originalUser: Partial<User>;
Expand Down Expand Up @@ -180,6 +183,56 @@ const UserSettings = (props: PropsToUserSettings) => {
setIsAddOtpTokenModalOpen(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 &&
pvoborni marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -232,6 +285,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 @@ -759,6 +759,17 @@ export const api = createApi({
});
},
}),
generateSubIds: build.mutation<FindRPCResponse, any[]>({
query: (payload) => {
const params = [[], payload[0]];

return getCommand({
method: "subid_generate",
params: params,
});
},
invalidatesTags: ["FullUser"],
}),
pvoborni marked this conversation as resolved.
Show resolved Hide resolved
}),
});

Expand Down Expand Up @@ -830,4 +841,5 @@ export const {
useChangePasswordMutation,
useGetCertProfileQuery,
useAddOtpTokenMutation,
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 @@ -332,3 +333,15 @@ export interface OTPToken {
type: string;
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
Loading