DeleteDraftComments: Don't update change modified timestamp

When removing all the changes associated with a user,
do not bump the associated updatedOn timestamp similarly
to what it does the single removal of individual drafts.

Add also coverage for the existing use-cases where
adding or removing a draft change should not update
the updatedOn timestamp, already working but not properly
covered.

Bug: Issue 11325
Change-Id: Ieaad3888b570db9eee6e2eb8130acc3b4cfe3d16
This commit is contained in:
Luca Milanesio
2019-08-24 21:38:33 +02:00
committed by David Pursehouse
parent 21c8de76ff
commit 16a6eeb825
2 changed files with 45 additions and 5 deletions

View File

@@ -200,6 +200,7 @@ public class DeleteDraftComments
.format(changeDataFactory.create(ctx.getDb(), ctx.getNotes()));
result.deleted = comments.build();
}
ctx.dontBumpLastUpdatedOn();
return dirty;
}

View File

@@ -72,10 +72,13 @@ import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.data.LabelFunction;
import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.Permission;
import com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
import com.google.gerrit.extensions.api.changes.DeleteReviewerInput;
import com.google.gerrit.extensions.api.changes.DeleteVoteInput;
import com.google.gerrit.extensions.api.changes.DraftApi;
import com.google.gerrit.extensions.api.changes.DraftInput;
import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.api.changes.NotifyInfo;
import com.google.gerrit.extensions.api.changes.RebaseInput;
@@ -286,11 +289,7 @@ public class ChangeIT extends AbstractDaemonTest {
@Test
public void administratorCanSetUserChangePrivate() throws Exception {
TestRepository<InMemoryRepository> userRepo = cloneProject(project, user);
PushOneCommit.Result result =
pushFactory.create(db, user.getIdent(), userRepo).to("refs/for/master");
String changeId = result.getChangeId();
String changeId = createNewChange();
assertThat(gApi.changes().id(changeId).get().isPrivate).isNull();
gApi.changes().id(changeId).setPrivate(true, null);
@@ -3846,6 +3845,46 @@ public class ChangeIT extends AbstractDaemonTest {
gApi.changes().id(changeId).current().submit();
}
@Test
public void draftCommentsShouldNotUpdateChangeTimestamp() throws Exception {
String changeId = createNewChange();
Timestamp changeTs = getChangeLastUpdate(changeId);
DraftApi draftApi = addDraftComment(changeId);
assertThat(getChangeLastUpdate(changeId)).isEqualTo(changeTs);
draftApi.delete();
assertThat(getChangeLastUpdate(changeId)).isEqualTo(changeTs);
}
@Test
public void deletingAllDraftCommentsShouldNotUpdateChangeTimestamp() throws Exception {
String changeId = createNewChange();
Timestamp changeTs = getChangeLastUpdate(changeId);
addDraftComment(changeId);
assertThat(getChangeLastUpdate(changeId)).isEqualTo(changeTs);
gApi.accounts().self().deleteDraftComments(new DeleteDraftCommentsInput());
assertThat(getChangeLastUpdate(changeId)).isEqualTo(changeTs);
}
private Timestamp getChangeLastUpdate(String changeId) throws RestApiException {
Timestamp changeTs = gApi.changes().id(changeId).get().updated;
return changeTs;
}
private String createNewChange() throws Exception {
TestRepository<InMemoryRepository> userRepo = cloneProject(project, user);
PushOneCommit.Result result =
pushFactory.create(db, user.getIdent(), userRepo).to("refs/for/master");
String changeId = result.getChangeId();
return changeId;
}
private DraftApi addDraftComment(String changeId) throws RestApiException {
DraftInput comment = new DraftInput();
comment.message = "foo";
comment.path = "/foo";
return gApi.changes().id(changeId).current().createDraft(comment);
}
private String getCommitMessage(String changeId) throws RestApiException, IOException {
return gApi.changes().id(changeId).current().file("/COMMIT_MSG").content().asString();
}