Line data Source code
1 : // Copyright (C) 2012 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.plugins; 16 : 17 : import com.google.common.collect.ImmutableSet; 18 : import com.google.gerrit.extensions.common.Input; 19 : import com.google.gerrit.extensions.common.PluginInfo; 20 : import com.google.gerrit.extensions.restapi.MethodNotAllowedException; 21 : import com.google.gerrit.extensions.restapi.Response; 22 : import com.google.gerrit.extensions.restapi.RestApiException; 23 : import com.google.gerrit.extensions.restapi.RestModifyView; 24 : import com.google.gerrit.server.permissions.GlobalPermission; 25 : import com.google.gerrit.server.permissions.PermissionBackend; 26 : import com.google.gerrit.server.permissions.PermissionBackendException; 27 : import com.google.inject.Inject; 28 : import com.google.inject.Singleton; 29 : 30 : @Singleton 31 : public class DisablePlugin implements RestModifyView<PluginResource, Input> { 32 : 33 : private final PluginLoader loader; 34 : private final PermissionBackend permissionBackend; 35 : private final MandatoryPluginsCollection mandatoryPluginsCollection; 36 : 37 : @Inject 38 : DisablePlugin( 39 : PluginLoader loader, 40 : PermissionBackend permissionBackend, 41 138 : MandatoryPluginsCollection mandatoryPluginsCollection) { 42 138 : this.loader = loader; 43 138 : this.permissionBackend = permissionBackend; 44 138 : this.mandatoryPluginsCollection = mandatoryPluginsCollection; 45 138 : } 46 : 47 : @Override 48 : public Response<PluginInfo> apply(PluginResource resource, Input input) 49 : throws RestApiException, PermissionBackendException { 50 2 : permissionBackend.currentUser().check(GlobalPermission.ADMINISTRATE_SERVER); 51 2 : loader.checkRemoteAdminEnabled(); 52 2 : String name = resource.getName(); 53 2 : if (mandatoryPluginsCollection.contains(name)) { 54 1 : throw new MethodNotAllowedException("Plugin " + name + " is mandatory"); 55 : } 56 2 : loader.disablePlugins(ImmutableSet.of(name)); 57 2 : return Response.ok(ListPlugins.toPluginInfo(loader.get(name))); 58 : } 59 : }