From 4512bb4582080fa2da9d88115bcf8f20209706ec Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Thu, 12 Feb 2015 14:45:27 -0800 Subject: [PATCH] REST API: only advertise submit if it's possible Currently the code for enabling the submit button as well as determining its visibility is partly done on the server side as well on the client side. This change changes the server side such that it also includes the logic which is currently in the web UI. This allows us to remove the logic from the web UI in a later patch. Change-Id: Ief2d4677208900143a67db7b06882e24d1bf2a5d --- .../google/gerrit/acceptance/rest/change/ActionsIT.java | 8 ++++++++ .../java/com/google/gerrit/server/change/Submit.java | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/ActionsIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/ActionsIT.java index b463a53c87..4acec9aef8 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/ActionsIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change/ActionsIT.java @@ -38,6 +38,14 @@ public class ActionsIT extends AbstractDaemonTest { return submitWholeTopicEnabledConfig(); } + @Test + public void revisionActionsOneChangePerTopicUnapproved() throws Exception { + String changeId = createChangeWithTopic("foo1").getChangeId(); + Map actions = getActions(changeId); + assertThat(actions).containsKey("cherrypick"); + assertThat(actions).hasSize(1); + } + @Test public void revisionActionsOneChangePerTopic() throws Exception { String changeId = createChangeWithTopic("foo1").getChangeId(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java index 86ce3b99ff..41151ae8da 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java @@ -81,6 +81,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -273,6 +274,14 @@ public class Submit implements RestModifyView, && resource.getChange().getStatus().isOpen() && resource.getPatchSet().getId().equals(current) && resource.getControl().canSubmit(); + + ReviewDb db = dbProvider.get(); + ChangeData cd = changeDataFactory.create(db, resource.getControl()); + if (problemsForSubmittingChanges(Arrays.asList(cd), resource.getUser()) + != null) { + visible = false; + } + if (!visible) { return new UiAction.Description() .setLabel("")