Fix default values for group and role mappers (#1511)

* fixed defaults for group and role mappers

* incorporate jon PR comments
This commit is contained in:
mfrances17 2021-11-19 09:01:14 -05:00 committed by GitHub
parent 0b95598411
commit 7105bb9917
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,8 @@ import {
ValidatedOptions,
} from "@patternfly/react-core";
import React, { useState } from "react";
import { useParams } from "react-router-dom";
import type { UserFederationLdapMapperParams } from "../../routes/UserFederationLdapMapper";
import { HelpItem } from "../../../components/help-enabler/HelpItem";
import { Controller, UseFormMethods } from "react-hook-form";
import { useTranslation } from "react-i18next";
@ -32,6 +34,7 @@ export const LdapMapperRoleGroup = ({
useState(false);
const [isClientIdDropdownOpen, setIsClientIdDropdownOpen] = useState(false);
const [clients, setClients] = useState<ClientRepresentation[]>([]);
const { id, mapperId } = useParams<UserFederationLdapMapperParams>();
let isRole = true;
const groupMapper = "group-ldap-mapper";
@ -52,6 +55,29 @@ export const LdapMapperRoleGroup = ({
[]
);
useFetch(
async () => {
return await adminClient.components.findOne({ id });
},
(fetchedComponent) => {
if (fetchedComponent) {
const vendor = fetchedComponent.config?.vendor[0];
if (mapperId === "new" && vendor === "ad") {
form.setValue(
isRole
? "config.role-object-classes[0]"
: "config.group-object-classes[0]",
"group"
);
form.setValue("config.membership-user-ldap-attribute[0]", "cn");
}
} else if (id) {
throw new Error(t("common:notFound"));
}
},
[]
);
return (
<>
<FormGroup
@ -143,7 +169,7 @@ export const LdapMapperRoleGroup = ({
type="text"
id="kc-object-classes"
data-testid="object-classes"
defaultValue="group"
defaultValue="groupOfNames"
name={
isRole
? "config.role-object-classes[0]"
@ -290,7 +316,7 @@ export const LdapMapperRoleGroup = ({
type="text"
id="kc-membership-user-ldap-attribute"
data-testid="membership-user-ldap-attribute"
defaultValue="cn"
defaultValue="uid"
name="config.membership-user-ldap-attribute[0]"
ref={form.register}
/>
@ -487,6 +513,7 @@ export const LdapMapperRoleGroup = ({
>
<Controller
name="config.client-id[0]"
defaultValue=""
control={form.control}
render={({ onChange, value }) => (
<Select