Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
AbstractEventProcessorTest: Rename parameter to avoid hiding
UpdateRemoteIT: Add missing @Override annotation
GetRemoteIT: Remove declaration of unthrown exception
Add Eclipse compiler settings
Change-Id: I6e6089801819bc84a251b931f54ab3703a2294ab
diff --git a/WORKSPACE b/WORKSPACE
index 7dfa6ac..4226923 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "0cdf281f110834b71ae134afe0a7e3fe346f0078",
+ commit = "6d3fd710ea4ca44805bb8c858d72b53bd3a500f3",
)
#Snapshot Plugin API
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/PermissionsImpl.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/PermissionsImpl.java
index b07f540..7f99366 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/PermissionsImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/PermissionsImpl.java
@@ -16,9 +16,11 @@
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CONFIG;
+import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.CurrentUser;
-import com.google.gerrit.server.project.ProjectCache;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.RefPermission;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -26,30 +28,29 @@
@Singleton
public class PermissionsImpl implements Permissions {
- private final ProjectCache projectCache;
+ private final PermissionBackend permissionBackend;
private final Provider<CurrentUser> currentUser;
@Inject
- PermissionsImpl(ProjectCache projectCache, Provider<CurrentUser> currentUser) {
- this.projectCache = projectCache;
+ PermissionsImpl(PermissionBackend permissionBackend, Provider<CurrentUser> currentUser) {
+ this.permissionBackend = permissionBackend;
this.currentUser = currentUser;
}
@Override
public boolean canRead(Project.NameKey project) {
- return projectCache
- .get(project)
- .controlFor(currentUser.get())
- .controlForRef(REFS_CONFIG)
- .isVisible();
+ return can(project, RefPermission.READ);
}
@Override
public boolean canUpdate(Project.NameKey project) {
- return projectCache
- .get(project)
- .controlFor(currentUser.get())
- .controlForRef(REFS_CONFIG)
- .canUpdate();
+ return can(project, RefPermission.UPDATE);
+ }
+
+ private boolean can(Project.NameKey project, RefPermission permission) {
+ return permissionBackend
+ .user(currentUser.get())
+ .ref(new Branch.NameKey(project, REFS_CONFIG))
+ .testOrFalse(permission);
}
}