Revert "Remove Revert Submission button"
This reverts commit fb0c7312fc.
Reason for revert: Frontend expects this information. This should be
reverted until frontend uses an alternative way of getting this information.
Change-Id: Iacbf8db9aec7eb54e555f889ee388fcaead5dd27
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.server.restapi.change;
|
package com.google.gerrit.server.restapi.change;
|
||||||
|
|
||||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||||
|
import static com.google.gerrit.extensions.conditions.BooleanCondition.and;
|
||||||
import static com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE;
|
import static com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
@@ -38,6 +39,7 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
|||||||
import com.google.gerrit.extensions.restapi.Response;
|
import com.google.gerrit.extensions.restapi.Response;
|
||||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
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.server.ChangeMessagesUtil;
|
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||||
import com.google.gerrit.server.ChangeUtil;
|
import com.google.gerrit.server.ChangeUtil;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
@@ -96,7 +98,8 @@ import org.eclipse.jgit.lib.Repository;
|
|||||||
import org.eclipse.jgit.revwalk.RevCommit;
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.revwalk.RevWalk;
|
import org.eclipse.jgit.revwalk.RevWalk;
|
||||||
|
|
||||||
public class RevertSubmission implements RestModifyView<ChangeResource, RevertInput> {
|
public class RevertSubmission
|
||||||
|
implements RestModifyView<ChangeResource, RevertInput>, UiAction<ChangeResource> {
|
||||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||||
|
|
||||||
private final Provider<InternalChangeQuery> queryProvider;
|
private final Provider<InternalChangeQuery> queryProvider;
|
||||||
@@ -527,6 +530,40 @@ public class RevertSubmission implements RestModifyView<ChangeResource, RevertIn
|
|||||||
potentialCommitToReturn.getName(), changeNotes.getChange().getChangeId()));
|
potentialCommitToReturn.getName(), changeNotes.getChange().getChangeId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Description getDescription(ChangeResource rsrc) {
|
||||||
|
Change change = rsrc.getChange();
|
||||||
|
boolean projectStatePermitsWrite = false;
|
||||||
|
try {
|
||||||
|
projectStatePermitsWrite = projectCache.checkedGet(rsrc.getProject()).statePermitsWrite();
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.atSevere().withCause(e).log(
|
||||||
|
"Failed to check if project state permits write: %s", rsrc.getProject());
|
||||||
|
}
|
||||||
|
return new UiAction.Description()
|
||||||
|
.setLabel("Revert submission")
|
||||||
|
.setTitle(
|
||||||
|
"Revert this change and all changes that have been submitted together with this change")
|
||||||
|
.setVisible(
|
||||||
|
and(
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
private class CreateCherryPickOp implements BatchUpdateOp {
|
private class CreateCherryPickOp implements BatchUpdateOp {
|
||||||
private final ObjectId revCommitId;
|
private final ObjectId revCommitId;
|
||||||
private final String topic;
|
private final String topic;
|
||||||
|
|||||||
@@ -78,6 +78,22 @@ public class ActionsIT extends AbstractDaemonTest {
|
|||||||
gApi.changes().id(changeId).current().submit();
|
gApi.changes().id(changeId).current().submit();
|
||||||
Map<String, ActionInfo> actions = getChangeActions(changeId);
|
Map<String, ActionInfo> actions = getChangeActions(changeId);
|
||||||
assertThat(actions).containsKey("revert");
|
assertThat(actions).containsKey("revert");
|
||||||
|
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
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user