From f5887c01bfe4e329ece5a43bc20f0794a4a207f5 Mon Sep 17 00:00:00 2001 From: Nico Sallembien Date: Tue, 15 Jun 2010 15:06:36 -0700 Subject: [PATCH] Compute appropriate rights in PatchSetPublishDetailFactory This code needed to be modified as well in order to work properly with new exclusive and inherited branch rights. Change-Id: I5a970240bd06b793d15f59c655aa0231c72925c9 --- .../PatchSetPublishDetailFactory.java | 37 +------------------ .../gerrit/server/project/RefControl.java | 2 +- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java index 3d201dbe1d..779475e73f 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java @@ -43,9 +43,6 @@ import com.google.gwtorm.client.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -133,25 +130,12 @@ final class PatchSetPublishDetailFactory extends Handler final Set am = user.getEffectiveGroups(); final ProjectState pe = projectCache.get(change.getProject()); for (ApprovalCategory.Id category : approvalTypes.getApprovalCategories()) { - List categoryRights = new ArrayList(); - categoryRights.addAll(filterMatching(pe.getLocalRights(category))); - categoryRights.addAll(filterMatching(pe.getInheritedRights(category))); - Collections.sort(categoryRights, RefRight.REF_PATTERN_ORDER); - + RefControl rc = pe.controlFor(user).controlForRef(change.getDest()); + List categoryRights = rc.getApplicableRights(category); computeAllowed(am, categoryRights, category); } } - private List filterMatching(Collection rights) { - List result = new ArrayList(); - for (RefRight right : rights) { - if (RefControl.matches(change.getDest().get(), right.getRefPattern())) { - result.add(right); - } - } - return result; - } - private void computeAllowed(final Set am, final List list, ApprovalCategory.Id category) { @@ -161,27 +145,10 @@ final class PatchSetPublishDetailFactory extends Handler allowed.put(category, s); } - boolean foundExclusive = false; - String previousPattern = ""; for (final RefRight r : list) { - if (!am.contains(r.getAccountGroupId())) { - if (r.isExclusive()) { - foundExclusive = true; - } continue; } - - if (foundExclusive && !previousPattern.equals(r.getRefPattern())) { - break; - } - - if (r.isExclusive()) { - foundExclusive = true; - } - - previousPattern = r.getRefPattern(); - final ApprovalType at = approvalTypes.getApprovalType(r.getApprovalCategoryId()); for (short m = r.getMinValue(); m <= r.getMaxValue(); m++) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/RefControl.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/RefControl.java index 6d3d5cd124..32fa01cbd4 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/RefControl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/RefControl.java @@ -370,7 +370,7 @@ public class RefControl { * matching when an exclusive ref right was encountered, for the given * approval category. * @param id The {@link ApprovalCategory.Id}. - * @return All applicalbe rights. + * @return All applicable rights. */ public List getApplicableRights(final ApprovalCategory.Id id) { List l = new ArrayList();