Add group query operator to match groups by owner

Change-Id: Ifcbbb1e2694d57f887a2282e543fdedbe571a43e
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-01-04 12:00:33 +01:00
parent c109ec165a
commit e661af0d43
4 changed files with 36 additions and 0 deletions

View File

@@ -27,6 +27,11 @@ name:'NAME'::
+
Matches groups that have the name 'NAME' (case-insensitive).
[[owner]]
owner:'UUID'::
+
Matches groups that are owned by a group that has the UUID 'UUID'.
[[uuid]]
uuid:'UUID'::
+

View File

@@ -43,6 +43,11 @@ public class GroupPredicates {
GroupQueryBuilder.FIELD_NAME, name.toLowerCase(Locale.US));
}
public static Predicate<AccountGroup> owner(String owner) {
return new GroupPredicate(GroupField.OWNER_UUID,
GroupQueryBuilder.FIELD_OWNER, owner);
}
static class GroupPredicate extends IndexPredicate<AccountGroup> {
GroupPredicate(FieldDef<AccountGroup, ?> def, String value) {
super(def, value);

View File

@@ -31,6 +31,7 @@ public class GroupQueryBuilder extends QueryBuilder<AccountGroup> {
public static final String FIELD_DESCRIPTION = "description";
public static final String FIELD_INNAME = "inname";
public static final String FIELD_NAME = "name";
public static final String FIELD_OWNER = "owner";
public static final String FIELD_LIMIT = "limit";
private static final QueryBuilder.Definition<AccountGroup, GroupQueryBuilder> mydef =
@@ -69,6 +70,11 @@ public class GroupQueryBuilder extends QueryBuilder<AccountGroup> {
return GroupPredicates.name(name);
}
@Operator
public Predicate<AccountGroup> owner(String owner) {
return GroupPredicates.owner(owner);
}
@Operator
public Predicate<AccountGroup> limit(String query)
throws QueryParseException {

View File

@@ -229,6 +229,18 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
assertQuery("description:\"\"");
}
@Test
public void byOwner() throws Exception {
assertQuery("owner:non-existing");
GroupInfo ownerGroup = createGroup(name("owner-group"));
GroupInfo group = createGroupWithOwner(name("group"), ownerGroup);
createGroup(name("group2"));
// ownerGroup owns itself
assertQuery("owner:" + ownerGroup.id, group, ownerGroup);
}
@Test
public void withLimit() throws Exception {
GroupInfo group1 = createGroup(name("group1"));
@@ -298,6 +310,14 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
return gApi.groups().create(in).get();
}
protected GroupInfo createGroupWithOwner(String name, GroupInfo ownerGroup)
throws Exception {
GroupInput in = new GroupInput();
in.name = name;
in.ownerId = ownerGroup.id;
return gApi.groups().create(in).get();
}
protected GroupInfo getGroup(AccountGroup.UUID uuid) throws Exception {
return gApi.groups().id(uuid.get()).get();
}