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:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user