Check canEditHashtags with PermissionBackend
Change-Id: Ief5473171d8e754b6d17104213d1613e4c974f8c
This commit is contained in:
committed by
David Pursehouse
parent
6b9563f3ce
commit
e92ad1112e
@@ -476,7 +476,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
public void setHashtags(HashtagsInput input) throws RestApiException {
|
||||
try {
|
||||
postHashtags.apply(change, input);
|
||||
} catch (UpdateException e) {
|
||||
} catch (UpdateException | PermissionBackendException e) {
|
||||
throw new RestApiException("Cannot post hashtags", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.extensions.webui.UiAction;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.permissions.ChangePermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.update.BatchUpdate;
|
||||
import com.google.gerrit.server.update.UpdateException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -47,7 +49,9 @@ public class PostHashtags
|
||||
|
||||
@Override
|
||||
public Response<ImmutableSortedSet<String>> apply(ChangeResource req, HashtagsInput input)
|
||||
throws RestApiException, UpdateException {
|
||||
throws RestApiException, UpdateException, PermissionBackendException {
|
||||
req.permissions().check(ChangePermission.EDIT_HASHTAGS);
|
||||
|
||||
try (BatchUpdate bu =
|
||||
batchUpdateFactory.create(
|
||||
db.get(), req.getChange().getProject(), req.getControl().getUser(), TimeUtil.nowTs())) {
|
||||
@@ -59,9 +63,9 @@ public class PostHashtags
|
||||
}
|
||||
|
||||
@Override
|
||||
public UiAction.Description getDescription(ChangeResource resource) {
|
||||
public UiAction.Description getDescription(ChangeResource rsrc) {
|
||||
return new UiAction.Description()
|
||||
.setLabel("Edit Hashtags")
|
||||
.setVisible(resource.getControl().canEditHashtags());
|
||||
.setVisible(rsrc.permissions().testOrFalse(ChangePermission.EDIT_HASHTAGS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +94,7 @@ public class SetHashtagsOp implements BatchUpdateOp {
|
||||
updatedHashtags = ImmutableSortedSet.of();
|
||||
return false;
|
||||
}
|
||||
if (!ctx.getControl().canEditHashtags()) {
|
||||
throw new AuthException("Editing hashtags not permitted");
|
||||
}
|
||||
|
||||
change = ctx.getChange();
|
||||
ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId());
|
||||
ChangeNotes notes = update.getNotes().load();
|
||||
|
||||
@@ -2197,6 +2197,7 @@ public class ReceiveCommits {
|
||||
.setUpdateRef(false)
|
||||
.setPatchSetDescription(magicBranch.message));
|
||||
if (!magicBranch.hashtags.isEmpty()) {
|
||||
// Any change owner is allowed to add hashtags when creating a change.
|
||||
bu.addOp(
|
||||
changeId,
|
||||
hashtagsFactory.create(new HashtagsInput(magicBranch.hashtags)).setFireEvent(false));
|
||||
|
||||
@@ -464,7 +464,7 @@ public class ChangeControl {
|
||||
}
|
||||
|
||||
/** Can this user edit the hashtag name? */
|
||||
public boolean canEditHashtags() {
|
||||
private boolean canEditHashtags() {
|
||||
return isOwner() // owner (aka creator) of the change can edit hashtags
|
||||
|| getRefControl().isOwner() // branch owner can edit hashtags
|
||||
|| getProjectControl().isOwner() // project owner can edit hashtags
|
||||
|
||||
@@ -447,7 +447,7 @@ public class RefControl {
|
||||
}
|
||||
|
||||
/** @return true if this user can edit hashtag names. */
|
||||
public boolean canEditHashtags() {
|
||||
boolean canEditHashtags() {
|
||||
return canPerform(Permission.EDIT_HASHTAGS);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user