Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  Upgrade mockito-core to 2.27.0

Change-Id: I9bede8e7cd3c93525d78af23462740585df5e7f2
diff --git a/WORKSPACE b/WORKSPACE
index 7a8a9bf..af1215e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "8d7664e169100e537340aed89345c3245cf12f22",
+    commit = "8386b3fbf80e375f0a10c8386c0a8dfe260c5c1b",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
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);
   }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java
index ef96108..4f1508c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/webhooks/rest/RemotesCollection.java
@@ -82,7 +82,6 @@
   }
 
   @Override
-  @SuppressWarnings("unchecked")
   public UpsertRemote.Inserter create(ProjectWebhooksResource parent, IdString id) {
     return inserterFactory.create(id.get());
   }