]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6947 api/permissions/remove_group_from_template use RemoveGroupFromTemplateWsRe...
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 12 Nov 2015 15:59:54 +0000 (16:59 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 17 Nov 2015 12:41:01 +0000 (13:41 +0100)
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveGroupFromTemplateAction.java
sonar-ws/src/main/java/org/sonarqube/ws/client/permission/PermissionsWsClient.java
sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveGroupFromTemplateWsRequest.java [new file with mode: 0644]

index a79f6877298a90023bc8b92f983d65f6352b5a9d..2ea303c3ef698c993badaa9b32f5b24c05dfd332 100644 (file)
@@ -29,17 +29,23 @@ import org.sonar.db.permission.PermissionTemplateDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.server.permission.ws.PermissionDependenciesFinder;
 import org.sonar.server.permission.ws.PermissionsWsAction;
-import org.sonar.server.usergroups.ws.WsGroupRef;
-import org.sonar.server.permission.ws.WsTemplateRef;
 import org.sonar.server.user.UserSession;
+import org.sonar.server.usergroups.ws.WsGroupRef;
+import org.sonarqube.ws.client.permission.RemoveGroupFromTemplateWsRequest;
 
 import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
-import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
 import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupIdParameter;
 import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createGroupNameParameter;
 import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectPermissionParameter;
 import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters;
-import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
+import static org.sonar.server.permission.ws.WsTemplateRef.newTemplateRef;
+import static org.sonar.server.usergroups.ws.WsGroupRef.newWsGroupRef;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
 
 public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
   private final DbClient dbClient;
@@ -70,17 +76,21 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
   }
 
   @Override
-  public void handle(Request wsRequest, Response wsResponse) throws Exception {
+  public void handle(Request request, Response response) throws Exception {
     checkGlobalAdminUser(userSession);
+    doHandle(toRemoveGroupFromTemplateWsRequest(request));
+    response.noContent();
+  }
 
-    String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
-    WsGroupRef group = WsGroupRef.newWsGroupRefFromPermissionRequest(wsRequest);
+  private void doHandle(RemoveGroupFromTemplateWsRequest request) {
+    String permission = request.getPermission();
+    Long groupIdInRequest = request.getGroupId() == null ? null : Long.valueOf(request.getGroupId());
+    WsGroupRef group = newWsGroupRef(groupIdInRequest, request.getGroupName());
 
     DbSession dbSession = dbClient.openSession(false);
     try {
       validateProjectPermission(permission);
-
-      PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, WsTemplateRef.fromRequest(wsRequest));
+      PermissionTemplateDto template = dependenciesFinder.getTemplate(dbSession, newTemplateRef(request.getTemplateId(), request.getTemplateName()));
       GroupDto groupDto = dependenciesFinder.getGroup(dbSession, group);
 
       Long groupId = groupDto == null ? null : groupDto.getId();
@@ -88,7 +98,14 @@ public class RemoveGroupFromTemplateAction implements PermissionsWsAction {
     } finally {
       dbClient.closeSession(dbSession);
     }
+  }
 
-    wsResponse.noContent();
+  private static RemoveGroupFromTemplateWsRequest toRemoveGroupFromTemplateWsRequest(Request request) {
+    return new RemoveGroupFromTemplateWsRequest()
+      .setPermission(request.mandatoryParam(PARAM_PERMISSION))
+      .setGroupId(request.param(PARAM_GROUP_ID))
+      .setGroupName(request.param(PARAM_GROUP_NAME))
+      .setTemplateId(request.param(PARAM_TEMPLATE_ID))
+      .setTemplateName(request.param(PARAM_TEMPLATE_NAME));
   }
 }
index 5db97477bd1e312f526aad96a48e3f13a24a17e1..f8844c287e0ad549eb4b8c3cd96aa94a2ac2f515 100644 (file)
@@ -123,6 +123,15 @@ public class PermissionsWsClient {
       .setParam(PARAM_PROJECT_KEY, request.getProjectKey()));
   }
 
+  public void removeGroupFromTemplate(RemoveGroupFromTemplateWsRequest request) {
+    wsClient.execute(newPostRequest(action("remove_group_from_template"))
+      .setParam(PARAM_PERMISSION, request.getPermission())
+      .setParam(PARAM_GROUP_ID, request.getGroupId())
+      .setParam(PARAM_GROUP_NAME, request.getGroupName())
+      .setParam(PARAM_TEMPLATE_ID, request.getTemplateId())
+      .setParam(PARAM_TEMPLATE_NAME, request.getTemplateName()));
+  }
+
   private static String action(String action) {
     return PermissionsWsParameters.ENDPOINT + "/" + action;
   }
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveGroupFromTemplateWsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveGroupFromTemplateWsRequest.java
new file mode 100644 (file)
index 0000000..48b48e3
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.permission;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+import static java.util.Objects.requireNonNull;
+
+public class RemoveGroupFromTemplateWsRequest {
+  private String permission;
+  private String groupId;
+  private String groupName;
+  private String templateId;
+  private String templateName;
+
+  public String getPermission() {
+    return permission;
+  }
+
+  public RemoveGroupFromTemplateWsRequest setPermission(String permission) {
+    this.permission = requireNonNull(permission);
+    return this;
+  }
+
+  @CheckForNull
+  public String getGroupId() {
+    return groupId;
+  }
+
+  public RemoveGroupFromTemplateWsRequest setGroupId(@Nullable String groupId) {
+    this.groupId = groupId;
+    return this;
+  }
+
+  @CheckForNull
+  public String getGroupName() {
+    return groupName;
+  }
+
+  public RemoveGroupFromTemplateWsRequest setGroupName(@Nullable String groupName) {
+    this.groupName = groupName;
+    return this;
+  }
+
+  @CheckForNull
+  public String getTemplateId() {
+    return templateId;
+  }
+
+  public RemoveGroupFromTemplateWsRequest setTemplateId(@Nullable String templateId) {
+    this.templateId = templateId;
+    return this;
+  }
+
+  @CheckForNull
+  public String getTemplateName() {
+    return templateName;
+  }
+
+  public RemoveGroupFromTemplateWsRequest setTemplateName(@Nullable String templateName) {
+    this.templateName = templateName;
+    return this;
+  }
+}