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:
Shawn O. Pearce
2010-04-24 13:14:06 -07:00
parent 73915b0ddf
commit 0134d1f533
3 changed files with 19 additions and 4 deletions

View File

@@ -41,6 +41,7 @@ public class ApprovalDetail {
protected Account.Id account; protected Account.Id account;
protected List<PatchSetApproval> approvals; protected List<PatchSetApproval> approvals;
protected boolean canRemove;
private transient int hasNonZero; private transient int hasNonZero;
private transient Timestamp sortOrder = EG_D; private transient Timestamp sortOrder = EG_D;
@@ -57,6 +58,14 @@ public class ApprovalDetail {
return account; return account;
} }
public boolean canRemove() {
return canRemove;
}
public void setCanRemove(boolean removeable) {
canRemove = removeable;
}
public Map<ApprovalCategory.Id, PatchSetApproval> getApprovalMap() { public Map<ApprovalCategory.Id, PatchSetApproval> getApprovalMap() {
final HashMap<ApprovalCategory.Id, PatchSetApproval> r; final HashMap<ApprovalCategory.Id, PatchSetApproval> r;
r = new HashMap<ApprovalCategory.Id, PatchSetApproval>(); r = new HashMap<ApprovalCategory.Id, PatchSetApproval>();

View File

@@ -282,10 +282,7 @@ public class ApprovalTable extends Composite {
col++; col++;
} }
// if (ad.canRemove()) {
// Remove button
//
if (change.getStatus().isOpen() && Gerrit.isSignedIn()) {
Button removeButton = new Button("X"); Button removeButton = new Button("X");
removeButton.setStyleName(Gerrit.RESOURCES.css().removeReviewer()); removeButton.setStyleName(Gerrit.RESOURCES.css().removeReviewer());
removeButton.addClickHandler(new ClickHandler() { removeButton.addClickHandler(new ClickHandler() {
@@ -306,6 +303,8 @@ public class ApprovalTable extends Composite {
} }
}); });
table.setWidget(row, col++, removeButton); table.setWidget(row, col++, removeButton);
} else {
table.setText(row, col++, "");
} }
table.setText(row, col++, hint.toString()); table.setText(row, col++, hint.toString());
} }

View File

@@ -30,6 +30,7 @@ import com.google.gerrit.reviewdb.PatchSetAncestor;
import com.google.gerrit.reviewdb.PatchSetApproval; import com.google.gerrit.reviewdb.PatchSetApproval;
import com.google.gerrit.reviewdb.RevId; import com.google.gerrit.reviewdb.RevId;
import com.google.gerrit.reviewdb.ReviewDb; import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountInfoCacheFactory; import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
@@ -154,14 +155,20 @@ public class ChangeDetailFactory extends Handler<ChangeDetail> {
detail.setCurrentActions(currentActions); detail.setCurrentActions(currentActions);
} }
final boolean canRemoveReviewers = detail.getChange().getStatus().isOpen() //
&& control.getCurrentUser() instanceof IdentifiedUser;
final HashMap<Account.Id, ApprovalDetail> ad = final HashMap<Account.Id, ApprovalDetail> ad =
new HashMap<Account.Id, ApprovalDetail>(); new HashMap<Account.Id, ApprovalDetail>();
for (PatchSetApproval ca : allApprovals) { for (PatchSetApproval ca : allApprovals) {
ApprovalDetail d = ad.get(ca.getAccountId()); ApprovalDetail d = ad.get(ca.getAccountId());
if (d == null) { if (d == null) {
d = new ApprovalDetail(ca.getAccountId()); d = new ApprovalDetail(ca.getAccountId());
d.setCanRemove(canRemoveReviewers);
ad.put(d.getAccount(), d); ad.put(d.getAccount(), d);
} }
if (d.canRemove()) {
d.setCanRemove(control.canRemoveReviewer(ca));
}
if (ca.getPatchSetId().equals(psId)) { if (ca.getPatchSetId().equals(psId)) {
d.add(ca); d.add(ca);
} }