Check canEditDescription with PermissionBackend

Change-Id: I28a0727ecde5b418e9996bb78858a1b18e96b8a4
This commit is contained in:
Shawn Pearce
2017-02-18 16:19:29 -08:00
committed by David Pursehouse
parent 46d61b3f2c
commit df11d43964
4 changed files with 9 additions and 9 deletions

View File

@@ -771,7 +771,7 @@ public class RevisionIT extends AbstractDaemonTest {
assertDescription(r, "");
setApiUser(user);
exception.expect(AuthException.class);
exception.expectMessage("changing description not permitted");
exception.expectMessage("edit description not permitted");
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).description("test");
}

View File

@@ -545,7 +545,7 @@ class RevisionApiImpl implements RevisionApi {
in.description = description;
try {
putDescription.apply(revision, in);
} catch (UpdateException e) {
} catch (UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot set description", e);
}
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.change;
import com.google.common.base.Strings;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.DefaultInput;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -28,6 +27,8 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.PatchSetUtil;
import com.google.gerrit.server.notedb.ChangeUpdate;
import com.google.gerrit.server.permissions.ChangePermission;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdateOp;
@@ -65,11 +66,10 @@ public class PutDescription
@Override
public Response<String> apply(RevisionResource rsrc, Input input)
throws UpdateException, RestApiException {
throws UpdateException, RestApiException, PermissionBackendException {
rsrc.permissions().check(ChangePermission.EDIT_DESCRIPTION);
ChangeControl ctl = rsrc.getControl();
if (!ctl.canEditDescription()) {
throw new AuthException("changing description not permitted");
}
Op op = new Op(input != null ? input : new Input(), rsrc.getPatchSet().getId());
try (BatchUpdate u =
batchUpdateFactory.create(
@@ -129,6 +129,6 @@ public class PutDescription
public UiAction.Description getDescription(RevisionResource rsrc) {
return new UiAction.Description()
.setLabel("Edit Description")
.setVisible(rsrc.getControl().canEditDescription());
.setVisible(rsrc.permissions().testOrFalse(ChangePermission.EDIT_DESCRIPTION));
}
}

View File

@@ -445,7 +445,7 @@ public class ChangeControl {
}
/** Can this user edit the description? */
public boolean canEditDescription() {
private boolean canEditDescription() {
if (getChange().getStatus().isOpen()) {
return isOwner() // owner (aka creator) of the change can edit desc
|| getRefControl().isOwner() // branch owner can edit desc