Submit whole topic: disable submit button if not ready
The current implementation just disables the submit button if the current user could not submit all changes in the topic. Additionally we want to block the submit button if the changes do not pass the submit rule checks individually. When the submission is disabled, show a tooltip explaining why there is a problem. This change is also still not what we want to have eventually: We're having a cache invalidation problem, when other changes in the same topic change and affect the submission of the whole topic here. Change-Id: Ic242e738efa9b53cbf0dfd167e64b070c84dac29
This commit is contained in:
@@ -94,6 +94,10 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
"Submit patch set ${patchSet} into ${branch}";
|
"Submit patch set ${patchSet} into ${branch}";
|
||||||
private static final String DEFAULT_TOPIC_TOOLTIP =
|
private static final String DEFAULT_TOPIC_TOOLTIP =
|
||||||
"Submit all ${topicSize} changes of the same topic";
|
"Submit all ${topicSize} changes of the same topic";
|
||||||
|
private static final String BLOCKED_TOPIC_TOOLTIP =
|
||||||
|
"Other changes in this topic are not ready";
|
||||||
|
private static final String BLOCKED_HIDDEN_TOPIC_TOOLTIP =
|
||||||
|
"Other hidden changes in this topic are not ready";
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
SUBMITTED, MERGED
|
SUBMITTED, MERGED
|
||||||
@@ -233,22 +237,32 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areChangesSubmittable(List<ChangeData> changes,
|
/**
|
||||||
|
* @param changes list of changes to be submitted at once
|
||||||
|
* @param identifiedUser the user who is checking to submit
|
||||||
|
* @return a reason why any of the changes is not submittable or null
|
||||||
|
*/
|
||||||
|
private String problemsForSubmittingChanges(List<ChangeData> changes,
|
||||||
IdentifiedUser identifiedUser) {
|
IdentifiedUser identifiedUser) {
|
||||||
for (ChangeData c : changes) {
|
for (ChangeData c : changes) {
|
||||||
try {
|
try {
|
||||||
ChangeControl changeControl = c.changeControl().forUser(
|
ChangeControl changeControl = c.changeControl().forUser(
|
||||||
identifiedUser);
|
identifiedUser);
|
||||||
|
if (!changeControl.isVisible(dbProvider.get())) {
|
||||||
|
return BLOCKED_HIDDEN_TOPIC_TOOLTIP;
|
||||||
|
}
|
||||||
if (!changeControl.canSubmit()) {
|
if (!changeControl.canSubmit()) {
|
||||||
return false;
|
return BLOCKED_TOPIC_TOOLTIP;
|
||||||
}
|
}
|
||||||
|
checkSubmitRule(c, c.currentPatchSet(), false);
|
||||||
} catch (OrmException e) {
|
} catch (OrmException e) {
|
||||||
log.error("Failed to get a ChangeControl for Change.Id " +
|
log.error("Error checking if change is submittable", e);
|
||||||
String.valueOf(c.getId()), e);
|
throw new OrmRuntimeException(e);
|
||||||
return false;
|
} catch (ResourceConflictException e) {
|
||||||
|
return BLOCKED_TOPIC_TOOLTIP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -274,17 +288,22 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
}
|
}
|
||||||
Map<String, String> params = ImmutableMap.of(
|
Map<String, String> params = ImmutableMap.of(
|
||||||
"topicSize", String.valueOf(changesByTopic.size()));
|
"topicSize", String.valueOf(changesByTopic.size()));
|
||||||
// TODO(sbeller):
|
String topicProblems = problemsForSubmittingChanges(changesByTopic,
|
||||||
// If the button is visible but disabled the problem of submitting
|
resource.getUser());
|
||||||
// is at another change in the same topic. Tell the user via
|
if (topicProblems != null) {
|
||||||
// tooltip. Caution: Check access control for those changes.
|
return new UiAction.Description()
|
||||||
|
.setLabel(submitTopicLabel)
|
||||||
|
.setTitle(topicProblems)
|
||||||
|
.setVisible(true)
|
||||||
|
.setEnabled(false);
|
||||||
|
} else {
|
||||||
return new UiAction.Description()
|
return new UiAction.Description()
|
||||||
.setLabel(submitTopicLabel)
|
.setLabel(submitTopicLabel)
|
||||||
.setTitle(Strings.emptyToNull(
|
.setTitle(Strings.emptyToNull(
|
||||||
submitTopicTooltip.replace(params)))
|
submitTopicTooltip.replace(params)))
|
||||||
.setVisible(true)
|
.setVisible(true)
|
||||||
.setEnabled(areChangesSubmittable(
|
.setEnabled(true);
|
||||||
changesByTopic, resource.getUser()));
|
}
|
||||||
} else {
|
} else {
|
||||||
RevId revId = resource.getPatchSet().getRevision();
|
RevId revId = resource.getPatchSet().getRevision();
|
||||||
Map<String, String> params = ImmutableMap.of(
|
Map<String, String> params = ImmutableMap.of(
|
||||||
@@ -336,13 +355,16 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
private Change submitThisChange(RevisionResource rsrc, IdentifiedUser caller,
|
private Change submitThisChange(RevisionResource rsrc, IdentifiedUser caller,
|
||||||
boolean force) throws ResourceConflictException, OrmException,
|
boolean force) throws ResourceConflictException, OrmException,
|
||||||
IOException {
|
IOException {
|
||||||
List<SubmitRecord> submitRecords = checkSubmitRule(rsrc, force);
|
ReviewDb db = dbProvider.get();
|
||||||
|
ChangeData cd = changeDataFactory.create(db, rsrc.getControl());
|
||||||
|
List<SubmitRecord> submitRecords = checkSubmitRule(cd,
|
||||||
|
rsrc.getPatchSet(), force);
|
||||||
|
|
||||||
final Timestamp timestamp = TimeUtil.nowTs();
|
final Timestamp timestamp = TimeUtil.nowTs();
|
||||||
Change change = rsrc.getChange();
|
Change change = rsrc.getChange();
|
||||||
ChangeUpdate update = updateFactory.create(rsrc.getControl(), timestamp);
|
ChangeUpdate update = updateFactory.create(rsrc.getControl(), timestamp);
|
||||||
update.submit(submitRecords);
|
update.submit(submitRecords);
|
||||||
|
|
||||||
ReviewDb db = dbProvider.get();
|
|
||||||
db.changes().beginTransaction(change.getId());
|
db.changes().beginTransaction(change.getId());
|
||||||
try {
|
try {
|
||||||
BatchMetaDataUpdate batch = approve(rsrc, update, caller, timestamp);
|
BatchMetaDataUpdate batch = approve(rsrc, update, caller, timestamp);
|
||||||
@@ -364,13 +386,18 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
boolean force, String topic) throws ResourceConflictException, OrmException,
|
boolean force, String topic) throws ResourceConflictException, OrmException,
|
||||||
IOException {
|
IOException {
|
||||||
Preconditions.checkNotNull(topic);
|
Preconditions.checkNotNull(topic);
|
||||||
List<SubmitRecord> submitRecords = checkSubmitRule(rsrc, force);
|
|
||||||
final Timestamp timestamp = TimeUtil.nowTs();
|
final Timestamp timestamp = TimeUtil.nowTs();
|
||||||
|
|
||||||
|
ReviewDb db = dbProvider.get();
|
||||||
|
ChangeData cd = changeDataFactory.create(db, rsrc.getControl());
|
||||||
|
|
||||||
|
List<SubmitRecord> submitRecords = checkSubmitRule(cd,
|
||||||
|
rsrc.getPatchSet(), force);
|
||||||
|
|
||||||
Change change = rsrc.getChange();
|
Change change = rsrc.getChange();
|
||||||
ChangeUpdate update = updateFactory.create(rsrc.getControl(), timestamp);
|
ChangeUpdate update = updateFactory.create(rsrc.getControl(), timestamp);
|
||||||
update.submit(submitRecords);
|
update.submit(submitRecords);
|
||||||
|
|
||||||
ReviewDb db = dbProvider.get();
|
|
||||||
db.changes().beginTransaction(change.getId());
|
db.changes().beginTransaction(change.getId());
|
||||||
|
|
||||||
List<ChangeData> changesByTopic = queryProvider.get().byTopicOpen(topic);
|
List<ChangeData> changesByTopic = queryProvider.get().byTopicOpen(topic);
|
||||||
@@ -498,12 +525,11 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SubmitRecord> checkSubmitRule(RevisionResource rsrc,
|
private List<SubmitRecord> checkSubmitRule(ChangeData cd,
|
||||||
boolean force) throws ResourceConflictException, OrmException {
|
PatchSet patchSet, boolean force)
|
||||||
ChangeData cd =
|
throws ResourceConflictException, OrmException {
|
||||||
changeDataFactory.create(dbProvider.get(), rsrc.getControl());
|
|
||||||
List<SubmitRecord> results = new SubmitRuleEvaluator(cd)
|
List<SubmitRecord> results = new SubmitRuleEvaluator(cd)
|
||||||
.setPatchSet(rsrc.getPatchSet())
|
.setPatchSet(patchSet)
|
||||||
.canSubmit();
|
.canSubmit();
|
||||||
Optional<SubmitRecord> ok = findOkRecord(results);
|
Optional<SubmitRecord> ok = findOkRecord(results);
|
||||||
if (ok.isPresent()) {
|
if (ok.isPresent()) {
|
||||||
@@ -514,8 +540,8 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
} else if (results.isEmpty()) {
|
} else if (results.isEmpty()) {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"ChangeControl.canSubmit returned empty list for %s in %s",
|
"ChangeControl.canSubmit returned empty list for %s in %s",
|
||||||
rsrc.getPatchSet().getId(),
|
patchSet.getId(),
|
||||||
rsrc.getChange().getProject().get()));
|
cd.change().getProject().get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SubmitRecord record : results) {
|
for (SubmitRecord record : results) {
|
||||||
@@ -562,8 +588,8 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"Unsupported SubmitRecord.Label %s for %s in %s",
|
"Unsupported SubmitRecord.Label %s for %s in %s",
|
||||||
lbl.toString(),
|
lbl.toString(),
|
||||||
rsrc.getPatchSet().getId(),
|
patchSet.getId(),
|
||||||
rsrc.getChange().getProject().get()));
|
cd.change().getProject().get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ResourceConflictException(msg.toString());
|
throw new ResourceConflictException(msg.toString());
|
||||||
@@ -572,8 +598,8 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>,
|
|||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"Unsupported SubmitRecord %s for %s in %s",
|
"Unsupported SubmitRecord %s for %s in %s",
|
||||||
record,
|
record,
|
||||||
rsrc.getPatchSet().getId(),
|
patchSet.getId().getId(),
|
||||||
rsrc.getChange().getProject().get()));
|
cd.change().getProject().get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
|||||||
Reference in New Issue
Block a user