From bdb8f889a5477b29429fb44337b73de8e3946caf Mon Sep 17 00:00:00 2001 From: Carla Martinez Date: Wed, 9 Aug 2023 14:45:11 +0200 Subject: [PATCH] Functionality for Text inputs The following fields need to be adapted to use the `IpaTextInput` component: - 'User login' (`uid`) - 'Password' (`has_password`) - 'Password expiration' (`krbpasswordexpiration`) - 'UID' (`uidnumber`) - 'GID' (`gidnumber`) - 'Login shell' (`loginshell`) - 'Home directory' (`homedirectory`) - 'Radius proxy username' (`ipatokenradiususername`) - 'External IdP user identifier' (`ipaidpsub`) Signed-off-by: Carla Martinez --- src/components/UserSettings.tsx | 7 +- .../UsersSections/UsersAccountSettings.tsx | 162 +++++++----------- src/hooks/useUserSettingsData.tsx | 14 +- 3 files changed, 82 insertions(+), 101 deletions(-) diff --git a/src/components/UserSettings.tsx b/src/components/UserSettings.tsx index a0cff31d..e78d5a2e 100644 --- a/src/components/UserSettings.tsx +++ b/src/components/UserSettings.tsx @@ -249,7 +249,12 @@ const UserSettings = (props: PropsToUserSettings) => { id="account-settings" text="Account settings" /> - + ; + onUserChange: (element: Partial) => void; + metadata: Metadata; + onRefresh: () => void; } // Generic data to pass to the Textbox adder @@ -38,32 +45,21 @@ interface ElementData { } const UsersAccountSettings = (props: PropsToUsersAccountSettings) => { - // TODO: This state variables should update the user data via the IPA API (`user_mod`) - const [userLogin] = useState(props.user.uid); + // TODO: Handle the `has_password` variable (boolean) by another Ipa component const [password] = useState(""); - const [passwordExpiration] = useState(""); - const [uid, setUid] = useState(props.user.uidnumber); - const [gid, setGid] = useState(""); + + // Get 'ipaObject' and 'recordOnChange' to use in 'IpaTextInput' + const { ipaObject, recordOnChange } = asRecord( + props.user, + props.onUserChange + ); + const [principalAliasList, setPrincipalAliasList] = useState([ { id: 0, element: props.user.uid + "@IPAEXAMPLE.TEST", }, ]); - const [homeDirectory, setHomeDirectory] = useState("/home/" + userLogin); - const [loginShell, setLoginShell] = useState("/bin/sh"); - const [radiusUsername, setRadiusUsername] = useState(""); - const [idpIdentifier, setIdpIdentifier] = useState(""); - - // UID - const uidInputHandler = (value: string) => { - setUid(value); - }; - - // GID - const gidInputHandler = (value: string) => { - setGid(value); - }; // Principal alias // - 'Add principal alias' handler @@ -96,16 +92,6 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => { setPrincipalAliasList(principalAliasListCopy); }; - // Home directory - const homeDirectoryInputHandler = (value: string) => { - setHomeDirectory(value); - }; - - // Login shell - const loginShellInputHandler = (value: string) => { - setLoginShell(value); - }; - // SSH public keys // -Text area const [textAreaSshPublicKeysValue, setTextAreaSshPublicKeysValue] = @@ -347,16 +333,6 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => { , ]; - // RADIUS username - const radiusUsernameInputHandler = (value: string) => { - setRadiusUsername(value); - }; - - // Track changes on External IdP user identifier textbox field - const idpIdentifierInputHandler = (value: string) => { - setIdpIdentifier(value); - }; - // Checkboxes const [passwordCheckbox] = useState(false); const [radiusCheckbox] = useState(false); @@ -503,13 +479,12 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => {
- @@ -519,40 +494,37 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => { value={password} type="password" aria-label="password" - isDisabled + readOnlyVariant="plain" /> - - - @@ -620,13 +592,12 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => { -
@@ -634,13 +605,12 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => {
- @@ -758,13 +728,12 @@ const UsersAccountSettings = (props: PropsToUsersAccountSettings) => { label="Radius proxy username" fieldId="radius-proxy-username" > - { label="External IdP user identifier" fieldId="external-idp-user-identifier" > -
diff --git a/src/hooks/useUserSettingsData.tsx b/src/hooks/useUserSettingsData.tsx index 7247e478..1ae89e34 100644 --- a/src/hooks/useUserSettingsData.tsx +++ b/src/hooks/useUserSettingsData.tsx @@ -84,9 +84,17 @@ const useUserSettingsData = (userId: string): UserSettingsData => { } let modified = false; for (const [key, value] of Object.entries(user)) { - if (userFullData.user[key] !== value) { - modified = true; - break; + if (Array.isArray(value)) { + // Using 'JSON.stringify' when comparing arrays (to prevent data type false positives) + if (JSON.stringify(userFullData.user[key]) !== JSON.stringify(value)) { + modified = true; + break; + } + } else { + if (userFullData.user[key] !== value) { + modified = true; + break; + } } } setModified(modified);