Only show reviewer removal buttons when removal is allowed
Don't bother showing the "X" remove button unless the user can actually perform this action at the time that the page was shown. This hides the removal flag for users who have voted a negative score, unless you are the project administrator. It also hides the flag unless the row is for yourself, or you are the change owner or the project's administrator. Change-Id: I30f3cf5081b8126ebf6644b4c64ce76c35dc1e88 Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -41,6 +41,7 @@ public class ApprovalDetail {
|
||||
|
||||
protected Account.Id account;
|
||||
protected List<PatchSetApproval> approvals;
|
||||
protected boolean canRemove;
|
||||
|
||||
private transient int hasNonZero;
|
||||
private transient Timestamp sortOrder = EG_D;
|
||||
@@ -57,6 +58,14 @@ public class ApprovalDetail {
|
||||
return account;
|
||||
}
|
||||
|
||||
public boolean canRemove() {
|
||||
return canRemove;
|
||||
}
|
||||
|
||||
public void setCanRemove(boolean removeable) {
|
||||
canRemove = removeable;
|
||||
}
|
||||
|
||||
public Map<ApprovalCategory.Id, PatchSetApproval> getApprovalMap() {
|
||||
final HashMap<ApprovalCategory.Id, PatchSetApproval> r;
|
||||
r = new HashMap<ApprovalCategory.Id, PatchSetApproval>();
|
||||
|
@@ -282,10 +282,7 @@ public class ApprovalTable extends Composite {
|
||||
col++;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove button
|
||||
//
|
||||
if (change.getStatus().isOpen() && Gerrit.isSignedIn()) {
|
||||
if (ad.canRemove()) {
|
||||
Button removeButton = new Button("X");
|
||||
removeButton.setStyleName(Gerrit.RESOURCES.css().removeReviewer());
|
||||
removeButton.addClickHandler(new ClickHandler() {
|
||||
@@ -306,6 +303,8 @@ public class ApprovalTable extends Composite {
|
||||
}
|
||||
});
|
||||
table.setWidget(row, col++, removeButton);
|
||||
} else {
|
||||
table.setText(row, col++, "");
|
||||
}
|
||||
table.setText(row, col++, hint.toString());
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import com.google.gerrit.reviewdb.PatchSetAncestor;
|
||||
import com.google.gerrit.reviewdb.PatchSetApproval;
|
||||
import com.google.gerrit.reviewdb.RevId;
|
||||
import com.google.gerrit.reviewdb.ReviewDb;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
@@ -154,14 +155,20 @@ public class ChangeDetailFactory extends Handler<ChangeDetail> {
|
||||
detail.setCurrentActions(currentActions);
|
||||
}
|
||||
|
||||
final boolean canRemoveReviewers = detail.getChange().getStatus().isOpen() //
|
||||
&& control.getCurrentUser() instanceof IdentifiedUser;
|
||||
final HashMap<Account.Id, ApprovalDetail> ad =
|
||||
new HashMap<Account.Id, ApprovalDetail>();
|
||||
for (PatchSetApproval ca : allApprovals) {
|
||||
ApprovalDetail d = ad.get(ca.getAccountId());
|
||||
if (d == null) {
|
||||
d = new ApprovalDetail(ca.getAccountId());
|
||||
d.setCanRemove(canRemoveReviewers);
|
||||
ad.put(d.getAccount(), d);
|
||||
}
|
||||
if (d.canRemove()) {
|
||||
d.setCanRemove(control.canRemoveReviewer(ca));
|
||||
}
|
||||
if (ca.getPatchSetId().equals(psId)) {
|
||||
d.add(ca);
|
||||
}
|
||||
|
Reference in New Issue
Block a user