Change arg of getSubGroups to briefRepresentation

Parameter name briefRepresentation should mean briefRepresentation,
   not full. This way callers will by default get the full
   representation, unless true is passed as value for
   briefRepresentation.

   Fixes #25096

Signed-off-by: Erwin Rooijakkers <erwin@rooijakkers.software>
This commit is contained in:
Erwin Rooijakkers 2023-12-11 15:09:15 +01:00 committed by Marek Posolda
parent 08751001db
commit 860978b15a
4 changed files with 33 additions and 2 deletions

View file

@ -0,0 +1,3 @@
= Fix handling of Groups.getSubGroups briefRepresentation parameter
Version 23.0.0 introduced a new endpoint getSubGroups ("children") on the Groups resource, where the meaning of the parameter briefRepresentation meant the retrieval of full representations of the sub groups. The meaning is now changed to return the brief representation.

View file

@ -4,6 +4,10 @@
include::changes-24_0_0.adoc[leveloffset=3]
=== Migrating to 23.0.3
include::changes-23_0_3.adoc[leveloffset=3]
=== Migrating to 23.0.2
include::changes-23_0_2.adoc[leveloffset=3]

View file

@ -159,12 +159,12 @@ public class GroupResource {
@Operation( summary = "Return a paginated list of subgroups that have a parent group corresponding to the group on the URL")
public Stream<GroupRepresentation> getSubGroups(@QueryParam("first") @DefaultValue("0") Integer first,
@QueryParam("max") @DefaultValue("10") Integer max,
@QueryParam("briefRepresentation") @DefaultValue("false") Boolean full) {
@QueryParam("briefRepresentation") @DefaultValue("false") Boolean briefRepresentation) {
this.auth.groups().requireView(group);
boolean canViewGlobal = auth.groups().canView();
return group.getSubGroupsStream(first, max)
.filter(g -> canViewGlobal || auth.groups().canView(g))
.map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(auth.groups(), g, full)));
.map(g -> GroupUtils.populateSubGroupCount(g, GroupUtils.toRepresentation(auth.groups(), g, !briefRepresentation)));
}
/**

View file

@ -1095,6 +1095,30 @@ public class GroupTest extends AbstractGroupTest {
assertNull(groups.get(0).getAttributes());
}
@Test
public void getSubGroups() throws Exception {
RealmResource realm = adminClient.realms().realm("test");
GroupRepresentation parent = new GroupRepresentation();
parent.setName("parent");
parent = createGroup(realm, parent);
GroupRepresentation child = new GroupRepresentation();
child.setName("child");
Map<String, List<String>> attributes = new HashMap<String, List<String>>();
attributes.put("attribute1", Arrays.asList("value1", "value2"));
child.setAttributes(attributes);
addSubGroup(realm, parent, child);
// Check brief and full retrieval of subgroups of parent
boolean briefRepresentation = true;
assertNull(realm.groups().group(parent.getId()).getSubGroups(null, null, briefRepresentation).get(0).getAttributes());
briefRepresentation = false;
assertThat(realm.groups().group(parent.getId()).getSubGroups(null, null, briefRepresentation).get(0).getAttributes().get("attribute1"), containsInAnyOrder("value1", "value2"));
}
@Test
public void searchAndCountGroups() throws Exception {
String firstGroupId = "";