use of com.google.gerrit.extensions.api.changes.DeleteCommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method deletePatchsetLevelComment.
@Test
public void deletePatchsetLevelComment() throws Exception {
requestScopeOperations.setApiUser(admin.id());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String commentMessage = "to be deleted";
CommentInput comment = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, commentMessage);
CommentsUtil.addComments(gApi, changeId, revId, comment);
Map<String, List<CommentInfo>> results = getPublishedComments(changeId, revId);
CommentInfo oldComment = Iterables.getOnlyElement(results.get(PATCHSET_LEVEL));
DeleteCommentInput input = new DeleteCommentInput("reason");
gApi.changes().id(changeId).revision(revId).comment(oldComment.id).delete(input);
CommentInfo updatedComment = Iterables.getOnlyElement(getPublishedComments(changeId, revId).get(PATCHSET_LEVEL));
assertThat(updatedComment.message).doesNotContain(commentMessage);
}
use of com.google.gerrit.extensions.api.changes.DeleteCommentInput in project gerrit by GerritCodeReview.
the class DeleteComment method apply.
@Override
public Response<CommentInfo> apply(HumanCommentResource rsrc, DeleteCommentInput input) throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException, UpdateException {
CurrentUser user = userProvider.get();
permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
if (input == null) {
input = new DeleteCommentInput();
}
String newMessage = getCommentNewMessage(user.asIdentifiedUser().getName(), input.reason);
DeleteCommentOp deleteCommentOp = new DeleteCommentOp(rsrc, newMessage);
try (BatchUpdate batchUpdate = updateFactory.create(rsrc.getRevisionResource().getProject(), user, TimeUtil.now())) {
batchUpdate.addOp(rsrc.getRevisionResource().getChange().getId(), deleteCommentOp).execute();
}
ChangeNotes updatedNotes = notesFactory.createChecked(rsrc.getRevisionResource().getProject(), rsrc.getRevisionResource().getChangeResource().getId());
List<HumanComment> changeComments = commentsUtil.publishedHumanCommentsByChange(updatedNotes);
Optional<HumanComment> updatedComment = changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst();
if (!updatedComment.isPresent()) {
// This should not happen as this endpoint should not remove the whole comment.
throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
}
return Response.ok(commentJson.get().newHumanCommentFormatter().format(updatedComment.get()));
}
use of com.google.gerrit.extensions.api.changes.DeleteCommentInput in project gerrit by GerritCodeReview.
the class DeleteComment method applyImpl.
@Override
public CommentInfo applyImpl(BatchUpdate.Factory batchUpdateFactory, CommentResource rsrc, DeleteCommentInput input) throws RestApiException, IOException, ConfigInvalidException, OrmException, PermissionBackendException, UpdateException {
CurrentUser user = userProvider.get();
permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
String newMessage = getCommentNewMessage(user.asIdentifiedUser().getName(), input.reason);
DeleteCommentOp deleteCommentOp = new DeleteCommentOp(rsrc, newMessage);
try (BatchUpdate batchUpdate = batchUpdateFactory.create(dbProvider.get(), rsrc.getRevisionResource().getProject(), user, TimeUtil.nowTs())) {
batchUpdate.addOp(rsrc.getRevisionResource().getChange().getId(), deleteCommentOp).execute();
}
ChangeNotes updatedNotes = notesFactory.createChecked(rsrc.getRevisionResource().getChange().getId());
List<Comment> changeComments = commentsUtil.publishedByChange(dbProvider.get(), updatedNotes);
Optional<Comment> updatedComment = changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst();
if (!updatedComment.isPresent()) {
// This should not happen as this endpoint should not remove the whole comment.
throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
}
return commentJson.get().newCommentFormatter().format(updatedComment.get());
}
use of com.google.gerrit.extensions.api.changes.DeleteCommentInput in project gerrit by GerritCodeReview.
the class PortedCommentsIT method deletedCommentContentIsNotPorted.
@Test
public void deletedCommentContentIsNotPorted() throws Exception {
// Set up change and patchsets.
Change.Id changeId = changeOps.newChange().create();
PatchSet.Id patchsetId1 = changeOps.change(changeId).currentPatchset().get().patchsetId();
PatchSet.Id patchsetId2 = changeOps.change(changeId).newPatchset().create();
// Add comment.
String commentUuid = newComment(patchsetId1).message("Confidential content").create();
getPortedComment(patchsetId2, commentUuid);
gApi.changes().id(changeId.get()).revision(patchsetId1.get()).comment(commentUuid).delete(new DeleteCommentInput());
List<CommentInfo> portedComments = flatten(getPortedComments(patchsetId2));
assertThatList(portedComments).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.DeleteCommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method deletedCommentsAreResolved.
@Test
public void deletedCommentsAreResolved() throws Exception {
requestScopeOperations.setApiUser(admin.id());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String commentMessage = "to be deleted";
CommentInput comment = CommentsUtil.newComment(COMMIT_MSG, Side.REVISION, /*line= */
0, commentMessage, /*unresolved= */
true);
CommentsUtil.addComments(gApi, changeId, revId, comment);
Map<String, List<CommentInfo>> results = getPublishedComments(changeId, revId);
CommentInfo oldComment = Iterables.getOnlyElement(results.get(COMMIT_MSG));
DeleteCommentInput input = new DeleteCommentInput("reason");
gApi.changes().id(changeId).revision(revId).comment(oldComment.id).delete(input);
CommentInfo updatedComment = Iterables.getOnlyElement(getPublishedComments(changeId, revId).get(COMMIT_MSG));
assertThat(updatedComment.message).doesNotContain(commentMessage);
assertThat(updatedComment.unresolved).isFalse();
}
Aggregations