Line data Source code
1 : // Copyright (C) 2013 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.restapi.project; 16 : 17 : import com.google.gerrit.extensions.api.projects.ConfigInfo; 18 : import com.google.gerrit.extensions.registration.DynamicMap; 19 : import com.google.gerrit.extensions.restapi.Response; 20 : import com.google.gerrit.extensions.restapi.RestReadView; 21 : import com.google.gerrit.extensions.restapi.RestView; 22 : import com.google.gerrit.server.EnableSignedPush; 23 : import com.google.gerrit.server.config.AllProjectsName; 24 : import com.google.gerrit.server.config.PluginConfigFactory; 25 : import com.google.gerrit.server.config.ProjectConfigEntry; 26 : import com.google.gerrit.server.extensions.webui.UiActions; 27 : import com.google.gerrit.server.permissions.PermissionBackend; 28 : import com.google.gerrit.server.permissions.PermissionBackendException; 29 : import com.google.gerrit.server.permissions.ProjectPermission; 30 : import com.google.gerrit.server.project.ProjectResource; 31 : import com.google.inject.Inject; 32 : import com.google.inject.Singleton; 33 : 34 : @Singleton 35 : public class GetConfig implements RestReadView<ProjectResource> { 36 : private final boolean serverEnableSignedPush; 37 : private final DynamicMap<ProjectConfigEntry> pluginConfigEntries; 38 : private final PluginConfigFactory cfgFactory; 39 : private final AllProjectsName allProjects; 40 : private final PermissionBackend permissionBackend; 41 : private final UiActions uiActions; 42 : private final DynamicMap<RestView<ProjectResource>> views; 43 : 44 : @Inject 45 : public GetConfig( 46 : @EnableSignedPush boolean serverEnableSignedPush, 47 : DynamicMap<ProjectConfigEntry> pluginConfigEntries, 48 : PluginConfigFactory cfgFactory, 49 : AllProjectsName allProjects, 50 : PermissionBackend permissionBackend, 51 : UiActions uiActions, 52 146 : DynamicMap<RestView<ProjectResource>> views) { 53 146 : this.serverEnableSignedPush = serverEnableSignedPush; 54 146 : this.pluginConfigEntries = pluginConfigEntries; 55 146 : this.allProjects = allProjects; 56 146 : this.cfgFactory = cfgFactory; 57 146 : this.permissionBackend = permissionBackend; 58 146 : this.uiActions = uiActions; 59 146 : this.views = views; 60 146 : } 61 : 62 : @Override 63 : public Response<ConfigInfo> apply(ProjectResource resource) throws PermissionBackendException { 64 3 : boolean readConfigAllowed = 65 : permissionBackend 66 3 : .currentUser() 67 3 : .project(resource.getNameKey()) 68 3 : .test(ProjectPermission.READ_CONFIG); 69 3 : return Response.ok( 70 3 : ConfigInfoCreator.constructInfo( 71 : serverEnableSignedPush, 72 3 : resource.getProjectState(), 73 3 : resource.getUser(), 74 3 : readConfigAllowed ? pluginConfigEntries : DynamicMap.emptyMap(), 75 : cfgFactory, 76 : allProjects, 77 : uiActions, 78 : views)); 79 : } 80 : }