Don't add non-existing accounts as reviewers

When adding reviewers to a change an account ID can be given as input.
In this case it was not checked if an account with such an ID actually
exists.

Change-Id: Ib4ff0041cd7bff26e359cf1826d3b56f1bd16837
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2013-02-25 10:49:38 +01:00
parent cdcc88ddc4
commit d5c40b4d6e

View File

@@ -28,7 +28,9 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.server.account.AccountState;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -45,10 +47,12 @@ public class Reviewers implements
static class Parser {
private final AccountResolver resolver;
private final AccountCache accountCache;
@Inject
Parser(AccountResolver resolver) {
Parser(AccountResolver resolver, AccountCache accountCache) {
this.resolver = resolver;
this.accountCache = accountCache;
}
Account.Id parse(ChangeResource rsrc, String id)
@@ -67,7 +71,9 @@ public class Reviewers implements
if (matches.size() != 1) {
return null;
}
return Iterables.getOnlyElement(matches);
AccountState a =
accountCache.getIfPresent(Iterables.getOnlyElement(matches));
return a != null ? a.getAccount().getId() : null;
}
}
}