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