Allow admins to toggle the WIP flag on all changes
Sometimes this can be useful, e.g. if one developers starts a WIP change, goes to vacation and another developer makes the change ready. At the moment the WIP flag cannot be removed by anyone else than the change owner. Change-Id: I4878f066b633b349dbfe927480ebb143539bf4d3 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -24,9 +24,13 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.WorkInProgressOp;
|
||||
import com.google.gerrit.server.change.WorkInProgressOp.Input;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.RetryHelper;
|
||||
import com.google.gerrit.server.update.RetryingRestModifyView;
|
||||
@@ -40,21 +44,30 @@ public class SetReadyForReview extends RetryingRestModifyView<ChangeResource, In
|
||||
implements UiAction<ChangeResource> {
|
||||
private final WorkInProgressOp.Factory opFactory;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<CurrentUser> self;
|
||||
private final PermissionBackend permissionBackend;
|
||||
|
||||
@Inject
|
||||
SetReadyForReview(
|
||||
RetryHelper retryHelper, WorkInProgressOp.Factory opFactory, Provider<ReviewDb> db) {
|
||||
RetryHelper retryHelper,
|
||||
WorkInProgressOp.Factory opFactory,
|
||||
Provider<ReviewDb> db,
|
||||
Provider<CurrentUser> self,
|
||||
PermissionBackend permissionBackend) {
|
||||
super(retryHelper);
|
||||
this.opFactory = opFactory;
|
||||
this.db = db;
|
||||
this.self = self;
|
||||
this.permissionBackend = permissionBackend;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response<?> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input)
|
||||
throws RestApiException, UpdateException {
|
||||
throws RestApiException, UpdateException, PermissionBackendException {
|
||||
Change change = rsrc.getChange();
|
||||
if (!rsrc.isUserOwner()) {
|
||||
if (!rsrc.isUserOwner()
|
||||
&& !permissionBackend.user(self).test(GlobalPermission.ADMINISTRATE_SERVER)) {
|
||||
throw new AuthException("not allowed to set ready for review");
|
||||
}
|
||||
|
||||
|
@@ -24,9 +24,13 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.ChangeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.WorkInProgressOp;
|
||||
import com.google.gerrit.server.change.WorkInProgressOp.Input;
|
||||
import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.RetryHelper;
|
||||
import com.google.gerrit.server.update.RetryingRestModifyView;
|
||||
@@ -40,21 +44,31 @@ public class SetWorkInProgress extends RetryingRestModifyView<ChangeResource, In
|
||||
implements UiAction<ChangeResource> {
|
||||
private final WorkInProgressOp.Factory opFactory;
|
||||
private final Provider<ReviewDb> db;
|
||||
private final Provider<CurrentUser> self;
|
||||
private final PermissionBackend permissionBackend;
|
||||
|
||||
@Inject
|
||||
SetWorkInProgress(
|
||||
WorkInProgressOp.Factory opFactory, RetryHelper retryHelper, Provider<ReviewDb> db) {
|
||||
WorkInProgressOp.Factory opFactory,
|
||||
RetryHelper retryHelper,
|
||||
Provider<ReviewDb> db,
|
||||
Provider<CurrentUser> self,
|
||||
PermissionBackend permissionBackend) {
|
||||
super(retryHelper);
|
||||
this.opFactory = opFactory;
|
||||
this.db = db;
|
||||
this.self = self;
|
||||
this.permissionBackend = permissionBackend;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response<?> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input)
|
||||
throws RestApiException, UpdateException {
|
||||
throws RestApiException, UpdateException, PermissionBackendException {
|
||||
Change change = rsrc.getChange();
|
||||
if (!rsrc.isUserOwner()) {
|
||||
|
||||
if (!rsrc.isUserOwner()
|
||||
&& !permissionBackend.user(self).test(GlobalPermission.ADMINISTRATE_SERVER)) {
|
||||
throw new AuthException("not allowed to set work in progress");
|
||||
}
|
||||
|
||||
|
@@ -417,6 +417,17 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
gApi.changes().id(changeId).setWorkInProgress();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setWorkInProgressAllowedAsAdmin() throws Exception {
|
||||
setApiUser(user);
|
||||
String changeId =
|
||||
gApi.changes().create(new ChangeInput(project.get(), "master", "Test Change")).get().id;
|
||||
|
||||
setApiUser(admin);
|
||||
gApi.changes().id(changeId).setWorkInProgress();
|
||||
assertThat(gApi.changes().id(changeId).get().workInProgress).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setReadyForReviewNotAllowedWithoutPermission() throws Exception {
|
||||
PushOneCommit.Result rready = createChange();
|
||||
@@ -429,6 +440,18 @@ public class ChangeIT extends AbstractDaemonTest {
|
||||
gApi.changes().id(changeId).setReadyForReview();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setReadyForReviewAllowedAsAdmin() throws Exception {
|
||||
setApiUser(user);
|
||||
String changeId =
|
||||
gApi.changes().create(new ChangeInput(project.get(), "master", "Test Change")).get().id;
|
||||
gApi.changes().id(changeId).setWorkInProgress();
|
||||
|
||||
setApiUser(admin);
|
||||
gApi.changes().id(changeId).setReadyForReview();
|
||||
assertThat(gApi.changes().id(changeId).get().workInProgress).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasReviewStarted() throws Exception {
|
||||
PushOneCommit.Result r = createWorkInProgressChange();
|
||||
|
Reference in New Issue
Block a user