Port AddReviewer to new REST API

Reviewers can now be added by a POST to /changes/*/reviewers with body
containing the reviewer string to search for.

The new code closely parallels the old but is simplified where
possible. The new handler only supports putting a single reviewer,
which is all the old handler was ever used for. Error handling is also
simplified, using server-supplied error text.

The response body includes a list "reviewers" of reviewers that were
newly added (which may be empty if), or an "error" string and optional
"confirm" boolean. If "confirm" is true, the error text describes why
confirmation is required, and redoing the POST with "confirmed": true in
the JSON body indicates confirmation.

Change-Id: If3d72bc1d3be7f6b96bfae7819d8b4b575104eaa
This commit is contained in:
Dave Borowitz
2013-02-12 12:10:26 -08:00
committed by Edwin Kempin
parent d386499438
commit 675879a733
10 changed files with 405 additions and 51 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.change;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.project.ChangeControl;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -27,7 +28,7 @@ public class ReviewerResource extends ChangeResource {
static interface Factory {
ReviewerResource create(ChangeResource rsrc, IdentifiedUser user);
ReviewerResource create(ChangeResource rsrc, Account account);
ReviewerResource create(ChangeResource rsrc, Account.Id id);
}
private final IdentifiedUser user;
@@ -42,11 +43,19 @@ public class ReviewerResource extends ChangeResource {
@AssistedInject
ReviewerResource(IdentifiedUser.GenericFactory userFactory,
@Assisted ChangeResource rsrc,
@Assisted Account account) {
this(rsrc, userFactory.create(account.getId()));
@Assisted Account.Id id) {
this(rsrc, userFactory.create(id));
}
public IdentifiedUser getUser() {
return user;
}
/**
* @return the control for the reviewer's user (as opposed to the caller's
* user as returned by {@link #getControl()}).
*/
public ChangeControl getUserControl() {
return getControl().forUser(user);
}
}