]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 6 Oct 2015 09:38:58 +0000 (11:38 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 6 Oct 2015 09:43:47 +0000 (11:43 +0200)
server/sonar-server/src/main/java/org/sonar/server/batch/Messages.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
server/sonar-server/src/main/java/org/sonar/server/permission/PermissionService.java
server/sonar-server/src/main/java/org/sonar/server/permission/ws/template/DefaultPermissionTemplateFinder.java
server/sonar-server/src/main/java/org/sonar/server/usergroups/ws/UserGroupsWsParameters.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java [new file with mode: 0644]

index 71c877da1105f7891e912f5ece6964918537267f..40e0518357706b2b25c30b419bb34b08356ce480 100644 (file)
@@ -24,5 +24,5 @@ public class Messages {
     // constants
   }
 
-  static String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.";
+  static final String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator.";
 }
index 2dbe0d3611ddeca5ceb9a4a7a95e7087c34a0167..b9454a2545dd2fecb0cecb86cfe753ef125dc556 100644 (file)
@@ -88,7 +88,7 @@ public class ComponentFinder {
     return component.get();
   }
 
-  private void checkIsProjectOrModule(ComponentDto component, ResourceTypes resourceTypes) {
+  private static void checkIsProjectOrModule(ComponentDto component, ResourceTypes resourceTypes) {
     Set<String> rootQualifiers = from(resourceTypes.getRoots())
       .transform(RESOURCE_TYPE_TO_QUALIFIER)
       .toSet();
index 5e18899fc336cf5420f8752bedea37af09ef9f36..ed223457c31202f85766e10f2126e74b285ca478 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.permission;
 
 import java.util.List;
 import org.sonar.api.server.ServerSide;
-import org.sonar.api.web.UserRole;
 import org.sonar.core.permission.GlobalPermissions;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -30,7 +29,6 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ResourceDto;
 import org.sonar.db.permission.PermissionRepository;
 import org.sonar.server.component.ComponentFinder;
-import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.issue.index.IssueAuthorizationIndexer;
 import org.sonar.server.user.UserSession;
 
@@ -73,7 +71,7 @@ public class PermissionService {
     ComponentDto component = componentFinder.getByKey(session, componentKey);
     ResourceDto provisioned = dbClient.resourceDao().selectProvisionedProject(session, componentKey);
     if (provisioned == null) {
-      checkProjectAdminPermission(componentKey);
+      checkProjectAdminUserByComponentKey(userSession, componentKey);
     } else {
       userSession.checkGlobalPermission(GlobalPermissions.PROVISIONING);
     }
@@ -106,12 +104,6 @@ public class PermissionService {
     indexProjectPermissions();
   }
 
-  private void checkProjectAdminPermission(String projectKey) {
-    if (!userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN) && !userSession.hasProjectPermission(UserRole.ADMIN, projectKey)) {
-      throw new ForbiddenException("Insufficient privileges");
-    }
-  }
-
   private void indexProjectPermissions() {
     issueAuthorizationIndexer.index();
   }
index f309355ff53c0914db0b0b7c314c3d5d051eb9a7..196b8bf537d450853453a1d1c470e1a663e0be73 100644 (file)
@@ -30,9 +30,9 @@ import org.sonar.api.resources.ResourceTypes;
 
 import static com.google.common.collect.FluentIterable.from;
 import static com.google.common.collect.Ordering.natural;
+import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
 import static org.sonar.server.permission.DefaultPermissionTemplates.DEFAULT_TEMPLATE_PROPERTY;
 import static org.sonar.server.permission.DefaultPermissionTemplates.defaultRootQualifierTemplateProperty;
-import static org.sonar.server.component.ResourceTypeFunctions.RESOURCE_TYPE_TO_QUALIFIER;
 
 public class DefaultPermissionTemplateFinder {
   private final Settings settings;
@@ -84,8 +84,7 @@ public class DefaultPermissionTemplateFinder {
 
     @Override
     public String apply(@Nonnull String qualifier) {
-      String effectiveTemplateUuid = effectiveTemplateUuid(settings, qualifier);
-      return effectiveTemplateUuid;
+      return effectiveTemplateUuid(settings, qualifier);
     }
   }
 
index 8b0550352ea9d4ae88cf3878ad9b8faf65b8b42d..d40d245f05230bd7fa1e2a1ab907b9b47f115386 100644 (file)
@@ -28,6 +28,10 @@ public class UserGroupsWsParameters {
   static final String PARAM_GROUP_ID = "id";
   static final String PARAM_LOGIN = "login";
 
+  private UserGroupsWsParameters() {
+    // static methods only
+  }
+
   static void createGroupParameters(NewAction action) {
     createGroupIdParameter(action);
     createGroupNameParameter(action);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/template/SearchTemplatesDataTest.java
new file mode 100644 (file)
index 0000000..08c63a3
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * 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.sonar.server.permission.ws.template;
+
+import com.google.common.collect.HashBasedTable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.resources.Qualifiers;
+
+import static java.util.Collections.singletonList;
+import static org.sonar.db.permission.PermissionTemplateTesting.newPermissionTemplateDto;
+
+public class SearchTemplatesDataTest {
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  SearchTemplatesData.Builder underTest = SearchTemplatesData.newBuilder()
+    .defaultTemplates(singletonList(new DefaultPermissionTemplateFinder.TemplateUuidQualifier("template_uuid", Qualifiers.PROJECT)))
+    .templates(singletonList(newPermissionTemplateDto()))
+    .userCountByTemplateIdAndPermission(HashBasedTable.<Long, String, Integer>create())
+    .groupCountByTemplateIdAndPermission(HashBasedTable.<Long, String, Integer>create());
+
+  @Test
+  public void fail_if_templates_is_null() {
+    expectedException.expect(IllegalStateException.class);
+    underTest.templates(null);
+
+    underTest.build();
+  }
+
+  @Test
+  public void fail_if_default_templates_are_null() {
+    expectedException.expect(IllegalStateException.class);
+    underTest.defaultTemplates(null);
+
+    underTest.build();
+  }
+
+  @Test
+  public void fail_if_user_count_is_null() {
+    expectedException.expect(IllegalStateException.class);
+    underTest.userCountByTemplateIdAndPermission(null);
+
+    underTest.build();
+  }
+
+  @Test
+  public void fail_if_group_count_is_null() {
+    expectedException.expect(IllegalStateException.class);
+    underTest.groupCountByTemplateIdAndPermission(null);
+
+    underTest.build();
+  }
+}