]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6487 WS permissions/search_project_permissions do not return component copies...
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 2 Sep 2015 15:48:16 +0000 (17:48 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Wed, 2 Sep 2015 15:48:24 +0000 (17:48 +0200)
server/sonar-server/src/main/resources/org/sonar/server/permission/ws/search_project_permissions-example.json
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
sonar-db/src/main/java/org/sonar/db/component/ComponentDao.java
sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml
sonar-db/src/test/java/org/sonar/db/component/ComponentTesting.java

index e3436b66386b00cc9523db51583b161d9a13fc7e..724353519c396436abf7574958b1c47e40e220d2 100644 (file)
@@ -1,4 +1,9 @@
 {
+  "paging": {
+    "pageIndex": 1,
+    "pageSize": 25,
+    "total": 4
+  },
   "projects": [
     {
       "id": "0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a",
       "name": "See Source Code",
       "description": "Ability to view the project\u0027s source code. (Users will also need \"Browse\" permission)"
     }
-  ],
-  "paging": {
-    "pageIndex": 1,
-    "pageSize": 25,
-    "total": 4
-  }
+  ]
 }
index 86db252ba226dcfdf957ccdbc5d37c55677ec268..3cf1281ca5d541e0d1c761b5d21101aafd987445 100644 (file)
@@ -55,6 +55,7 @@ import static org.sonar.api.server.ws.WebService.Param.PAGE;
 import static org.sonar.api.server.ws.WebService.Param.PAGE_SIZE;
 import static org.sonar.api.server.ws.WebService.Param.TEXT_QUERY;
 import static org.sonar.db.component.ComponentTesting.newDeveloper;
+import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.component.ComponentTesting.newView;
 import static org.sonar.db.user.GroupTesting.newGroupDto;
@@ -104,6 +105,7 @@ public class SearchProjectPermissionsActionTest {
     ComponentDto project2 = insertClang();
     ComponentDto dev = insertDeveloper();
     ComponentDto view = insertView();
+    insertProjectInView(jdk7, view);
 
     insertUserRole(UserRole.ISSUE_ADMIN, user1.getId(), jdk7.getId());
     insertUserRole(UserRole.ADMIN, user1.getId(), jdk7.getId());
@@ -256,6 +258,10 @@ public class SearchProjectPermissionsActionTest {
       .setKey("Java"));
   }
 
+  private ComponentDto insertProjectInView(ComponentDto project, ComponentDto view) {
+    return insertComponent(newProjectCopy("project-in-view-uuid", project, view));
+  }
+
   private ComponentDto insertDeveloper() {
     return insertComponent(newDeveloper("Simon Brandhof")
       .setUuid("4e607bf9-7ed0-484a-946d-d58ba7dab2fb")
index 7e334fd864e5d73524f80b7ccbab85b024f5c61a..4b753923e859ba07527c0be35d08ebef41f73712 100644 (file)
@@ -178,6 +178,9 @@ public class ComponentDao implements Dao {
     return mapper(session).selectProjects();
   }
 
+  /**
+   * Does not return component copies
+   */
   public List<ComponentDto> selectComponents(DbSession session, Collection<String> qualifiers, int offset, int limit, @Nullable String query) {
     Map<String, Object> parameters = newHashMapWithExpectedSize(2);
     addProjectQualifier(parameters);
@@ -284,6 +287,7 @@ public class ComponentDao implements Dao {
   public List<ViewsComponentDto> selectViewTree(DbSession dbSession, String rootViewUuid) {
     return mapper(dbSession).selectViewTree(rootViewUuid);
   }
+
   private ComponentMapper mapper(DbSession session) {
     return session.getMapper(ComponentMapper.class);
   }
index 3dca165678b35255cb9a9613dff88a9f63f0c156..86861586b7d5efdb2403b5611fd59c6b5153c777 100644 (file)
     <include refid="componentColumns"/>
     from projects p
     <where>
-      p.enabled=${_true}
+      AND p.enabled=${_true}
+      AND p.copy_resource_id is null
       AND p.qualifier in
       <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=",">
         #{qualifier}
     from projects p
     <where>
       p.enabled=${_true}
+      AND p.copy_resource_id is null
       AND p.qualifier in
       <foreach collection="qualifiers" open="(" close=")" item="qualifier" separator=",">
         #{qualifier}
index ddbc5c345e094ed0e1598c09b989ebc7604de85e..043608fe0a9b022a466af7fb63bfdf8e5690ade2 100644 (file)
 
 package org.sonar.db.component;
 
-import com.google.common.base.Preconditions;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.Scopes;
 import org.sonar.core.util.Uuids;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import static org.sonar.db.component.ComponentDto.MODULE_UUID_PATH_SEP;
 
 public class ComponentTesting {
@@ -135,7 +135,7 @@ public class ComponentTesting {
   }
 
   public static ComponentDto newProjectCopy(String uuid, ComponentDto project, ComponentDto view) {
-    Preconditions.checkNotNull(project.getId(), "The project need to be persisted before creating this technical project.");
+    checkNotNull(project.getId(), "The project need to be persisted before creating this technical project.");
     return newChildComponent(uuid, view)
       .setUuid(uuid)
       .setKey(view.key() + project.key())
@@ -149,7 +149,7 @@ public class ComponentTesting {
   }
 
   public static ComponentDto newDevProjectCopy(String uuid, ComponentDto project, ComponentDto developer) {
-    Preconditions.checkNotNull(project.getId(), "The project need to be persisted before creating this technical project.");
+    checkNotNull(project.getId(), "The project need to be persisted before creating this technical project.");
     return newChildComponent(uuid, developer)
       .setUuid(uuid)
       .setKey(developer.key() + ":" + project.key())