Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
Upgrade bazlets to latest stable-2.14 to build with 2.14.20 API
Change-Id: I56f2f827fa55682fb0857e785364bfc119411c9d
diff --git a/WORKSPACE b/WORKSPACE
index ba2b9a1..af1215e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "39310fb43f4eaaad2e338b3bcbf393a2f4e11293",
+ 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());
}