Skip to content

Add support to dynamically display attributes in user creation wizard #8101

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

Merged
merged 10 commits into from
Apr 29, 2025
54 changes: 53 additions & 1 deletion features/admin.users.v1/components/wizard/add-user-wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

// Keep statement as this to avoid cyclic dependency. Do not import from config index.
import { FeatureConfigInterface } from "@wso2is/admin.core.v1/models/config";
import { AppState } from "@wso2is/admin.core.v1/store";
import { userConfig } from "@wso2is/admin.extensions.v1";
import { administratorConfig } from "@wso2is/admin.extensions.v1/configs/administrator";
import { SCIMConfigs } from "@wso2is/admin.extensions.v1/configs/scim";
Expand All @@ -40,10 +42,12 @@ import { Heading, LinkButton, PrimaryButton, Steps, useWizardAlert } from "@wso2
import { AxiosError, AxiosResponse } from "axios";
import cloneDeep from "lodash-es/cloneDeep";
import intersection from "lodash-es/intersection";
import isEmpty from "lodash-es/isEmpty";
import merge from "lodash-es/merge";
import omit from "lodash-es/omit";
import React, { FunctionComponent, ReactElement, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { Dispatch } from "redux";
import { Grid, Icon, Modal } from "semantic-ui-react";
import { AddUserUpdated } from "./steps/add-user-basic";
Expand Down Expand Up @@ -124,6 +128,8 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
const [ submitGroupList, setSubmitGroupList ] = useTrigger();
const [ finishSubmit, setFinishSubmit ] = useTrigger();

const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features);

const [ partiallyCompletedStep, setPartiallyCompletedStep ] = useState<number>(undefined);
const [ currentWizardStep, setCurrentWizardStep ] = useState<number>(currentStep);
const [ wizardState, setWizardState ] = useState<WizardStateInterface>(undefined);
Expand All @@ -141,6 +147,10 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
const [ submitStep, setSubmitStep ] = useState<WizardStepsFormTypes>(undefined);
const [ selectedGroupsList, setSelectedGroupList ] = useState<GroupsInterface[]>([]);

const isDistinctAttributeProfileForUserCreationDisabled: boolean = featureConfig?.users?.disabledFeatures?.includes(
UserManagementConstants.DISTINCT_ATTRIBUTE_PROFILES_FOR_USER_CREATION_FEATURE_FLAG
);

const excludedAttributes: string = "members";

const {
Expand Down Expand Up @@ -502,6 +512,48 @@ export const AddUserWizard: FunctionComponent<AddUserWizardPropsInterface> = (
};
}

if (!isDistinctAttributeProfileForUserCreationDisabled) {
const combinedUserDetails: UserDetailsInterface = omit({
...userInfo,
...userDetails
}, "passwordOption", "newPassword", "userType", "domain", "firstName", "lastName");

// If email value is not present, use the emails value.
if (isEmpty(userInfo?.email) && userInfo?.emails.length > 0) {
delete combinedUserDetails.email;

const primaryEmail: string = userInfo.emails.find((subAttribute: any) =>
typeof subAttribute === "string");

if (primaryEmail) {
combinedUserDetails.emails = [
{
primary: true,
value: primaryEmail
},
...userInfo?.emails
];
}
else {
// This means that the user has not provided any email value.
// This is an invalid case. Therefore, we need to throw an error.
dispatch(addAlert({
description: t(
"users:notifications.addUser.genericError.description"
),
level: AlertLevels.ERROR,
message: t(
"users:notifications.addUser.genericError.message"
)
}));

return;
}
}

userDetails = { ...combinedUserDetails };
}

setIsSubmitting(true);

addUser(userDetails)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 200px;
display: inline-block;
vertical-align: bottom;
}
Loading
Loading