ReviewerPredicate: Filter out draft changes when DRAFT workflow is disabled

Change-Id: Icd11184d893d0a32c2112534d05f053acdf8a700
This commit is contained in:
David Ostrovsky
2014-01-29 08:25:23 +01:00
parent 945fbd4bea
commit 58aa6d58ab
6 changed files with 33 additions and 7 deletions

View File

@@ -215,6 +215,10 @@ public class ChangeField {
public Iterable<Integer> get(ChangeData input, FillArgs args)
throws OrmException {
Set<Integer> r = Sets.newHashSet();
if (!args.allowsDrafts &&
input.change().getStatus() == Change.Status.DRAFT) {
return r;
}
for (PatchSetApproval a : input.approvals().values()) {
r.add(a.getAccountId().get());
}

View File

@@ -14,10 +14,13 @@
package com.google.gerrit.server.index;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.TrackingFooters;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import org.eclipse.jgit.lib.Config;
/**
* Definition of a field stored in the secondary index.
*
@@ -55,10 +58,15 @@ public abstract class FieldDef<I, T> {
/** Arguments needed to fill in missing data in the input object. */
public static class FillArgs {
final TrackingFooters trackingFooters;
final boolean allowsDrafts;
@Inject
FillArgs(TrackingFooters trackingFooters) {
FillArgs(TrackingFooters trackingFooters,
@GerritServerConfig Config cfg) {
this.trackingFooters = trackingFooters;
this.allowsDrafts = cfg == null
? true
: cfg.getBoolean("change", "allowDrafts", true);
}
}

View File

@@ -35,7 +35,7 @@ public class BasicChangeRewrites extends QueryRewriter<ChangeData> {
new InvalidProvider<ReviewDb>(), //
new InvalidProvider<ChangeQueryRewriter>(), //
null, null, null, null, null, null, null, //
null, null, null, null, null, null, null, null, null), null);
null, null, null, null, null, null, null, null, null, null), null);
private static final QueryRewriter.Definition<ChangeData, BasicChangeRewrites> mydef =
new QueryRewriter.Definition<ChangeData, BasicChangeRewrites>(

View File

@@ -31,6 +31,7 @@ import com.google.gerrit.server.account.CapabilityControl;
import com.google.gerrit.server.account.GroupBackend;
import com.google.gerrit.server.account.GroupBackends;
import com.google.gerrit.server.config.AllProjectsName;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.TrackingFooters;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.SubmitStrategyFactory;
@@ -51,6 +52,7 @@ import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.Config;
import java.util.ArrayList;
import java.util.Collection;
@@ -161,6 +163,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
final SubmitStrategyFactory submitStrategyFactory;
final ConflictsCache conflictsCache;
final TrackingFooters trackingFooters;
final boolean allowsDrafts;
@Inject
@VisibleForTesting
@@ -181,7 +184,8 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
IndexCollection indexes,
SubmitStrategyFactory submitStrategyFactory,
ConflictsCache conflictsCache,
TrackingFooters trackingFooters) {
TrackingFooters trackingFooters,
@GerritServerConfig Config cfg) {
this.db = dbProvider;
this.rewriter = rewriter;
this.userFactory = userFactory;
@@ -200,6 +204,9 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
this.submitStrategyFactory = submitStrategyFactory;
this.conflictsCache = conflictsCache;
this.trackingFooters = trackingFooters;
this.allowsDrafts = cfg == null
? true
: cfg.getBoolean("change", "allowDrafts", true);
}
}
@@ -305,7 +312,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
}
if ("reviewer".equalsIgnoreCase(value)) {
return new ReviewerPredicate(self());
return new ReviewerPredicate(self(), args.allowsDrafts);
}
if ("mergeable".equalsIgnoreCase(value)) {
@@ -581,7 +588,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
Set<Account.Id> m = parseAccount(who);
List<ReviewerPredicate> p = Lists.newArrayListWithCapacity(m.size());
for (Account.Id id : m) {
p.add(new ReviewerPredicate(id));
p.add(new ReviewerPredicate(id, args.allowsDrafts));
}
return Predicate.or(p);
}

View File

@@ -15,16 +15,19 @@
package com.google.gerrit.server.query.change;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.index.ChangeField;
import com.google.gerrit.server.index.IndexPredicate;
import com.google.gwtorm.server.OrmException;
class ReviewerPredicate extends IndexPredicate<ChangeData> {
private final Account.Id id;
private boolean allowDrafts;
ReviewerPredicate(Account.Id id) {
ReviewerPredicate(Account.Id id, boolean allowDrafts) {
super(ChangeField.REVIEWER, id.toString());
this.id = id;
this.allowDrafts = allowDrafts;
}
Account.Id getAccountId() {
@@ -33,6 +36,10 @@ class ReviewerPredicate extends IndexPredicate<ChangeData> {
@Override
public boolean match(final ChangeData object) throws OrmException {
if (!allowDrafts &&
object.change().getStatus() == Change.Status.DRAFT) {
return false;
}
for (Account.Id accountId : object.reviewers().values()) {
if (id.equals(accountId)) {
return true;

View File

@@ -27,7 +27,7 @@ public class FakeQueryBuilder extends ChangeQueryBuilder {
FakeQueryBuilder.class),
new ChangeQueryBuilder.Arguments(null, null, null, null, null, null,
null, null, null, null, null, null, null, null, indexes, null, null,
null),
null, null),
null);
}