Fixing updating attribute value

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor 2025-08-04 13:28:39 -03:00
parent 5436f9781c
commit a8997c364f
3 changed files with 14 additions and 11 deletions

View File

@ -17,7 +17,7 @@ export const TextAreaComponent = (props: UserProfileFieldProps) => {
rows={attribute.annotations?.["inputTypeRows"] as number}
readOnly={attribute.readOnly}
isRequired={isRequired}
value={attribute.defaultValue}
defaultValue={attribute.defaultValue}
/>
</UserProfileGroup>
);

View File

@ -31,7 +31,7 @@ export const TextComponent = (props: UserProfileFieldProps) => {
}
isDisabled={attribute.readOnly}
isRequired={isRequired}
value={attribute.defaultValue}
defaultValue={attribute.defaultValue}
{...form.register(fieldName(attribute.name))}
/>
</UserProfileGroup>

View File

@ -410,23 +410,20 @@ public class DefaultAttributes extends HashMap<String, List<String>> implements
}
}
// the profile should always hold all attributes defined in the config and set default value if needed
// the profile should always hold all attributes defined in the config
for (String attributeName : metadataByAttribute.keySet()) {
if (!isSupportedAttribute(attributeName) || newAttributes.containsKey(attributeName)) {
continue;
}
AttributeMetadata metadata = metadataByAttribute.get(attributeName);
List<String> values = EMPTY_VALUE;
if (metadata.getDefaultValue() != null) {
values = Collections.singletonList(metadata.getDefaultValue());
}
AttributeMetadata metadata = metadataByAttribute.get(attributeName);
if (user != null && isIncludeAttributeIfNotProvided(metadata)) {
values = normalizeAttributeValues(attributeName, user.getAttributes().getOrDefault(attributeName, EMPTY_VALUE));
values = user.getAttributes().getOrDefault(attributeName, EMPTY_VALUE);
}
newAttributes.put(attributeName, values);
newAttributes.put(attributeName, normalizeAttributeValues(attributeName, values));
}
if (user != null) {
@ -471,10 +468,16 @@ public class DefaultAttributes extends HashMap<String, List<String>> implements
if (value instanceof String) {
values = Collections.singletonList((String) value);
} else {
values = (List<String>) value;
values = value == null ? EMPTY_VALUE : (List<String>) value;
}
Stream<String> valuesStream = Optional.ofNullable(values).orElse(EMPTY_VALUE).stream().filter(Objects::nonNull);
AttributeMetadata metadata = metadataByAttribute.get(name);
if (values.isEmpty() && metadata != null && metadata.getDefaultValue() != null) {
values = List.of(metadata.getDefaultValue());
}
Stream<String> valuesStream = values.stream().filter(Objects::nonNull);
// do not normalize the username if a federated user because we need to respect the format from the external identity store
if ((UserModel.USERNAME.equals(name) && !isFederated()) || UserModel.EMAIL.equals(name)) {