Normalize regex attribute values before saving (#1381)
This commit is contained in:
parent
acd8921b20
commit
7c4f0149b2
1 changed files with 11 additions and 11 deletions
|
@ -31,7 +31,7 @@ import { AssociatedRolesModal } from "../../realm-roles/AssociatedRolesModal";
|
||||||
import type { RoleRepresentation } from "../../model/role-model";
|
import type { RoleRepresentation } from "../../model/role-model";
|
||||||
import { useAlerts } from "../../components/alert/Alerts";
|
import { useAlerts } from "../../components/alert/Alerts";
|
||||||
import type { IdentityProviderEditMapperParams } from "../routes/EditMapper";
|
import type { IdentityProviderEditMapperParams } from "../routes/EditMapper";
|
||||||
import { convertToFormValues } from "../../util";
|
import { convertFormValuesToObject, convertToFormValues } from "../../util";
|
||||||
import { toIdentityProvider } from "../routes/IdentityProvider";
|
import { toIdentityProvider } from "../routes/IdentityProvider";
|
||||||
import type IdentityProviderMapperRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderMapperRepresentation";
|
import type IdentityProviderMapperRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderMapperRepresentation";
|
||||||
import { AddMapperForm } from "./AddMapperForm";
|
import { AddMapperForm } from "./AddMapperForm";
|
||||||
|
@ -83,16 +83,19 @@ export const AddMapper = () => {
|
||||||
const [rolesModalOpen, setRolesModalOpen] = useState(false);
|
const [rolesModalOpen, setRolesModalOpen] = useState(false);
|
||||||
|
|
||||||
const save = async (idpMapper: IdentityProviderMapperRepresentation) => {
|
const save = async (idpMapper: IdentityProviderMapperRepresentation) => {
|
||||||
|
const attributes = JSON.stringify(idpMapper.config?.attributes ?? []);
|
||||||
|
const config = convertFormValuesToObject({
|
||||||
|
...idpMapper.config,
|
||||||
|
attributes,
|
||||||
|
});
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
const updatedMapper = {
|
const updatedMapper = {
|
||||||
...idpMapper,
|
...idpMapper,
|
||||||
identityProviderAlias: alias!,
|
identityProviderAlias: alias!,
|
||||||
id: id,
|
id: id,
|
||||||
name: currentMapper?.name!,
|
name: currentMapper?.name!,
|
||||||
config: {
|
config,
|
||||||
...idpMapper.config,
|
|
||||||
attributes: JSON.stringify(idpMapper.config?.attributes!),
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
await adminClient.identityProviders.updateMapper(
|
await adminClient.identityProviders.updateMapper(
|
||||||
|
@ -112,10 +115,7 @@ export const AddMapper = () => {
|
||||||
identityProviderMapper: {
|
identityProviderMapper: {
|
||||||
...idpMapper,
|
...idpMapper,
|
||||||
identityProviderAlias: alias,
|
identityProviderAlias: alias,
|
||||||
config: {
|
config,
|
||||||
...idpMapper.config,
|
|
||||||
attributes: JSON.stringify(idpMapper.config.attributes),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
alias: alias!,
|
alias: alias!,
|
||||||
});
|
});
|
||||||
|
@ -157,10 +157,10 @@ export const AddMapper = () => {
|
||||||
form.reset();
|
form.reset();
|
||||||
Object.entries(mapper).map(([key, value]) => {
|
Object.entries(mapper).map(([key, value]) => {
|
||||||
if (key === "config") {
|
if (key === "config") {
|
||||||
if (mapper.config?.["are-attribute-values-regex"]) {
|
if (mapper.config?.["are.attribute.values.regex"]) {
|
||||||
form.setValue(
|
form.setValue(
|
||||||
"config.are-attribute-values-regex",
|
"config.are-attribute-values-regex",
|
||||||
value["are-attribute-values-regex"][0]
|
mapper.config["are.attribute.values.regex"]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue