summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Hiesel <hiesel@google.com>2017-08-09 14:42:21 +0200
committerPatrick Hiesel <hiesel@google.com>2017-08-16 14:56:01 +0200
commit35d87c092ea7ef55085f2608917a85b2bd909b2f (patch)
treed5af1c1d125de29b552d4a056e04bab75859e610
parent0721b208ad863ff2f2c7fe1c89950dc2b921abaa (diff)
Refactor callers of RefControl#isVisible
This commit refactors callers to use PermissionBackend instead of RefControl#isVisible and adds handling for PermissionBackendException on EventDispatcher#postEvent. Change-Id: Ic6378b0fd88cc770b061c551d0511d352a9f3d61
-rw-r--r--src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index 6fbff98..1bbb0d7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -48,6 +48,7 @@ import com.google.gerrit.server.git.WorkQueue;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.permissions.ProjectPermission;
+import com.google.gerrit.server.permissions.RefPermission;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.PerRequestProjectControlCache;
import com.google.gerrit.server.project.ProjectControl;
@@ -126,7 +127,7 @@ public class Destination {
this.permissionBackend = permissionBackend;
this.stateLog = stateLog;
- final CurrentUser remoteUser;
+ CurrentUser remoteUser;
if (!cfg.getAuthGroupNames().isEmpty()) {
ImmutableSet.Builder<AccountGroup.UUID> builder = ImmutableSet.builder();
for (String name : cfg.getAuthGroupNames()) {
@@ -246,9 +247,22 @@ public class Destination {
@Override
public Boolean call() throws NoSuchProjectException, PermissionBackendException {
ProjectControl projectControl = controlFor(project);
- return shouldReplicate(projectControl)
- && (PushOne.ALL_REFS.equals(ref)
- || projectControl.controlForRef(ref).isVisible());
+ if (!shouldReplicate(projectControl)) {
+ return false;
+ }
+ if (PushOne.ALL_REFS.equals(ref)) {
+ return true;
+ }
+ try {
+ permissionBackend
+ .user(projectControl.getUser())
+ .project(project)
+ .ref(ref)
+ .check(RefPermission.READ);
+ } catch (AuthException e) {
+ return false;
+ }
+ return true;
}
})
.call();
@@ -616,7 +630,11 @@ public class Destination {
for (String ref : refs) {
ReplicationScheduledEvent event =
new ReplicationScheduledEvent(project.get(), ref, targetNode);
- eventDispatcher.get().postEvent(new Branch.NameKey(project, ref), event);
+ try {
+ eventDispatcher.get().postEvent(new Branch.NameKey(project, ref), event);
+ } catch (PermissionBackendException e) {
+ repLog.error("error posting event", e);
+ }
}
}
@@ -626,7 +644,11 @@ public class Destination {
for (String ref : pushOp.getRefs()) {
RefReplicatedEvent event =
new RefReplicatedEvent(project.get(), ref, targetNode, RefPushResult.FAILED, status);
- eventDispatcher.get().postEvent(new Branch.NameKey(project, ref), event);
+ try {
+ eventDispatcher.get().postEvent(new Branch.NameKey(project, ref), event);
+ } catch (PermissionBackendException e) {
+ repLog.error("error posting event", e);
+ }
}
}
}