Update approvals in web UI to adapt to rules.pl submit_rule
The UI now shows whatever the results of the submit_rule are, which permits the submit_rule to make an ApprovalCategory optional, or to make a new label required. Currently making a new label required is also going to make the change unsubmittable, as we do not yet have a way to store the new label. Change-Id: I9c6600c181e9f22ff980539d535caa8458d9a654
This commit is contained in:
@@ -21,9 +21,9 @@ import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ApprovalDetail {
|
||||
public static final Comparator<ApprovalDetail> SORT =
|
||||
@@ -43,6 +43,8 @@ public class ApprovalDetail {
|
||||
protected List<PatchSetApproval> approvals;
|
||||
protected boolean canRemove;
|
||||
|
||||
private transient Set<String> approved;
|
||||
private transient Set<String> rejected;
|
||||
private transient int hasNonZero;
|
||||
private transient Timestamp sortOrder = EG_D;
|
||||
|
||||
@@ -66,13 +68,17 @@ public class ApprovalDetail {
|
||||
canRemove = removeable;
|
||||
}
|
||||
|
||||
public Map<ApprovalCategory.Id, PatchSetApproval> getApprovalMap() {
|
||||
final HashMap<ApprovalCategory.Id, PatchSetApproval> r;
|
||||
r = new HashMap<ApprovalCategory.Id, PatchSetApproval>();
|
||||
for (final PatchSetApproval ca : approvals) {
|
||||
r.put(ca.getCategoryId(), ca);
|
||||
public List<PatchSetApproval> getPatchSetApprovals() {
|
||||
return approvals;
|
||||
}
|
||||
|
||||
public PatchSetApproval getPatchSetApproval(ApprovalCategory.Id category) {
|
||||
for (PatchSetApproval psa : approvals) {
|
||||
if (psa.getCategoryId().equals(category)) {
|
||||
return psa;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sortFirst() {
|
||||
@@ -91,4 +97,26 @@ public class ApprovalDetail {
|
||||
hasNonZero = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void approved(String label) {
|
||||
if (approved == null) {
|
||||
approved = new HashSet<String>();
|
||||
}
|
||||
approved.add(label);
|
||||
}
|
||||
|
||||
public void rejected(String label) {
|
||||
if (rejected == null) {
|
||||
rejected = new HashSet<String>();
|
||||
}
|
||||
rejected.add(label);
|
||||
}
|
||||
|
||||
public boolean isApproved(String label) {
|
||||
return approved != null && approved.contains(label);
|
||||
}
|
||||
|
||||
public boolean isRejected(String label) {
|
||||
return rejected != null && rejected.contains(label);
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@
|
||||
|
||||
package com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.reviewdb.ApprovalCategory;
|
||||
import com.google.gerrit.reviewdb.Change;
|
||||
import com.google.gerrit.reviewdb.ChangeMessage;
|
||||
import com.google.gerrit.reviewdb.PatchSet;
|
||||
@@ -23,7 +22,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/** Detail necessary to display a change. */
|
||||
public class ChangeDetail {
|
||||
@@ -38,7 +36,7 @@ public class ChangeDetail {
|
||||
protected List<ChangeInfo> neededBy;
|
||||
protected List<PatchSet> patchSets;
|
||||
protected List<ApprovalDetail> approvals;
|
||||
protected Set<ApprovalCategory.Id> missingApprovals;
|
||||
protected List<SubmitRecord> submitRecords;
|
||||
protected boolean canSubmit;
|
||||
protected List<ChangeMessage> messages;
|
||||
protected PatchSet.Id currentPatchSetId;
|
||||
@@ -153,12 +151,12 @@ public class ChangeDetail {
|
||||
Collections.sort(approvals, ApprovalDetail.SORT);
|
||||
}
|
||||
|
||||
public Set<ApprovalCategory.Id> getMissingApprovals() {
|
||||
return missingApprovals;
|
||||
public void setSubmitRecords(List<SubmitRecord> all) {
|
||||
submitRecords = all;
|
||||
}
|
||||
|
||||
public void setMissingApprovals(Set<ApprovalCategory.Id> a) {
|
||||
missingApprovals = a;
|
||||
public List<SubmitRecord> getSubmitRecords() {
|
||||
return submitRecords;
|
||||
}
|
||||
|
||||
public boolean isCurrentPatchSet(final PatchSetDetail detail) {
|
||||
|
@@ -0,0 +1,82 @@
|
||||
// Copyright (C) 2011 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.common.data;
|
||||
|
||||
import com.google.gerrit.reviewdb.Account;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes the state required to submit a change.
|
||||
*/
|
||||
public class SubmitRecord {
|
||||
public static enum Status {
|
||||
/** The change is ready for submission. */
|
||||
OK,
|
||||
|
||||
/** The change is missing a required label. */
|
||||
NOT_READY,
|
||||
|
||||
/** The change has been closed. */
|
||||
CLOSED,
|
||||
|
||||
/**
|
||||
* An internal server error occurred preventing computation.
|
||||
* <p>
|
||||
* Additional detail may be available in {@link SubmitRecord#errorMessage}.
|
||||
*/
|
||||
RULE_ERROR;
|
||||
}
|
||||
|
||||
public Status status;
|
||||
public List<Label> labels;
|
||||
public String errorMessage;
|
||||
|
||||
public static class Label {
|
||||
public static enum Status {
|
||||
/**
|
||||
* This label provides what is necessary for submission.
|
||||
* <p>
|
||||
* If provided, {@link Label#appliedBy} describes the user account
|
||||
* that applied this label to the change.
|
||||
*/
|
||||
OK,
|
||||
|
||||
/**
|
||||
* This label prevents the change from being submitted.
|
||||
* <p>
|
||||
* If provided, {@link Label#appliedBy} describes the user account
|
||||
* that applied this label to the change.
|
||||
*/
|
||||
REJECT,
|
||||
|
||||
/**
|
||||
* The label is required for submission, but has not been satisfied.
|
||||
*/
|
||||
NEED,
|
||||
|
||||
/**
|
||||
* The label is required for submission, but is impossible to complete.
|
||||
* The likely cause is access has not been granted correctly by the
|
||||
* project owner or site administrator.
|
||||
*/
|
||||
IMPOSSIBLE;
|
||||
}
|
||||
|
||||
public String label;
|
||||
public Status status;
|
||||
public Account.Id appliedBy;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user