Create ChangeUpdates with IdentifiedUsers rather than Accounts
Allows the user to be passed into MetaDataUpdate.create() so we can create updates by arbitrary users, e.g. when posting a review on behalf of someone else. Change-Id: I71968d252e04651d7b597034fa17273e9749d0b0
This commit is contained in:
@@ -74,13 +74,14 @@ public class IdentifiedUser extends CurrentUser {
|
||||
private final GroupBackend groupBackend;
|
||||
|
||||
@Inject
|
||||
GenericFactory(
|
||||
CapabilityControl.Factory capabilityControlFactory,
|
||||
final AuthConfig authConfig,
|
||||
final @AnonymousCowardName String anonymousCowardName,
|
||||
final @CanonicalWebUrl Provider<String> canonicalUrl,
|
||||
final Realm realm, final AccountCache accountCache,
|
||||
final GroupBackend groupBackend) {
|
||||
public GenericFactory(
|
||||
@Nullable CapabilityControl.Factory capabilityControlFactory,
|
||||
AuthConfig authConfig,
|
||||
@AnonymousCowardName String anonymousCowardName,
|
||||
@CanonicalWebUrl Provider<String> canonicalUrl,
|
||||
Realm realm,
|
||||
AccountCache accountCache,
|
||||
GroupBackend groupBackend) {
|
||||
this.capabilityControlFactory = capabilityControlFactory;
|
||||
this.authConfig = authConfig;
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
|
||||
@@ -49,19 +49,24 @@ public class MetaDataUpdate {
|
||||
}
|
||||
|
||||
public PersonIdent getUserPersonIdent() {
|
||||
return createPersonIdent();
|
||||
return createPersonIdent(identifiedUser.get());
|
||||
}
|
||||
|
||||
public MetaDataUpdate create(Project.NameKey name)
|
||||
throws RepositoryNotFoundException, IOException {
|
||||
return create(name, identifiedUser.get());
|
||||
}
|
||||
|
||||
public MetaDataUpdate create(Project.NameKey name, IdentifiedUser user)
|
||||
throws RepositoryNotFoundException, IOException {
|
||||
MetaDataUpdate md = factory.create(name, mgr.openRepository(name));
|
||||
md.getCommitBuilder().setAuthor(createPersonIdent());
|
||||
md.getCommitBuilder().setAuthor(createPersonIdent(user));
|
||||
md.getCommitBuilder().setCommitter(serverIdent);
|
||||
return md;
|
||||
}
|
||||
|
||||
private PersonIdent createPersonIdent() {
|
||||
return identifiedUser.get().newCommitterIdent(
|
||||
private PersonIdent createPersonIdent(IdentifiedUser user) {
|
||||
return user.newCommitterIdent(
|
||||
serverIdent.getWhen(), serverIdent.getTimeZone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.GERRIT_PLACEHOLDER_
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.common.data.LabelType;
|
||||
import com.google.gerrit.common.data.LabelTypes;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
@@ -36,9 +35,8 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.VersionedMetaData;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.util.LabelVote;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.CommitBuilder;
|
||||
@@ -63,41 +61,10 @@ import java.util.TimeZone;
|
||||
* This class is not thread-safe.
|
||||
*/
|
||||
public class ChangeUpdate extends VersionedMetaData {
|
||||
@Singleton
|
||||
public static class Factory {
|
||||
private final GitRepositoryManager repoManager;
|
||||
private final AccountCache accountCache;
|
||||
private final MetaDataUpdate.User updateFactory;
|
||||
private final ProjectCache projectCache;
|
||||
private final Provider<IdentifiedUser> user;
|
||||
private final PersonIdent serverIdent;
|
||||
|
||||
@Inject
|
||||
Factory(
|
||||
GitRepositoryManager repoManager,
|
||||
AccountCache accountCache,
|
||||
MetaDataUpdate.User updateFactory,
|
||||
ProjectCache projectCache,
|
||||
Provider<IdentifiedUser> user,
|
||||
@GerritPersonIdent PersonIdent serverIdent) {
|
||||
this.repoManager = repoManager;
|
||||
this.accountCache = accountCache;
|
||||
this.updateFactory = updateFactory;
|
||||
this.projectCache = projectCache;
|
||||
this.user = user;
|
||||
this.serverIdent = serverIdent;
|
||||
}
|
||||
|
||||
public ChangeUpdate create(Change change) {
|
||||
return create(change, serverIdent.getWhen());
|
||||
}
|
||||
|
||||
public ChangeUpdate create(Change change, Date when) {
|
||||
return new ChangeUpdate(
|
||||
repoManager, accountCache, updateFactory,
|
||||
projectCache.get(change.getProject()).getLabelTypes(),
|
||||
change, user.get().getAccount(), when, serverIdent.getTimeZone());
|
||||
}
|
||||
public interface Factory {
|
||||
ChangeUpdate create(Change change);
|
||||
ChangeUpdate create(Change change, Date when);
|
||||
ChangeUpdate create(Change change, Date when, IdentifiedUser user);
|
||||
}
|
||||
|
||||
private final GitRepositoryManager repoManager;
|
||||
@@ -105,7 +72,7 @@ public class ChangeUpdate extends VersionedMetaData {
|
||||
private final MetaDataUpdate.User updateFactory;
|
||||
private final LabelTypes labelTypes;
|
||||
private final Change change;
|
||||
private final Account account;
|
||||
private final IdentifiedUser user;
|
||||
private final Date when;
|
||||
private final TimeZone tz;
|
||||
private final Map<String, Short> approvals;
|
||||
@@ -113,32 +80,72 @@ public class ChangeUpdate extends VersionedMetaData {
|
||||
private String subject;
|
||||
private PatchSet.Id psId;
|
||||
|
||||
@VisibleForTesting
|
||||
ChangeUpdate(GitRepositoryManager repoManager, AccountCache accountCache,
|
||||
LabelTypes labelTypes, Change change, Account account, Date when,
|
||||
TimeZone tz) {
|
||||
this(repoManager, accountCache, null, labelTypes, change, account, when,
|
||||
tz);
|
||||
@AssistedInject
|
||||
ChangeUpdate(
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
GitRepositoryManager repoManager,
|
||||
AccountCache accountCache,
|
||||
MetaDataUpdate.User updateFactory,
|
||||
ProjectCache projectCache,
|
||||
IdentifiedUser user,
|
||||
@Assisted Change change) {
|
||||
this(serverIdent, repoManager, accountCache, updateFactory, projectCache,
|
||||
user, change, serverIdent.getWhen());
|
||||
}
|
||||
|
||||
private ChangeUpdate(GitRepositoryManager repoManager,
|
||||
AccountCache accountCache, @Nullable MetaDataUpdate.User updateFactory,
|
||||
LabelTypes labelTypes, Change change, Account account, Date when,
|
||||
TimeZone tz) {
|
||||
@AssistedInject
|
||||
ChangeUpdate(
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
GitRepositoryManager repoManager,
|
||||
AccountCache accountCache,
|
||||
MetaDataUpdate.User updateFactory,
|
||||
ProjectCache projectCache,
|
||||
IdentifiedUser user,
|
||||
@Assisted Change change,
|
||||
@Assisted Date when) {
|
||||
this(serverIdent, repoManager, accountCache, updateFactory, projectCache,
|
||||
change, when, user);
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
ChangeUpdate(
|
||||
@GerritPersonIdent PersonIdent serverIdent,
|
||||
GitRepositoryManager repoManager,
|
||||
AccountCache accountCache,
|
||||
MetaDataUpdate.User updateFactory,
|
||||
ProjectCache projectCache,
|
||||
@Assisted Change change,
|
||||
@Assisted Date when,
|
||||
@Assisted IdentifiedUser user) {
|
||||
this(serverIdent, repoManager, accountCache, updateFactory,
|
||||
projectCache.get(change.getDest().getParentKey()).getLabelTypes(),
|
||||
change, when, user);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ChangeUpdate(
|
||||
PersonIdent serverIdent,
|
||||
GitRepositoryManager repoManager,
|
||||
AccountCache accountCache,
|
||||
MetaDataUpdate.User updateFactory,
|
||||
LabelTypes labelTypes,
|
||||
Change change,
|
||||
Date when,
|
||||
IdentifiedUser user) {
|
||||
this.repoManager = repoManager;
|
||||
this.accountCache = accountCache;
|
||||
this.updateFactory = updateFactory;
|
||||
this.labelTypes = labelTypes;
|
||||
this.change = change;
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
this.when = when;
|
||||
this.tz = tz;
|
||||
this.tz = serverIdent.getTimeZone();
|
||||
this.approvals = Maps.newTreeMap(labelTypes.nameComparator());
|
||||
this.reviewers = Maps.newLinkedHashMap();
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
public IdentifiedUser getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Date getWhen() {
|
||||
@@ -169,7 +176,7 @@ public class ChangeUpdate extends VersionedMetaData {
|
||||
|
||||
public RevCommit commit() throws IOException {
|
||||
return commit(checkNotNull(updateFactory, "MetaDataUpdate.Factory")
|
||||
.create(change.getProject()));
|
||||
.create(change.getProject(), user));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,7 +204,7 @@ public class ChangeUpdate extends VersionedMetaData {
|
||||
}
|
||||
|
||||
public PersonIdent newCommitter() {
|
||||
return newIdent(account);
|
||||
return newIdent(user.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
|
||||
package com.google.gerrit.server.notedb;
|
||||
|
||||
import static com.google.gerrit.server.notedb.ReviewerState.CC;
|
||||
import static com.google.gerrit.server.notedb.ReviewerState.REVIEWER;
|
||||
import static com.google.gerrit.server.project.Util.category;
|
||||
import static com.google.gerrit.server.project.Util.value;
|
||||
import static com.google.inject.Scopes.SINGLETON;
|
||||
import static java.util.concurrent.TimeUnit.DAYS;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
@@ -35,15 +38,31 @@ import com.google.gerrit.reviewdb.client.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.client.PatchSetInfo;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.CapabilityControl;
|
||||
import com.google.gerrit.server.account.GroupBackend;
|
||||
import com.google.gerrit.server.account.Realm;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.AnonymousCowardNameProvider;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.extensions.events.GitReferenceUpdated;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.util.TimeUtil;
|
||||
import com.google.gerrit.testutil.FakeAccountCache;
|
||||
import com.google.gerrit.testutil.FakeRealm;
|
||||
import com.google.gerrit.testutil.InMemoryRepositoryManager;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.revwalk.RevWalk;
|
||||
@@ -64,16 +83,8 @@ public class ChangeNotesTest {
|
||||
private static final TimeZone TZ =
|
||||
TimeZone.getTimeZone("America/Los_Angeles");
|
||||
|
||||
private static final Account CHANGE_OWNER;
|
||||
private static final Account OTHER_ACCOUNT;
|
||||
static {
|
||||
CHANGE_OWNER = new Account(new Account.Id(1), TimeUtil.nowTs());
|
||||
CHANGE_OWNER.setFullName("Change Owner");
|
||||
CHANGE_OWNER.setPreferredEmail("change@owner.com");
|
||||
OTHER_ACCOUNT = new Account(new Account.Id(2), TimeUtil.nowTs());
|
||||
OTHER_ACCOUNT.setFullName("Other Account");
|
||||
OTHER_ACCOUNT.setPreferredEmail("other@account.com");
|
||||
}
|
||||
private static final PersonIdent SERVER_IDENT =
|
||||
new PersonIdent("Gerrit Server", "noreply@gerrit.com", new Date(), TZ);
|
||||
|
||||
private static final LabelTypes LABEL_TYPES = new LabelTypes(ImmutableList.of(
|
||||
category("Verified",
|
||||
@@ -89,6 +100,8 @@ public class ChangeNotesTest {
|
||||
private InMemoryRepositoryManager repoManager;
|
||||
private InMemoryRepository repo;
|
||||
private FakeAccountCache accountCache;
|
||||
private IdentifiedUser changeOwner;
|
||||
private IdentifiedUser otherUser;
|
||||
private volatile long clockStepMs;
|
||||
|
||||
@Before
|
||||
@@ -97,8 +110,36 @@ public class ChangeNotesTest {
|
||||
repoManager = new InMemoryRepositoryManager();
|
||||
repo = repoManager.createRepository(project);
|
||||
accountCache = new FakeAccountCache();
|
||||
accountCache.put(CHANGE_OWNER);
|
||||
accountCache.put(OTHER_ACCOUNT);
|
||||
Account co = new Account(new Account.Id(1), TimeUtil.nowTs());
|
||||
co.setFullName("Change Owner");
|
||||
co.setPreferredEmail("change@owner.com");
|
||||
accountCache.put(co);
|
||||
Account ou = new Account(new Account.Id(2), TimeUtil.nowTs());
|
||||
ou.setFullName("Other Account");
|
||||
ou.setPreferredEmail("other@account.com");
|
||||
accountCache.put(ou);
|
||||
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
bind(CapabilityControl.Factory.class)
|
||||
.toProvider(Providers.<CapabilityControl.Factory> of(null));
|
||||
bind(Config.class).annotatedWith(GerritServerConfig.class)
|
||||
.toInstance(new Config());
|
||||
bind(String.class).annotatedWith(AnonymousCowardName.class)
|
||||
.toProvider(AnonymousCowardNameProvider.class);
|
||||
bind(String.class).annotatedWith(CanonicalWebUrl.class)
|
||||
.toInstance("http://localhost:8080/");
|
||||
bind(Realm.class).to(FakeRealm.class);
|
||||
bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
|
||||
bind(AccountCache.class).toInstance(accountCache);
|
||||
}
|
||||
});
|
||||
|
||||
IdentifiedUser.GenericFactory userFactory =
|
||||
injector.getInstance(IdentifiedUser.GenericFactory.class);
|
||||
changeOwner = userFactory.create(co.getId());
|
||||
otherUser = userFactory.create(ou.getId());
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -124,11 +165,11 @@ public class ChangeNotesTest {
|
||||
@Test
|
||||
public void approvalsCommitFormat() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) -1);
|
||||
update.putApproval("Verified", (short) 1);
|
||||
update.putReviewer(CHANGE_OWNER.getId(), ReviewerState.REVIEWER);
|
||||
update.putReviewer(OTHER_ACCOUNT.getId(), ReviewerState.CC);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().getId(), CC);
|
||||
commit(update);
|
||||
assertEquals("refs/changes/01/1/meta", update.getRefName());
|
||||
|
||||
@@ -165,12 +206,12 @@ public class ChangeNotesTest {
|
||||
@Test
|
||||
public void approvalsOnePatchSet() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) -1);
|
||||
update.putApproval("Verified", (short) 1);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
assertEquals(1, notes.getApprovals().keySet().size());
|
||||
List<PatchSetApproval> psas =
|
||||
notes.getApprovals().get(c.currentPatchSetId());
|
||||
@@ -192,18 +233,18 @@ public class ChangeNotesTest {
|
||||
@Test
|
||||
public void approvalsMultiplePatchSets() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) -1);
|
||||
commit(update);
|
||||
PatchSet.Id ps1 = c.currentPatchSetId();
|
||||
|
||||
incrementPatchSet(c);
|
||||
update = newUpdate(c, CHANGE_OWNER);
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) 1);
|
||||
commit(update);
|
||||
PatchSet.Id ps2 = c.currentPatchSetId();
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
ListMultimap<PatchSet.Id, PatchSetApproval> psas = notes.getApprovals();
|
||||
assertEquals(2, notes.getApprovals().keySet().size());
|
||||
|
||||
@@ -225,21 +266,21 @@ public class ChangeNotesTest {
|
||||
@Test
|
||||
public void approvalsMultipleApprovals() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) -1);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
PatchSetApproval psa = Iterables.getOnlyElement(
|
||||
notes.getApprovals().get(c.currentPatchSetId()));
|
||||
assertEquals("Code-Review", psa.getLabel());
|
||||
assertEquals((short) -1, psa.getValue());
|
||||
|
||||
update = newUpdate(c, CHANGE_OWNER);
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) 1);
|
||||
commit(update);
|
||||
|
||||
notes = newNotes(c);
|
||||
notes = newChange(c);
|
||||
psa = Iterables.getOnlyElement(
|
||||
notes.getApprovals().get(c.currentPatchSetId()));
|
||||
assertEquals("Code-Review", psa.getLabel());
|
||||
@@ -249,15 +290,15 @@ public class ChangeNotesTest {
|
||||
@Test
|
||||
public void approvalsMultipleUsers() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) -1);
|
||||
commit(update);
|
||||
|
||||
update = newUpdate(c, OTHER_ACCOUNT);
|
||||
update = newUpdate(c, otherUser);
|
||||
update.putApproval("Code-Review", (short) 1);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
assertEquals(1, notes.getApprovals().keySet().size());
|
||||
List<PatchSetApproval> psas =
|
||||
notes.getApprovals().get(c.currentPatchSetId());
|
||||
@@ -279,85 +320,85 @@ public class ChangeNotesTest {
|
||||
@Test
|
||||
public void multipleReviewers() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
update.putReviewer(CHANGE_OWNER.getId(), ReviewerState.REVIEWER);
|
||||
update.putReviewer(OTHER_ACCOUNT.getId(), ReviewerState.REVIEWER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
assertEquals(ImmutableSetMultimap.of(
|
||||
ReviewerState.REVIEWER, new Account.Id(1),
|
||||
ReviewerState.REVIEWER, new Account.Id(2)),
|
||||
REVIEWER, new Account.Id(1),
|
||||
REVIEWER, new Account.Id(2)),
|
||||
notes.getReviewers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reviewerTypes() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
update.putReviewer(CHANGE_OWNER.getId(), ReviewerState.REVIEWER);
|
||||
update.putReviewer(OTHER_ACCOUNT.getId(), ReviewerState.CC);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
|
||||
update.putReviewer(otherUser.getAccount().getId(), CC);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
assertEquals(ImmutableSetMultimap.of(
|
||||
ReviewerState.REVIEWER, new Account.Id(1),
|
||||
ReviewerState.CC, new Account.Id(2)),
|
||||
REVIEWER, new Account.Id(1),
|
||||
CC, new Account.Id(2)),
|
||||
notes.getReviewers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oneReviewerMultipleTypes() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
update.putReviewer(OTHER_ACCOUNT.getId(), ReviewerState.REVIEWER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
assertEquals(ImmutableSetMultimap.of(
|
||||
ReviewerState.REVIEWER, new Account.Id(2)),
|
||||
REVIEWER, new Account.Id(2)),
|
||||
notes.getReviewers());
|
||||
|
||||
update = newUpdate(c, OTHER_ACCOUNT);
|
||||
update.putReviewer(OTHER_ACCOUNT.getId(), ReviewerState.CC);
|
||||
update = newUpdate(c, otherUser);
|
||||
update.putReviewer(otherUser.getAccount().getId(), CC);
|
||||
commit(update);
|
||||
|
||||
notes = newNotes(c);
|
||||
notes = newChange(c);
|
||||
assertEquals(ImmutableSetMultimap.of(
|
||||
ReviewerState.CC, new Account.Id(2)),
|
||||
CC, new Account.Id(2)),
|
||||
notes.getReviewers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeReviewer() throws Exception {
|
||||
Change c = newChange();
|
||||
ChangeUpdate update = newUpdate(c, CHANGE_OWNER);
|
||||
update.putReviewer(OTHER_ACCOUNT.getId(), ReviewerState.REVIEWER);
|
||||
ChangeUpdate update = newUpdate(c, changeOwner);
|
||||
update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
|
||||
commit(update);
|
||||
|
||||
update = newUpdate(c, CHANGE_OWNER);
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.putApproval("Code-Review", (short) 1);
|
||||
commit(update);
|
||||
|
||||
update = newUpdate(c, OTHER_ACCOUNT);
|
||||
update = newUpdate(c, otherUser);
|
||||
update.putApproval("Code-Review", (short) 1);
|
||||
commit(update);
|
||||
|
||||
ChangeNotes notes = newNotes(c);
|
||||
ChangeNotes notes = newChange(c);
|
||||
List<PatchSetApproval> psas =
|
||||
notes.getApprovals().get(c.currentPatchSetId());
|
||||
assertEquals(2, psas.size());
|
||||
assertEquals(CHANGE_OWNER.getId(), psas.get(0).getAccountId());
|
||||
assertEquals(OTHER_ACCOUNT.getId(), psas.get(1).getAccountId());
|
||||
assertEquals(changeOwner.getAccount().getId(), psas.get(0).getAccountId());
|
||||
assertEquals(otherUser.getAccount().getId(), psas.get(1).getAccountId());
|
||||
|
||||
update = newUpdate(c, CHANGE_OWNER);
|
||||
update.removeReviewer(OTHER_ACCOUNT.getId());
|
||||
update = newUpdate(c, changeOwner);
|
||||
update.removeReviewer(otherUser.getAccount().getId());
|
||||
commit(update);
|
||||
|
||||
notes = newNotes(c);
|
||||
notes = newChange(c);
|
||||
psas = notes.getApprovals().get(c.currentPatchSetId());
|
||||
assertEquals(1, psas.size());
|
||||
assertEquals(CHANGE_OWNER.getId(), psas.get(0).getAccountId());
|
||||
assertEquals(changeOwner.getAccount().getId(), psas.get(0).getAccountId());
|
||||
}
|
||||
|
||||
private Change newChange() {
|
||||
@@ -365,20 +406,20 @@ public class ChangeNotesTest {
|
||||
Change c = new Change(
|
||||
new Change.Key("Iabcd1234abcd1234abcd1234abcd1234abcd1234"),
|
||||
changeId,
|
||||
CHANGE_OWNER.getId(),
|
||||
changeOwner.getAccount().getId(),
|
||||
new Branch.NameKey(project, "master"),
|
||||
TimeUtil.nowTs());
|
||||
incrementPatchSet(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
private ChangeUpdate newUpdate(Change c, Account account)
|
||||
private ChangeUpdate newUpdate(Change c, IdentifiedUser user)
|
||||
throws ConfigInvalidException, IOException {
|
||||
return new ChangeUpdate(repoManager, accountCache, LABEL_TYPES, c, account,
|
||||
TimeUtil.nowTs(), TZ);
|
||||
return new ChangeUpdate(SERVER_IDENT, repoManager, accountCache, null,
|
||||
LABEL_TYPES, c, TimeUtil.nowTs(), user);
|
||||
}
|
||||
|
||||
private ChangeNotes newNotes(Change c) throws OrmException {
|
||||
private ChangeNotes newChange(Change c) throws OrmException {
|
||||
return new ChangeNotes(repoManager, c).load();
|
||||
}
|
||||
|
||||
@@ -401,10 +442,8 @@ public class ChangeNotesTest {
|
||||
private RevCommit commit(ChangeUpdate update) throws IOException {
|
||||
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED,
|
||||
project, repo);
|
||||
md.getCommitBuilder().setAuthor(new PersonIdent(
|
||||
update.getAccount().getFullName(),
|
||||
update.getAccount().getPreferredEmail(),
|
||||
update.getWhen(), TZ));
|
||||
md.getCommitBuilder().setAuthor(
|
||||
update.getUser().newCommitterIdent(update.getWhen(), TZ));
|
||||
return update.commit(md);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2014 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.testutil;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Account.FieldName;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AuthRequest;
|
||||
import com.google.gerrit.server.account.Realm;
|
||||
|
||||
/** Fake implementation of {@link Realm} for testing. */
|
||||
public class FakeRealm implements Realm {
|
||||
@Override
|
||||
public boolean allowsEdit(FieldName field) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthRequest authenticate(AuthRequest who) {
|
||||
return who;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthRequest link(ReviewDb db, Account.Id to, AuthRequest who) {
|
||||
return who;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthRequest unlink(ReviewDb db, Account.Id to, AuthRequest who) {
|
||||
return who;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateAccount(AuthRequest who, Account account) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account.Id lookup(String accountName) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user