]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8276 organization in WS api/permissions/remove_project_creator_from_template
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 16 Oct 2016 21:08:15 +0000 (23:08 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 16 Oct 2016 21:16:39 +0000 (23:16 +0200)
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateAction.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/RemoveProjectCreatorFromTemplateActionTest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/permission/RemoveProjectCreatorFromTemplateWsRequest.java

index e71bdf7cde24efa3e5d3896d601379e6d6275e1d..3d9cbec8537044037b72a385f4de58693e481040 100644 (file)
@@ -35,10 +35,11 @@ import org.sonar.server.permission.ws.PermissionsWsAction;
 import org.sonar.server.user.UserSession;
 import org.sonarqube.ws.client.permission.RemoveProjectCreatorFromTemplateWsRequest;
 
-import static org.sonar.server.permission.PermissionPrivilegeChecker.checkGlobalAdminUser;
+import static org.sonar.server.permission.PermissionPrivilegeChecker.checkProjectAdmin;
 import static org.sonar.server.permission.ws.PermissionRequestValidator.validateProjectPermission;
 import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createProjectPermissionParameter;
 import static org.sonar.server.permission.ws.PermissionsWsParametersBuilder.createTemplateParameters;
+import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ORGANIZATION_KEY;
 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;
@@ -71,14 +72,16 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
 
   @Override
   public void handle(Request request, Response response) throws Exception {
-    checkGlobalAdminUser(userSession);
     doHandle(toWsRequest(request));
     response.noContent();
   }
 
   private void doHandle(RemoveProjectCreatorFromTemplateWsRequest request) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(request.getTemplateId(), request.getTemplateName()));
+      PermissionTemplateDto template = wsSupport.findTemplate(dbSession, WsTemplateRef.newTemplateRef(
+        request.getTemplateId(), request.getOrganization(), request.getTemplateName()));
+      checkProjectAdmin(userSession, template.getOrganizationUuid(), Optional.empty());
+
       PermissionTemplateCharacteristicDao dao = dbClient.permissionTemplateCharacteristicDao();
       Optional<PermissionTemplateCharacteristicDto> templatePermission = dao.selectByPermissionAndTemplateId(dbSession, request.getPermission(), template.getId());
       if (templatePermission.isPresent()) {
@@ -99,6 +102,7 @@ public class RemoveProjectCreatorFromTemplateAction implements PermissionsWsActi
     RemoveProjectCreatorFromTemplateWsRequest wsRequest = RemoveProjectCreatorFromTemplateWsRequest.builder()
       .setPermission(request.mandatoryParam(PARAM_PERMISSION))
       .setTemplateId(request.param(PARAM_TEMPLATE_ID))
+      .setOrganization(request.param(PARAM_ORGANIZATION_KEY))
       .setTemplateName(request.param(PARAM_TEMPLATE_NAME))
       .build();
     validateProjectPermission(wsRequest.getPermission());
index cb8c2ac3dbbd1a8cfc3a5ddb9b21a1b9050ae851..4d0a419e2bf6e79bc5091ec763a15ad53732a184 100644 (file)
@@ -55,7 +55,7 @@ public class RemoveProjectCreatorFromTemplateActionTest extends BasePermissionWs
 
   @Before
   public void setUp() {
-    userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+    loginAsAdminOnDefaultOrganization();
     when(system.now()).thenReturn(2_000_000_000L);
     template = insertTemplate();
   }
index 7cb87736828b2500966f5f47a33067e0a66df1a7..798374831ccfaac2d019e83e5f5e22d37f586902 100644 (file)
@@ -26,11 +26,13 @@ import static java.util.Objects.requireNonNull;
 
 public class RemoveProjectCreatorFromTemplateWsRequest {
   private final String templateId;
+  private final String organization;
   private final String templateName;
   private final String permission;
 
   private RemoveProjectCreatorFromTemplateWsRequest(Builder builder) {
     this.templateId = builder.templateId;
+    this.organization = builder.organization;
     this.templateName = builder.templateName;
     this.permission = requireNonNull(builder.permission);
   }
@@ -40,6 +42,11 @@ public class RemoveProjectCreatorFromTemplateWsRequest {
     return templateId;
   }
 
+  @CheckForNull
+  public String getOrganization() {
+    return organization;
+  }
+
   @CheckForNull
   public String getTemplateName() {
     return templateName;
@@ -55,6 +62,7 @@ public class RemoveProjectCreatorFromTemplateWsRequest {
 
   public static class Builder {
     private String templateId;
+    private String organization;
     private String templateName;
     private String permission;
 
@@ -67,6 +75,11 @@ public class RemoveProjectCreatorFromTemplateWsRequest {
       return this;
     }
 
+    public Builder setOrganization(String s) {
+      this.organization = s;
+      return this;
+    }
+
     public Builder setTemplateName(String templateName) {
       this.templateName = templateName;
       return this;