Add query operator that matches groups that are visible to all users
Change-Id: I161d66f26ace58a8e0d6a6183853936336ed0d15 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -22,6 +22,13 @@ inname:'NAMEPART'::
|
|||||||
Matches groups that have a name part that starts with 'NAMEPART'
|
Matches groups that have a name part that starts with 'NAMEPART'
|
||||||
(case-insensitive).
|
(case-insensitive).
|
||||||
|
|
||||||
|
[[is]]
|
||||||
|
[[is-visibleToAll]]
|
||||||
|
is:visibleToAll::
|
||||||
|
+
|
||||||
|
Matches groups that are in the groups options marked as visible to all
|
||||||
|
registered users.
|
||||||
|
|
||||||
[[name]]
|
[[name]]
|
||||||
name:'NAME'::
|
name:'NAME'::
|
||||||
+
|
+
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ public class GroupPredicates {
|
|||||||
GroupQueryBuilder.FIELD_OWNER, owner);
|
GroupQueryBuilder.FIELD_OWNER, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Predicate<AccountGroup> isVisibleToAll() {
|
||||||
|
return new GroupPredicate(GroupField.IS_VISIBLE_TO_ALL, "1");
|
||||||
|
}
|
||||||
|
|
||||||
static class GroupPredicate extends IndexPredicate<AccountGroup> {
|
static class GroupPredicate extends IndexPredicate<AccountGroup> {
|
||||||
GroupPredicate(FieldDef<AccountGroup, ?> def, String value) {
|
GroupPredicate(FieldDef<AccountGroup, ?> def, String value) {
|
||||||
super(def, value);
|
super(def, value);
|
||||||
|
|||||||
@@ -75,6 +75,14 @@ public class GroupQueryBuilder extends QueryBuilder<AccountGroup> {
|
|||||||
return GroupPredicates.owner(owner);
|
return GroupPredicates.owner(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operator
|
||||||
|
public Predicate<AccountGroup> is(String value) throws QueryParseException {
|
||||||
|
if ("visibleToAll".equalsIgnoreCase(value)) {
|
||||||
|
return GroupPredicates.isVisibleToAll();
|
||||||
|
}
|
||||||
|
throw error("Invalid query");
|
||||||
|
}
|
||||||
|
|
||||||
@Operator
|
@Operator
|
||||||
public Predicate<AccountGroup> limit(String query)
|
public Predicate<AccountGroup> limit(String query)
|
||||||
throws QueryParseException {
|
throws QueryParseException {
|
||||||
|
|||||||
@@ -241,6 +241,17 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
|||||||
assertQuery("owner:" + ownerGroup.id, group, ownerGroup);
|
assertQuery("owner:" + ownerGroup.id, group, ownerGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void byIsVisibleToAll() throws Exception {
|
||||||
|
assertQuery("is:visibleToAll");
|
||||||
|
|
||||||
|
GroupInfo groupThatIsVisibleToAll =
|
||||||
|
createGroupThatIsVisibleToAll(name("group-that-is-visible-to-all"));
|
||||||
|
createGroup(name("group"));
|
||||||
|
|
||||||
|
assertQuery("is:visibleToAll", groupThatIsVisibleToAll);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withLimit() throws Exception {
|
public void withLimit() throws Exception {
|
||||||
GroupInfo group1 = createGroup(name("group1"));
|
GroupInfo group1 = createGroup(name("group1"));
|
||||||
@@ -318,6 +329,14 @@ public abstract class AbstractQueryGroupsTest extends GerritServerTests {
|
|||||||
return gApi.groups().create(in).get();
|
return gApi.groups().create(in).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected GroupInfo createGroupThatIsVisibleToAll(String name)
|
||||||
|
throws Exception {
|
||||||
|
GroupInput in = new GroupInput();
|
||||||
|
in.name = name;
|
||||||
|
in.visibleToAll = true;
|
||||||
|
return gApi.groups().create(in).get();
|
||||||
|
}
|
||||||
|
|
||||||
protected GroupInfo getGroup(AccountGroup.UUID uuid) throws Exception {
|
protected GroupInfo getGroup(AccountGroup.UUID uuid) throws Exception {
|
||||||
return gApi.groups().id(uuid.get()).get();
|
return gApi.groups().id(uuid.get()).get();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user