]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR−9105 add ProjectsService#changeVisibility
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 21 Apr 2017 14:06:56 +0000 (16:06 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:25:54 +0000 (14:25 +0200)
server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
sonar-ws/src/main/java/org/sonarqube/ws/client/project/ProjectsService.java
sonar-ws/src/main/java/org/sonarqube/ws/client/project/UpdateVisibilityRequest.java [new file with mode: 0644]

index 6f37b1f70e0680e19847ac3d1fbc8c362a073df6..df819ed4de54d9609fb9ce385fbf3980ad230860 100644 (file)
@@ -119,7 +119,7 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
   private void updatePermissionsToPrivate(DbSession dbSession, ComponentDto component) {
     // delete project permissions for group AnyOne
     dbClient.groupPermissionDao().deleteByRootComponentIdAndGroupId(dbSession, component.getId(), null);
-    // grant UserRole.CODEVIEWER and UserRole.USER
+    // grant UserRole.CODEVIEWER and UserRole.USER to any group or user with at least one permission on project
     PUBLIC_PERMISSIONS.forEach(permission -> {
       dbClient.groupPermissionDao().selectGroupIdsWithPermissionOnProjectBut(dbSession, component.getId(), permission)
         .forEach(groupId -> insertProjectPermissionOnGroup(dbSession, component, permission, groupId));
index 72b3fed9e558962c04babe25441ffcee8ad2ddd1..42659383338f5ec43e6bfa2163672a9aac9edfb7 100644 (file)
@@ -106,4 +106,12 @@ public class ProjectsService extends BaseService {
       .setParam(PAGE_SIZE, request.getPageSize());
     return call(get, SearchWsResponse.parser());
   }
+
+  public void updateVisibility(UpdateVisibilityRequest request) {
+    PostRequest post = new PostRequest(path("update_visibility"))
+        .setParam(PARAM_PROJECT, request.getProject())
+        .setParam("visibility", request.getVisibility());
+
+    call(post);
+  }
 }
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/project/UpdateVisibilityRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/project/UpdateVisibilityRequest.java
new file mode 100644 (file)
index 0000000..804ccdc
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonarqube.ws.client.project;
+
+public class UpdateVisibilityRequest {
+  private final String project;
+  private final String visibility;
+
+  public enum Visibility {
+    PUBLIC, PRIVATE
+  }
+
+  public UpdateVisibilityRequest(String project, Visibility visibility) {
+    this.project = project;
+    this.visibility = visibility == Visibility.PUBLIC ? "public" : "private";
+  }
+
+  public String getProject() {
+    return project;
+  }
+
+  public String getVisibility() {
+    return visibility;
+  }
+}