use of com.google.gerrit.entities.PermissionRule in project gerrit by GerritCodeReview.
the class RefControl method canPerform.
/**
* True if the user has this permission.
*/
private boolean canPerform(String permissionName, boolean isChangeOwner, boolean withForce) {
if (isBlocked(permissionName, isChangeOwner, withForce)) {
if (logger.atFine().isEnabled() || LoggingContext.getInstance().isAclLogging()) {
String logMessage = String.format("'%s' cannot perform '%s' with force=%s on project '%s' for ref '%s'" + " because this permission is blocked", getUser().getLoggableName(), permissionName, withForce, projectControl.getProject().getName(), refName);
LoggingContext.getInstance().addAclLogRecord(logMessage);
logger.atFine().log("%s (caller: %s)", logMessage, callerFinder.findCallerLazy());
}
return false;
}
for (PermissionRule pr : relevant.getAllowRules(permissionName)) {
if (isAllow(pr, withForce) && projectControl.match(pr, isChangeOwner)) {
if (logger.atFine().isEnabled() || LoggingContext.getInstance().isAclLogging()) {
String logMessage = String.format("'%s' can perform '%s' with force=%s on project '%s' for ref '%s'", getUser().getLoggableName(), permissionName, withForce, projectControl.getProject().getName(), refName);
LoggingContext.getInstance().addAclLogRecord(logMessage);
logger.atFine().log("%s (caller: %s)", logMessage, callerFinder.findCallerLazy());
}
return true;
}
}
if (logger.atFine().isEnabled() || LoggingContext.getInstance().isAclLogging()) {
String logMessage = String.format("'%s' cannot perform '%s' with force=%s on project '%s' for ref '%s'", getUser().getLoggableName(), permissionName, withForce, projectControl.getProject().getName(), refName);
LoggingContext.getInstance().addAclLogRecord(logMessage);
logger.atFine().log("%s (caller: %s)", logMessage, callerFinder.findCallerLazy());
}
return false;
}
use of com.google.gerrit.entities.PermissionRule in project gerrit by GerritCodeReview.
the class RefControl method toRange.
private PermissionRange toRange(String permissionName, boolean isChangeOwner) {
int blockAllowMin = Integer.MIN_VALUE, blockAllowMax = Integer.MAX_VALUE;
projectLoop: for (List<Permission> ps : relevant.getBlockRules(permissionName)) {
boolean blockFound = false;
int projectBlockAllowMin = Integer.MIN_VALUE, projectBlockAllowMax = Integer.MAX_VALUE;
for (Permission p : ps) {
if (p.getExclusiveGroup()) {
for (PermissionRule pr : p.getRules()) {
if (pr.getAction() == Action.ALLOW && projectControl.match(pr, isChangeOwner)) {
// exclusive override, usually for a more specific ref.
continue projectLoop;
}
}
}
for (PermissionRule pr : p.getRules()) {
if (pr.getAction() == Action.BLOCK && projectControl.match(pr, isChangeOwner)) {
projectBlockAllowMin = pr.getMin() + 1;
projectBlockAllowMax = pr.getMax() - 1;
blockFound = true;
}
}
if (blockFound) {
for (PermissionRule pr : p.getRules()) {
if (pr.getAction() == Action.ALLOW && projectControl.match(pr, isChangeOwner)) {
projectBlockAllowMin = pr.getMin();
projectBlockAllowMax = pr.getMax();
break;
}
}
break;
}
}
blockAllowMin = Math.max(projectBlockAllowMin, blockAllowMin);
blockAllowMax = Math.min(projectBlockAllowMax, blockAllowMax);
}
int voteMin = 0, voteMax = 0;
for (PermissionRule pr : relevant.getAllowRules(permissionName)) {
if (pr.getAction() == PermissionRule.Action.ALLOW && projectControl.match(pr, isChangeOwner)) {
// For votes, contrary to normal permissions, we aggregate all applicable rules.
voteMin = Math.min(voteMin, pr.getMin());
voteMax = Math.max(voteMax, pr.getMax());
}
}
return new PermissionRange(permissionName, /* min= */
Math.max(voteMin, blockAllowMin), /* max= */
Math.min(voteMax, blockAllowMax));
}
use of com.google.gerrit.entities.PermissionRule in project gerrit by GerritCodeReview.
the class PermissionRuleSerializerTest method roundTrip.
@Test
public void roundTrip() {
PermissionRule permissionRuleAutoValue = PermissionRule.builder(GroupReference.create("name")).setAction(PermissionRule.Action.BATCH).setForce(!PermissionRule.DEF_FORCE).setMax(321).setMin(123).build();
assertThat(deserialize(serialize(permissionRuleAutoValue))).isEqualTo(permissionRuleAutoValue);
}
Aggregations