8000 Keep the description of organization groups when importing a realm by vasipallyn · Pull Request #55176 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,10 @@ private void validateClientAndRealmTimeouts(RealmModel realm) {
private void importOrganizationGroup(OrganizationProvider provider, OrganizationModel organization, RealmModel realm, GroupRepresentation groupRep, GroupModel parent) {
GroupModel group = provider.createGroup(organization, groupRep.getId(), groupRep.getName(), parent);

if (groupRep.getDescription() != null) {
group.setDescription(groupRep.getDescription());
}

if (groupRep.getAttributes() != null) {
for (Map.Entry<String, List<String>> attr : groupRep.getAttributes().entrySet()) {
group.setAttribute(attr.getKey(), attr.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ private void validateOrganizationGroups(OrganizationResource organization, Map<S
// Validate group IDs are preserved
validateGroupIds(topLevelGroups, expectedGroupIds);

// Validate descriptions of top-level groups are preserved
for (GroupRepresentation group : topLevelGroups) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update can set a subgroup's description after addSubGroup. Could the test use that in its setup and check the descriptions of Development-0 and QA-0 after the round trip too?

assertEquals(groupDescription(group.getName()), group.getDescription(), "Group description mismatch for group: " + group.getName());
}

// Validate subgroups
validateSubGroups(organization, topLevelGroups, expectedGroupIds);

Expand Down Expand Up @@ -306,6 +311,11 @@ private void validateSubGroups(OrganizationResource organization, List<GroupRepr

// Validate group IDs are preserved
validateGroupIds(subGroups, expectedGroupIds);

// Validate descriptions of subgroups are preserved
for (GroupRepresentation group : subGroups) {
assertEquals(groupDescription(group.getName()), group.getDescription(), "Group description mismatch for group: " + group.getName());
}
}

private void validateGroupMemberships(OrganizationResource organization, List<GroupRepresentation> topLevelGroups) {
Expand Down Expand Up @@ -487,6 +497,7 @@ private void assertPartialExportImport(HttpClient client, OrganizationRepresenta
private String createTopLevelGroup(OrganizationResource organization, String name) {
GroupRepresentation group = new GroupRepresentation();
group.setName(name);
group.setDescription(groupDescription(name));
try (Response response = organization.groups().addTopLevelGroup(group)) {
assertThat(response.getStatus(), equalTo(Response.Status.CREATED.getStatusCode()));
return ApiUtil.getCreatedId(response);
Expand All @@ -496,9 +507,20 @@ private String createTopLevelGroup(OrganizationResource organization, String nam
private String createSubGroup(OrganizationResource organization, String parentId, String name) {
GroupRepresentation group = new GroupRepresentation();
group.setName(name);
String id;
try (Response response = organization.groups().group(parentId).addSubGroup(group)) {
assertThat(response.getStatus(), equalTo(Response.Status.CREATED.getStatusCode()));
return response.readEntity(GroupRepresentation.class).getId();
id = response.readEntity(GroupRepresentation.class).getId();
}
// addSubGroup does not store the description, so set it with an update
group.setDescription(groupDescription(name));
try (Response response = organization.groups().group(id).update(group)) {
assertThat(response.getStatus(), equalTo(Response.Status.NO_CONTENT.getStatusCode()));
}
return id;
}

private static String groupDescription(String groupName) {
return "Description of " + groupName;
}
}
0