Support to delete a comment with 'NoteDbRewriter' in BatchUpdate

This change adds a new interface 'NoteDbRewriter', which can be used to
rewrite the NoteDb commit history in BatchUpdate.

By implementing the new interface, this change allows users with
administrate server capability to delete a comment by replacing the
comment's message.

To delete a whole comment, the rewritter is required to update the
commit message, which contains the number of the comments put in by the
original commit. This can be done in later changes when necessary.

Bug: Issue 4445
Change-Id: Icaeb3c24f5dc88f6b44b1297366a692a32676910
This commit is contained in:
Changcheng Xiao
2017-02-10 09:39:48 +01:00
parent 368c922dfc
commit e5b14cebd5
15 changed files with 857 additions and 6 deletions

View File

@@ -17,9 +17,11 @@ package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.CommentApi;
import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.CommentResource;
import com.google.gerrit.server.change.DeleteComment;
import com.google.gerrit.server.change.GetComment;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -30,11 +32,14 @@ class CommentApiImpl implements CommentApi {
}
private final GetComment getComment;
private final DeleteComment deleteComment;
private final CommentResource comment;
@Inject
CommentApiImpl(GetComment getComment, @Assisted CommentResource comment) {
CommentApiImpl(
GetComment getComment, DeleteComment deleteComment, @Assisted CommentResource comment) {
this.getComment = getComment;
this.deleteComment = deleteComment;
this.comment = comment;
}
@@ -46,4 +51,13 @@ class CommentApiImpl implements CommentApi {
throw asRestApiException("Cannot retrieve comment", e);
}
}
@Override
public CommentInfo delete(DeleteCommentInput input) throws RestApiException {
try {
return deleteComment.apply(comment, input);
} catch (Exception e) {
throw asRestApiException("Cannot delete comment", e);
}
}
}

View File

@@ -16,9 +16,11 @@ package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
import com.google.gerrit.extensions.api.changes.DraftApi;
import com.google.gerrit.extensions.api.changes.DraftInput;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.NotImplementedException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.DeleteDraftComment;
import com.google.gerrit.server.change.DraftCommentResource;
@@ -75,4 +77,9 @@ class DraftApiImpl implements DraftApi {
throw asRestApiException("Cannot delete draft", e);
}
}
@Override
public CommentInfo delete(DeleteCommentInput input) {
throw new NotImplementedException();
}
}