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
This commit is contained in:
Stefan Beller 2015-02-12 14:45:27 -08:00 committed by David Pursehouse
parent 09cd95dbfd
commit 4512bb4582
2 changed files with 17 additions and 0 deletions

View File

@ -38,6 +38,14 @@ public class ActionsIT extends AbstractDaemonTest {
return submitWholeTopicEnabledConfig(); return submitWholeTopicEnabledConfig();
} }
@Test
public void revisionActionsOneChangePerTopicUnapproved() throws Exception {
String changeId = createChangeWithTopic("foo1").getChangeId();
Map<String, ActionInfo> actions = getActions(changeId);
assertThat(actions).containsKey("cherrypick");
assertThat(actions).hasSize(1);
}
@Test @Test
public void revisionActionsOneChangePerTopic() throws Exception { public void revisionActionsOneChangePerTopic() throws Exception {
String changeId = createChangeWithTopic("foo1").getChangeId(); String changeId = createChangeWithTopic("foo1").getChangeId();

View File

@ -81,6 +81,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -273,6 +274,14 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
&& resource.getChange().getStatus().isOpen() && resource.getChange().getStatus().isOpen()
&& resource.getPatchSet().getId().equals(current) && resource.getPatchSet().getId().equals(current)
&& resource.getControl().canSubmit(); && 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) { if (!visible) {
return new UiAction.Description() return new UiAction.Description()
.setLabel("") .setLabel("")