Account Index: By default return only active accounts

If neither 'is:active' nor 'is:inactive' is contained in the query,
add 'is:active' to the query so that by default only active accounts
are returned.

Change-Id: I73f9b654e61f8c027eaa04d704d9b0280439ecf6
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2016-06-29 09:57:53 +02:00
parent b2326bec27
commit 6725d06c30
2 changed files with 10 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.server.index.IndexRewriter;
import com.google.gerrit.server.index.QueryOptions;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.account.AccountPredicates;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -37,6 +38,9 @@ public class AccountIndexRewriter implements IndexRewriter<AccountState> {
@Override
public Predicate<AccountState> rewrite(Predicate<AccountState> in,
QueryOptions opts) throws QueryParseException {
if (!AccountPredicates.hasActive(in)) {
in = Predicate.and(in, AccountPredicates.isActive());
}
AccountIndex index = indexes.getSearchIndex();
checkNotNull(index, "no active search index configured for accounts");
return new IndexedAccountQuery(index, in, opts);

View File

@@ -20,8 +20,13 @@ import com.google.gerrit.server.index.FieldDef;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gerrit.server.index.account.AccountField;
import com.google.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryBuilder;
public class AccountPredicates {
public static boolean hasActive(Predicate<AccountState> p) {
return QueryBuilder.find(p, AccountPredicate.class,
AccountField.ACTIVE.getName()) != null;
}
static Predicate<AccountState> id(Account.Id accountId) {
return new AccountPredicate(AccountField.ID,
@@ -38,7 +43,7 @@ public class AccountPredicates {
AccountQueryBuilder.FIELD_NAME, name);
}
static Predicate<AccountState> isActive() {
public static Predicate<AccountState> isActive() {
return new AccountPredicate(AccountField.ACTIVE, "1");
}