Merge "Hide Revert Submission button for singular changes"

This commit is contained in:
Gal Paikin
2019-11-27 15:58:23 +00:00
committed by Gerrit Code Review
2 changed files with 29 additions and 3 deletions

View File

@@ -160,10 +160,21 @@ public class RevertSubmission
"Revert this change and all changes that have been submitted together with this change")
.setVisible(
and(
change.isMerged() && change.getSubmissionId() != null && projectStatePermitsWrite,
change.isMerged()
&& change.getSubmissionId() != null
&& isChangePartOfSubmission(change.getSubmissionId())
&& projectStatePermitsWrite,
permissionBackend
.user(rsrc.getUser())
.ref(change.getDest())
.testCond(CREATE_CHANGE)));
}
/**
* @param submissionId the submission id of the change.
* @return True if the submission has more than one change, false otherwise.
*/
private Boolean isChangePartOfSubmission(String submissionId) {
return (queryProvider.get().setLimit(2).bySubmissionId(submissionId).size() > 1);
}
}

View File

@@ -72,13 +72,28 @@ public class ActionsIT extends AbstractDaemonTest {
}
@Test
public void changeActionOneMergedChangeHasReverts() throws Exception {
public void changeActionOneMergedChangeHasOnlyNormalRevert() throws Exception {
String changeId = createChangeWithTopic().getChangeId();
gApi.changes().id(changeId).current().review(ReviewInput.approve());
gApi.changes().id(changeId).current().submit();
Map<String, ActionInfo> actions = getChangeActions(changeId);
assertThat(actions).containsKey("revert");
assertThat(actions).containsKey("revert_submission");
assertThat(actions).doesNotContainKey("revert_submission");
}
@Test
public void changeActionTwoMergedChangesHaveReverts() throws Exception {
String changeId1 = createChangeWithTopic().getChangeId();
String changeId2 = createChangeWithTopic().getChangeId();
gApi.changes().id(changeId1).current().review(ReviewInput.approve());
gApi.changes().id(changeId2).current().review(ReviewInput.approve());
gApi.changes().id(changeId2).current().submit();
Map<String, ActionInfo> actions1 = getChangeActions(changeId1);
assertThat(actions1).containsKey("revert");
assertThat(actions1).containsKey("revert_submission");
Map<String, ActionInfo> actions2 = getChangeActions(changeId2);
assertThat(actions2).containsKey("revert");
assertThat(actions2).containsKey("revert_submission");
}
@Test