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
This commit is contained in:
@@ -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<PatchSetPublishDetail>
|
||||
final Set<AccountGroup.Id> am = user.getEffectiveGroups();
|
||||
final ProjectState pe = projectCache.get(change.getProject());
|
||||
for (ApprovalCategory.Id category : approvalTypes.getApprovalCategories()) {
|
||||
List<RefRight> categoryRights = new ArrayList<RefRight>();
|
||||
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<RefRight> categoryRights = rc.getApplicableRights(category);
|
||||
computeAllowed(am, categoryRights, category);
|
||||
}
|
||||
}
|
||||
|
||||
private List<RefRight> filterMatching(Collection<RefRight> rights) {
|
||||
List<RefRight> result = new ArrayList<RefRight>();
|
||||
for (RefRight right : rights) {
|
||||
if (RefControl.matches(change.getDest().get(), right.getRefPattern())) {
|
||||
result.add(right);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void computeAllowed(final Set<AccountGroup.Id> am,
|
||||
final List<RefRight> list, ApprovalCategory.Id category) {
|
||||
|
||||
@@ -161,27 +145,10 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
|
||||
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++) {
|
||||
|
||||
@@ -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<RefRight> getApplicableRights(final ApprovalCategory.Id id) {
|
||||
List<RefRight> l = new ArrayList<RefRight>();
|
||||
|
||||
Reference in New Issue
Block a user