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.Inject;
|
||||||
import com.google.inject.assistedinject.Assisted;
|
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.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -133,25 +130,12 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
|
|||||||
final Set<AccountGroup.Id> am = user.getEffectiveGroups();
|
final Set<AccountGroup.Id> am = user.getEffectiveGroups();
|
||||||
final ProjectState pe = projectCache.get(change.getProject());
|
final ProjectState pe = projectCache.get(change.getProject());
|
||||||
for (ApprovalCategory.Id category : approvalTypes.getApprovalCategories()) {
|
for (ApprovalCategory.Id category : approvalTypes.getApprovalCategories()) {
|
||||||
List<RefRight> categoryRights = new ArrayList<RefRight>();
|
RefControl rc = pe.controlFor(user).controlForRef(change.getDest());
|
||||||
categoryRights.addAll(filterMatching(pe.getLocalRights(category)));
|
List<RefRight> categoryRights = rc.getApplicableRights(category);
|
||||||
categoryRights.addAll(filterMatching(pe.getInheritedRights(category)));
|
|
||||||
Collections.sort(categoryRights, RefRight.REF_PATTERN_ORDER);
|
|
||||||
|
|
||||||
computeAllowed(am, categoryRights, 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,
|
private void computeAllowed(final Set<AccountGroup.Id> am,
|
||||||
final List<RefRight> list, ApprovalCategory.Id category) {
|
final List<RefRight> list, ApprovalCategory.Id category) {
|
||||||
|
|
||||||
@@ -161,27 +145,10 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
|
|||||||
allowed.put(category, s);
|
allowed.put(category, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean foundExclusive = false;
|
|
||||||
String previousPattern = "";
|
|
||||||
for (final RefRight r : list) {
|
for (final RefRight r : list) {
|
||||||
|
|
||||||
if (!am.contains(r.getAccountGroupId())) {
|
if (!am.contains(r.getAccountGroupId())) {
|
||||||
if (r.isExclusive()) {
|
|
||||||
foundExclusive = true;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundExclusive && !previousPattern.equals(r.getRefPattern())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r.isExclusive()) {
|
|
||||||
foundExclusive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
previousPattern = r.getRefPattern();
|
|
||||||
|
|
||||||
final ApprovalType at =
|
final ApprovalType at =
|
||||||
approvalTypes.getApprovalType(r.getApprovalCategoryId());
|
approvalTypes.getApprovalType(r.getApprovalCategoryId());
|
||||||
for (short m = r.getMinValue(); m <= r.getMaxValue(); m++) {
|
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
|
* matching when an exclusive ref right was encountered, for the given
|
||||||
* approval category.
|
* approval category.
|
||||||
* @param id The {@link ApprovalCategory.Id}.
|
* @param id The {@link ApprovalCategory.Id}.
|
||||||
* @return All applicalbe rights.
|
* @return All applicable rights.
|
||||||
*/
|
*/
|
||||||
public List<RefRight> getApplicableRights(final ApprovalCategory.Id id) {
|
public List<RefRight> getApplicableRights(final ApprovalCategory.Id id) {
|
||||||
List<RefRight> l = new ArrayList<RefRight>();
|
List<RefRight> l = new ArrayList<RefRight>();
|
||||||
|
|||||||
Reference in New Issue
Block a user