Merge branch 'stable-2.14' into stable-2.15
* stable-2.14:
Automatically format BUILD file with buildifier lint mode
Change-Id: I81c66f2b7b4ea043f505fd039afcc7e5ff4dbdfe
diff --git a/WORKSPACE b/WORKSPACE
index 8c41b35..e23551a 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "2c39029a585bd1d5b785150948f162730f7b7e42",
+ commit = "ca34f0cf89b2e041ea7f4aa4b9696efc2d76746f",
#local_path = "/home/<user>/projects/bazlets",
)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java b/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java
index 93f594b..edc2a12 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/emoticons/GetPreference.java
@@ -14,12 +14,16 @@
package com.googlesource.gerrit.plugins.emoticons;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
+
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.config.ConfigResource;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -34,23 +38,26 @@
private final ProjectCache projectCache;
private final String pluginName;
private final Provider<GetConfig> getConfig;
+ private final PermissionBackend permissionBackend;
@Inject
GetPreference(
Provider<IdentifiedUser> self,
ProjectCache projectCache,
@PluginName String pluginName,
- Provider<GetConfig> getConfig) {
+ Provider<GetConfig> getConfig,
+ PermissionBackend permissionBackend) {
this.self = self;
this.projectCache = projectCache;
this.pluginName = pluginName;
this.getConfig = getConfig;
+ this.permissionBackend = permissionBackend;
}
@Override
- public ConfigInfo apply(AccountResource rsrc) throws AuthException {
- if (self.get() != rsrc.getUser() && !self.get().getCapabilities().canAdministrateServer()) {
- throw new AuthException("not allowed to get preference");
+ public ConfigInfo apply(AccountResource rsrc) throws AuthException, PermissionBackendException {
+ if (self.get() != rsrc.getUser()) {
+ permissionBackend.user(self).check(ADMINISTRATE_SERVER);
}
ConfigInfo globalCfg = getConfig.get().apply(new ConfigResource());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java b/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java
index db0d804..d3bcd91 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.emoticons;
+import static com.google.gerrit.server.permissions.GlobalPermission.ADMINISTRATE_SERVER;
import static com.googlesource.gerrit.plugins.emoticons.GetPreference.KEY_SHOW_EMOTICONS;
import static com.googlesource.gerrit.plugins.emoticons.GetPreference.PREFERENCE;
@@ -26,6 +27,8 @@
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.git.MetaDataUpdate;
import com.google.gerrit.server.git.ProjectLevelConfig;
+import com.google.gerrit.server.permissions.PermissionBackend;
+import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject;
import com.google.inject.Provider;
@@ -39,24 +42,28 @@
private final ProjectCache projectCache;
private final MetaDataUpdate.User metaDataUpdateFactory;
private final String pluginName;
+ private final PermissionBackend permissionBackend;
@Inject
PutPreference(
Provider<IdentifiedUser> self,
ProjectCache projectCache,
MetaDataUpdate.User metaDataUpdateFactory,
- @PluginName String pluginName) {
+ @PluginName String pluginName,
+ PermissionBackend permissionBackend) {
this.self = self;
this.projectCache = projectCache;
this.metaDataUpdateFactory = metaDataUpdateFactory;
this.pluginName = pluginName;
+ this.permissionBackend = permissionBackend;
}
@Override
public Response<String> apply(AccountResource rsrc, Input input)
- throws AuthException, RepositoryNotFoundException, IOException, UnprocessableEntityException {
- if (self.get() != rsrc.getUser() && !self.get().getCapabilities().canAdministrateServer()) {
- throw new AuthException("not allowed to change preference");
+ throws AuthException, RepositoryNotFoundException, IOException, UnprocessableEntityException,
+ PermissionBackendException {
+ if (self.get() != rsrc.getUser()) {
+ permissionBackend.user(self).check(ADMINISTRATE_SERVER);
}
if (input == null) {
input = new Input();