From e92ed5b98c04f9417d7d32d9d972f7d4f939c096 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 27 May 2022 11:26:37 +0200 Subject: [PATCH] Use endpoint for required actions (#2692) --- public/resources/en/users.json | 3 --- src/user/UserForm.tsx | 37 +++++++++++++++------------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/public/resources/en/users.json b/public/resources/en/users.json index 2ed26f2846..41942dc363 100644 --- a/public/resources/en/users.json +++ b/public/resources/en/users.json @@ -72,9 +72,6 @@ "linkAccountTitle": "Link account to {{provider}}?", "idpLinkSuccess": "Identity provider has been linked", "couldNotLinkIdP": "Could not link identity provider {{error}}", - "configureOTP": "Configure OTP", - "updatePassword": "Update Password", - "updateProfile": "Update Profile", "verifyEmail": "Verify Email", "updateUserLocale": "Update User Locale", "consents": "Consents", diff --git a/src/user/UserForm.tsx b/src/user/UserForm.tsx index f4b72a8518..25ee508c70 100644 --- a/src/user/UserForm.tsx +++ b/src/user/UserForm.tsx @@ -27,6 +27,7 @@ import { emailRegexPattern } from "../util"; import { GroupPickerDialog } from "../components/group/GroupPickerDialog"; import moment from "moment"; import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; +import type RequiredActionProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation"; export type BruteForced = { isBruteForceProtected?: boolean; @@ -75,17 +76,22 @@ export const UserForm = ({ const [open, setOpen] = useState(false); const [locked, setLocked] = useState(isLocked); const [realm, setRealm] = useState(); + const [requiredActions, setRequiredActions] = useState< + RequiredActionProviderRepresentation[] + >([]); useFetch( - async () => { - const realm = await adminClient.realms.findOne({ realm: realmName }); + () => + Promise.all([ + adminClient.realms.findOne({ realm: realmName }), + adminClient.authenticationManagement.getRequiredActions(), + ]), + ([realm, actions]) => { if (!realm) { throw new Error(t("common:notFound")); } - return realm; - }, - (realm) => { setRealm(realm); + setRequiredActions(actions); }, [] ); @@ -99,21 +105,6 @@ export const UserForm = ({ } }; - const requiredUserActionsOptions = [ - - {t("configureOTP")} - , - - {t("updatePassword")} - , - - {t("updateProfile")} - , - - {t("verifyEmail")} - , - ]; - const clearSelection = () => { setRequiredUserActionsDropdownOpen(false); }; @@ -372,7 +363,11 @@ export const UserForm = ({ onClear={clearSelection} variant="typeaheadmulti" > - {requiredUserActionsOptions} + {requiredActions.map(({ alias, name }) => ( + + {name} + + ))} )} />