]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19445 update elasticSearch permission index
authorBenjamin Campomenosi <109955405+benjamin-campomenosi-sonarsource@users.noreply.github.com>
Sun, 11 Jun 2023 18:10:29 +0000 (20:10 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 19 Jun 2023 20:03:14 +0000 (20:03 +0000)
13 files changed:
server/sonar-db-dao/src/it/java/org/sonar/db/permission/AuthorizationDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
server/sonar-webserver-auth/src/it/java/org/sonar/server/user/ServerUserSessionIT.java
server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
server/sonar-webserver-es/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/GroupPermissionChangerIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/GroupsActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/template/ApplyTemplateActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java

index c3e8b2736552f65065b05df802b522d03ddcf00d..3215b538ed018e8dfd665dedec7fdbf04b6446aa 100644 (file)
@@ -307,7 +307,7 @@ public class AuthorizationDaoIT {
     ComponentDto otherProject = db.components().insertPublicProject().getMainBranchComponent();
     UserDto otherUser = db.users().insertUser();
     db.users().insertMember(group1, user);
-    db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
+    db.users().insertEntityPermissionOnGroup(group1, randomPermission, project);
 
     assertThat(underTest.keepAuthorizedEntityUuids(dbSession, singleton(project.getUuid()), user.getUuid(), randomPermission))
       .containsOnly(project.getUuid());
@@ -424,7 +424,7 @@ public class AuthorizationDaoIT {
     db.users().insertProjectPermissionOnUser(user, UserRole.USER, project2);
     db.users().insertProjectPermissionOnUser(user, UserRole.USER, project3);
     db.users().insertMember(group, user);
-    db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project1);
+    db.users().insertEntityPermissionOnGroup(group, UserRole.USER, project1);
 
     assertThat(underTest.keepAuthorizedEntityUuids(dbSession, newHashSet(project2.getUuid(), project3.getUuid()), user.getUuid(), UserRole.USER))
       .containsOnly(project2.getUuid(), project3.getUuid());
@@ -446,8 +446,8 @@ public class AuthorizationDaoIT {
     GroupDto group = db.users().insertGroup();
     db.users().insertMembers(group, user1);
     db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project1);
-    db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project2);
-    db.users().insertProjectPermissionOnGroup(group, UserRole.USER, project3);
+    db.users().insertEntityPermissionOnGroup(group, UserRole.USER, project2);
+    db.users().insertEntityPermissionOnGroup(group, UserRole.USER, project3);
 
     assertThat(underTest.keepAuthorizedEntityUuids(dbSession, newHashSet(project2.getUuid(), project3.getUuid()), user1.getUuid(), UserRole.USER))
       .containsOnly(project2.getUuid(), project3.getUuid());
@@ -548,7 +548,7 @@ public class AuthorizationDaoIT {
     ProjectDto otherProject = db.components().insertPublicProject().getProjectDto();
     UserDto otherUser = db.users().insertUser();
     db.users().insertMember(group1, user);
-    db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
+    db.users().insertEntityPermissionOnGroup(group1, randomPermission, project);
 
     assertThat(underTest.keepAuthorizedUsersForRoleAndEntity(dbSession, singleton(user.getUuid()), randomPermission, project.getUuid()))
       .containsOnly(user.getUuid());
@@ -629,7 +629,7 @@ public class AuthorizationDaoIT {
     ProjectDto otherProject = db.components().insertPublicProject().getProjectDto();
     UserDto otherUser = db.users().insertUser();
     db.users().insertMember(group1, user);
-    db.users().insertProjectPermissionOnGroup(group1, randomPermission, project);
+    db.users().insertEntityPermissionOnGroup(group1, randomPermission, project);
 
     assertThat(underTest.keepAuthorizedUsersForRoleAndEntity(dbSession, singleton(user.getUuid()), randomPermission, project.getUuid()))
       .containsOnly(user.getUuid());
@@ -656,7 +656,7 @@ public class AuthorizationDaoIT {
     db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project1);
     db.users().insertProjectPermissionOnUser(user2, UserRole.USER, project1);
     db.users().insertProjectPermissionOnUser(user3, UserRole.USER, project1);
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.USER, project3);
+    db.users().insertEntityPermissionOnGroup(group2, UserRole.USER, project3);
 
     assertThat(underTest.keepAuthorizedUsersForRoleAndEntity(dbSession,
       // Only 100 and 101 has 'user' role on project
@@ -764,8 +764,8 @@ public class AuthorizationDaoIT {
   @Test
   public void selectEntityPermissions_returns_permissions_of_logged_in_user_on_specified_project_through_group_membership() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.CODEVIEWER, project);
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.CODEVIEWER, project);
+    db.users().insertEntityPermissionOnGroup(group2, UserRole.ISSUE_ADMIN, project);
     db.users().insertMember(group1, user);
 
     assertThat(underTest.selectEntityPermissions(dbSession, project.getUuid(), user.getUuid())).containsOnly(UserRole.CODEVIEWER);
@@ -775,7 +775,7 @@ public class AuthorizationDaoIT {
   public void selectEntityPermissions_returns_permissions_of_logged_in_user_on_specified_private_project_through_all_possible_configurations() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     db.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, project);
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.USER, project);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.USER, project);
     db.users().insertMember(group1, user);
 
     assertThat(underTest.selectEntityPermissions(dbSession, project.getUuid(), user.getUuid())).containsOnly(UserRole.CODEVIEWER, UserRole.USER);
@@ -786,7 +786,7 @@ public class AuthorizationDaoIT {
     ProjectDto project = db.components().insertPublicProject().getProjectDto();
     db.users().insertProjectPermissionOnUser(user, "p1", project);
     db.users().insertProjectPermissionOnAnyone("p2", project);
-    db.users().insertProjectPermissionOnGroup(group1, "p3", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p3", project);
     db.users().insertMember(group1, user);
 
     assertThat(underTest.selectEntityPermissions(dbSession, project.getUuid(), user.getUuid())).containsOnly("p1", "p2", "p3");
@@ -813,7 +813,7 @@ public class AuthorizationDaoIT {
     UserDto user = db.users().insertUser();
     GroupDto group = db.users().insertGroup();
     db.users().insertMember(group, user);
-    db.users().insertProjectPermissionOnGroup(group, UserRole.ADMIN, privateProject);
+    db.users().insertEntityPermissionOnGroup(group, UserRole.ADMIN, privateProject);
 
     assertThat(underTest.keepAuthorizedEntityUuids(dbSession, newHashSet(privateProject.getUuid(), publicProject.getUuid()), user.getUuid(), UserRole.ADMIN))
       .containsOnly(privateProject.getUuid());
@@ -1029,7 +1029,7 @@ public class AuthorizationDaoIT {
     UserDto admin2 = db.users().insertUser();
     GroupDto adminGroup = db.users().insertGroup("ADMIN");
     db.users().insertMember(adminGroup, admin2);
-    db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
 
     assertThat(underTest.keepAuthorizedLoginsOnEntity(dbSession, newHashSet(user1.getLogin()), project.getKey(), UserRole.USER))
       .containsOnly(user1.getLogin());
@@ -1045,8 +1045,8 @@ public class AuthorizationDaoIT {
 
     GroupDto userGroup = db.users().insertGroup("USERS");
     GroupDto adminGroup = db.users().insertGroup("ADMIN");
-    db.users().insertProjectPermissionOnGroup(userGroup, UserRole.USER, project);
-    db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(userGroup, UserRole.USER, project);
+    db.users().insertEntityPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
 
     // admin with "direct" ADMIN role
     UserDto admin1 = db.users().insertUser();
@@ -1088,8 +1088,8 @@ public class AuthorizationDaoIT {
 
     GroupDto userGroup = db.users().insertGroup("USERS");
     GroupDto adminGroup = db.users().insertGroup("ADMIN");
-    db.users().insertProjectPermissionOnGroup(userGroup, UserRole.USER, project);
-    db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(userGroup, UserRole.USER, project);
+    db.users().insertEntityPermissionOnGroup(adminGroup, UserRole.ADMIN, project);
 
     // admin with "direct" ADMIN role
     UserDto admin1 = db.users().insertUser();
index e39b978f23988379b45a83cc4f6fe59a32346003..cbd12a7e6a14165650a62deca545ee300d578993 100644 (file)
@@ -69,12 +69,12 @@ public class GroupPermissionDaoIT {
     ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
     ProjectDto project3 = db.components().insertPrivateProject().getProjectDto();
 
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.ISSUE_ADMIN, project1);
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, project2);
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project2);
-    db.users().insertProjectPermissionOnGroup(group3, UserRole.ADMIN, project2);
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.USER, project2);
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.USER, project3);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.ISSUE_ADMIN, project1);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.ADMIN, project2);
+    db.users().insertEntityPermissionOnGroup(group2, UserRole.ADMIN, project2);
+    db.users().insertEntityPermissionOnGroup(group3, UserRole.ADMIN, project2);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.USER, project2);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.USER, project3);
 
     final List<CountPerEntityPermission> result = new ArrayList<>();
     underTest.groupsCountByComponentUuidAndPermission(dbSession, asList(project2.getUuid(), project3.getUuid(), "789"),
@@ -95,14 +95,14 @@ public class GroupPermissionDaoIT {
     ProjectDto project2 = db.components().insertPublicProject().getProjectDto();
     ProjectDto project3 = db.components().insertPublicProject().getProjectDto();
 
-    db.users().insertProjectPermissionOnGroup(group1, "p1", project1);
-    db.users().insertProjectPermissionOnGroup(group1, "p2", project2);
-    db.users().insertProjectPermissionOnGroup(group2, "p2", project2);
-    db.users().insertProjectPermissionOnGroup(group3, "p2", project2);
+    db.users().insertEntityPermissionOnGroup(group1, "p1", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "p2", project2);
+    db.users().insertEntityPermissionOnGroup(group2, "p2", project2);
+    db.users().insertEntityPermissionOnGroup(group3, "p2", project2);
     // anyone group
     db.users().insertProjectPermissionOnAnyone("p2", project2);
-    db.users().insertProjectPermissionOnGroup(group1, "p3", project2);
-    db.users().insertProjectPermissionOnGroup(group1, "p3", project3);
+    db.users().insertEntityPermissionOnGroup(group1, "p3", project2);
+    db.users().insertEntityPermissionOnGroup(group1, "p3", project3);
 
     final List<CountPerEntityPermission> result = new ArrayList<>();
     underTest.groupsCountByComponentUuidAndPermission(dbSession, asList(project2.getUuid(), project3.getUuid(), "789"),
@@ -132,7 +132,7 @@ public class GroupPermissionDaoIT {
     IntStream.rangeClosed(1, DEFAULT_PAGE_SIZE + 1).forEach(i -> {
       GroupDto group = db.users().insertGroup("Group-" + i);
       // Add permission on project to be sure projects are excluded
-      db.users().insertProjectPermissionOnGroup(group, GlobalPermission.SCAN.getKey(), project);
+      db.users().insertEntityPermissionOnGroup(group, GlobalPermission.SCAN.getKey(), project);
     });
     String lastGroupName = "Group-" + (DEFAULT_PAGE_SIZE + 1);
     db.users().insertPermissionOnGroup(db.users().selectGroup(lastGroupName).orElseGet(() -> fail("group not found")), GlobalPermission.SCAN);
@@ -151,7 +151,7 @@ public class GroupPermissionDaoIT {
     });
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     String lastGroupName = "Group-" + (DEFAULT_PAGE_SIZE + 1);
-    db.users().insertProjectPermissionOnGroup(db.users().selectGroup(lastGroupName).orElseGet(() -> fail("group not found")), GlobalPermission.SCAN.getKey(), project);
+    db.users().insertEntityPermissionOnGroup(db.users().selectGroup(lastGroupName).orElseGet(() -> fail("group not found")), GlobalPermission.SCAN.getKey(), project);
 
     assertThat(underTest.selectGroupNamesByQuery(dbSession, newQuery()
       .setEntity(project)
@@ -192,7 +192,7 @@ public class GroupPermissionDaoIT {
     db.users().insertPermissionOnAnyone(GlobalPermission.PROVISION_PROJECTS);
     db.users().insertPermissionOnGroup(group1, GlobalPermission.SCAN);
     db.users().insertPermissionOnGroup(group3, GlobalPermission.ADMINISTER);
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group2, UserRole.ADMIN, project);
 
     assertThat(underTest.selectGroupNamesByQuery(dbSession,
       newQuery().setPermission(GlobalPermission.SCAN.getKey()).build())).containsExactly(ANYONE, group1.getName());
@@ -213,13 +213,13 @@ public class GroupPermissionDaoIT {
     ProjectDto project = db.components().insertPublicProject().getProjectDto();
     ProjectDto anotherProject = db.components().insertPublicProject().getProjectDto();
 
-    db.users().insertProjectPermissionOnGroup(group1, "p1", project);
-    db.users().insertProjectPermissionOnGroup(group1, "p2", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p1", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p2", project);
     db.users().insertProjectPermissionOnAnyone("p3", project);
 
-    db.users().insertProjectPermissionOnGroup(group1, "p4", anotherProject);
+    db.users().insertEntityPermissionOnGroup(group1, "p4", anotherProject);
     db.users().insertProjectPermissionOnAnyone("p4", anotherProject);
-    db.users().insertProjectPermissionOnGroup(group3, "p1", anotherProject);
+    db.users().insertEntityPermissionOnGroup(group3, "p1", anotherProject);
     db.users().insertPermissionOnGroup(group2, "p5");
 
     PermissionQuery.Builder builderOnComponent = newQuery()
@@ -241,11 +241,11 @@ public class GroupPermissionDaoIT {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     ProjectDto anotherProject = db.components().insertPrivateProject().getProjectDto();
 
-    db.users().insertProjectPermissionOnGroup(group1, GlobalPermission.SCAN.getKey(), project);
-    db.users().insertProjectPermissionOnGroup(group1, GlobalPermission.PROVISION_PROJECTS.getKey(), project);
+    db.users().insertEntityPermissionOnGroup(group1, GlobalPermission.SCAN.getKey(), project);
+    db.users().insertEntityPermissionOnGroup(group1, GlobalPermission.PROVISION_PROJECTS.getKey(), project);
 
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, anotherProject);
-    db.users().insertProjectPermissionOnGroup(group3, UserRole.SCAN, anotherProject);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.ADMIN, anotherProject);
+    db.users().insertEntityPermissionOnGroup(group3, UserRole.SCAN, anotherProject);
     db.users().insertPermissionOnGroup(group2, GlobalPermission.SCAN);
 
     PermissionQuery.Builder builderOnComponent = newQuery()
@@ -568,8 +568,8 @@ public class GroupPermissionDaoIT {
     ProjectDto project = randomPublicOrPrivateProject().getProjectDto();
     GroupDto group1 = db.users().insertGroup();
     GroupDto group2 = db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group1, "p1", project);
-    db.users().insertProjectPermissionOnGroup(group2, "p2", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p1", project);
+    db.users().insertEntityPermissionOnGroup(group2, "p2", project);
 
     assertThat(underTest.selectGroupUuidsWithPermissionOnEntityBut(dbSession, project.getUuid(), "p2"))
       .containsOnly(group1.getUuid());
@@ -600,8 +600,8 @@ public class GroupPermissionDaoIT {
     GroupDto group1 = db.users().insertGroup();
     GroupDto group2 = db.users().insertGroup();
     db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group1, "p1", project.getProjectDto());
-    db.users().insertProjectPermissionOnGroup(group2, "p2", project.getProjectDto());
+    db.users().insertEntityPermissionOnGroup(group1, "p1", project.getProjectDto());
+    db.users().insertEntityPermissionOnGroup(group2, "p2", project.getProjectDto());
 
     assertThat(underTest.selectGroupUuidsWithPermissionOnEntityBut(dbSession, project.projectUuid(), "p2"))
       .containsOnly(group1.getUuid());
@@ -616,8 +616,8 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
     ProjectDto project2 = db.components().insertPrivateProject().getProjectDto();
     db.users().insertPermissionOnGroup(group1, "perm1");
-    db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
-    db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
+    db.users().insertEntityPermissionOnGroup(group1, "perm2", project1);
+    db.users().insertEntityPermissionOnGroup(group2, "perm3", project2);
 
     underTest.deleteByEntityUuid(dbSession, project1);
     dbSession.commit();
@@ -633,8 +633,8 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
     ProjectDto project2 = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnGroup(group1, "perm1");
-    db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
-    db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
+    db.users().insertEntityPermissionOnGroup(group1, "perm2", project1);
+    db.users().insertEntityPermissionOnGroup(group2, "perm3", project2);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
     db.users().insertProjectPermissionOnAnyone("perm5", project2);
 
@@ -651,7 +651,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnAnyone("perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
-    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm2", group1.getUuid(), group1.getName(), null);
@@ -667,7 +667,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
     db.users().insertPermissionOnAnyone("perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
-    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "perm3", project1);
 
     underTest.delete(dbSession, "perm2", group1.getUuid(), group1.getName(), null);
     dbSession.commit();
@@ -682,7 +682,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnAnyone("perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
-    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm1", null, null, null);
@@ -698,7 +698,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPrivateProject().getProjectDto();
     db.users().insertPermissionOnAnyone("perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
-    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "perm3", project1);
 
     underTest.delete(dbSession, "perm3", group1.getUuid(), group1.getName(), project1);
     dbSession.commit();
@@ -713,7 +713,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnAnyone("perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
-    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm3", group1.getUuid(), group1.getName(), project1);
@@ -729,7 +729,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project1 = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnAnyone("perm1");
     db.users().insertPermissionOnGroup(group1, "perm2");
-    db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+    db.users().insertEntityPermissionOnGroup(group1, "perm3", project1);
     db.users().insertProjectPermissionOnAnyone("perm4", project1);
 
     underTest.delete(dbSession, "perm4", null, null, project1);
@@ -744,7 +744,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project = db.components().insertPublicProject().getProjectDto();
     GroupDto group = db.users().insertGroup();
     db.users().insertProjectPermissionOnAnyone("p1", project);
-    db.users().insertProjectPermissionOnGroup(group, "p2", project);
+    db.users().insertEntityPermissionOnGroup(group, "p2", project);
     db.users().insertPermissionOnAnyone("p3");
     db.users().insertPermissionOnGroup(group, "p4");
     assertThat(underTest.selectEntityPermissionsOfGroup(dbSession, null, project.getUuid()))
@@ -775,9 +775,9 @@ public class GroupPermissionDaoIT {
     GroupDto group1 = db.users().insertGroup();
     GroupDto group2 = db.users().insertGroup();
     db.users().insertProjectPermissionOnAnyone("p1", project);
-    db.users().insertProjectPermissionOnGroup(group1, "p2", project);
-    db.users().insertProjectPermissionOnGroup(group2, "p3", project);
-    db.users().insertProjectPermissionOnGroup(group2, "p4", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p2", project);
+    db.users().insertEntityPermissionOnGroup(group2, "p3", project);
+    db.users().insertEntityPermissionOnGroup(group2, "p4", project);
     db.users().insertPermissionOnAnyone("p5");
     db.users().insertPermissionOnGroup(group1, "p6");
     db.users().insertPermissionOnGroup(group2, "p7");
@@ -852,7 +852,7 @@ public class GroupPermissionDaoIT {
   public void deleteByRootEntityAndGroupUuid_has_no_effect_if_component_has_no_group_permission_for_group_AnyOne() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     GroupDto group1 = db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group1, "p1", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p1", project);
     assertThat(underTest.selectEntityPermissionsOfGroup(dbSession, null, project.getUuid()))
       .isEmpty();
     assertThat(underTest.selectEntityPermissionsOfGroup(dbSession, group1.getUuid(), project.getUuid()))
@@ -878,7 +878,7 @@ public class GroupPermissionDaoIT {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     GroupDto group1 = db.users().insertGroup();
     GroupDto group2 = db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group1, "p1", project);
+    db.users().insertEntityPermissionOnGroup(group1, "p1", project);
     db.users().insertPermissionOnAnyone("p2");
     db.users().insertPermissionOnGroup(group1, "p3");
 
@@ -902,7 +902,7 @@ public class GroupPermissionDaoIT {
     Stream.of("p1", "p2").forEach(permission -> {
       db.users().insertPermissionOnAnyone(permission);
       db.users().insertPermissionOnGroup(group, permission);
-      db.users().insertProjectPermissionOnGroup(group, permission, project);
+      db.users().insertEntityPermissionOnGroup(group, permission, project);
       db.users().insertProjectPermissionOnAnyone(permission, project);
     });
     assertThat(getGlobalPermissionsForAnyone()).containsOnly("p1", "p2");
@@ -948,7 +948,7 @@ public class GroupPermissionDaoIT {
     GroupDto group = db.users().insertGroup();
     db.users().insertPermissionOnAnyone("p1");
     db.users().insertPermissionOnGroup(group, "p1");
-    db.users().insertProjectPermissionOnGroup(group, "p1", project);
+    db.users().insertEntityPermissionOnGroup(group, "p1", project);
     db.users().insertProjectPermissionOnAnyone("p1", project);
 
     ProjectDto anotherProject = ComponentTesting.newProjectDto();
index a29cd88a954ffbfe1f999f60bbf1ff9658a6740a..7eef54bc022da93a193b6378f7fbc31d779dc449 100644 (file)
@@ -33,7 +33,7 @@ public class UserPermissionNewValue extends PermissionNewValue {
   private final String userLogin;
 
   public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String componentKey, @Nullable String componentName,
-    @Nullable UserId userId, String qualifier, @Nullable PermissionTemplateDto templateDto) {
+    @Nullable UserId userId, @Nullable String qualifier, @Nullable PermissionTemplateDto templateDto) {
     super(permissionDto.getUuid(), permissionDto.getComponentUuid(), componentKey, componentName, permissionDto.getPermission(), qualifier, templateDto);
     this.userUuid = userId != null ? userId.getUuid() : null;
     this.userLogin = userId != null ? userId.getLogin() : null;
index 48ff0a55a8ac2e96d09ec285d3abfcb245b6e631..a7cdf78310217bffe5ab4f55d258dca873917861 100644 (file)
@@ -270,7 +270,7 @@ public class UserDbTester {
       .setComponentUuid(project.uuid())
       .setComponentName(project.name());
 
-    //TODO, will be removed later
+    // TODO, will be removed later
     ProjectDto projectDto = new ProjectDto();
     projectDto.setQualifier(project.qualifier());
     projectDto.setKey(project.getKey());
@@ -314,7 +314,7 @@ public class UserDbTester {
       .setComponentUuid(project.uuid())
       .setComponentName(project.name());
 
-    //TODO, will be removed later
+    // TODO, will be removed later
     ProjectDto projectDto = new ProjectDto();
     projectDto.setQualifier(project.qualifier());
     projectDto.setKey(project.getKey());
@@ -323,17 +323,20 @@ public class UserDbTester {
     return dto;
   }
 
-  public GroupPermissionDto insertProjectPermissionOnGroup(GroupDto group, String permission, EntityDto entity) {
-    checkArgument(entity.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
-      "%s can't be granted on a public project", permission);
+  public GroupPermissionDto insertEntityPermissionOnGroup(GroupDto group, String permission, EntityDto entityDto) {
+    checkArgument(entityDto.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
+      "%s can't be granted on a public entity (project or portfolio)", permission);
+    Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), entityDto.getUuid());
+    // I don't know if this check is worth it
+    branchDto.ifPresent(dto -> checkArgument(dto.isMain(), PERMISSIONS_CANT_BE_GRANTED_ON_BRANCHES));
     GroupPermissionDto dto = new GroupPermissionDto()
       .setUuid(Uuids.createFast())
       .setGroupUuid(group.getUuid())
       .setGroupName(group.getName())
       .setRole(permission)
-      .setComponentUuid(entity.getUuid())
-      .setComponentName(entity.getName());
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, entity, null);
+      .setComponentUuid(entityDto.getUuid())
+      .setComponentName(entityDto.getUuid());
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, entityDto, null);
     db.commit();
     return dto;
   }
index 292ae6d3fd187e27639e78be5ccb6460b619d0bc..b7f46f28dd2cab53521c482e91ae126c843ccf88 100644 (file)
@@ -408,7 +408,7 @@ public class ServerUserSessionIT {
   @Test
   public void hasComponentPermissionByDtoOrUuid_returns_true_for_anonymous_user_for_permissions_USER_and_CODEVIEWER_on_public_projects_with_group_permissions() {
     ProjectData publicProject = db.components().insertPublicProject();
-    db.users().insertProjectPermissionOnGroup(db.users().insertGroup(), "p1", publicProject.getProjectDto());
+    db.users().insertEntityPermissionOnGroup(db.users().insertGroup(), "p1", publicProject.getProjectDto());
 
     ServerUserSession underTest = newAnonymousSession();
 
@@ -442,7 +442,7 @@ public class ServerUserSessionIT {
   public void hasComponentPermissionByDtoOrUuid_returns_false_for_authenticated_user_for_permissions_USER_and_CODEVIEWER_on_private_projects_with_group_permissions() {
     UserDto user = db.users().insertUser();
     ProjectData privateProject = db.components().insertPrivateProject();
-    db.users().insertProjectPermissionOnGroup(db.users().insertGroup(), "p1", privateProject.getProjectDto());
+    db.users().insertEntityPermissionOnGroup(db.users().insertGroup(), "p1", privateProject.getProjectDto());
 
     ServerUserSession underTest = newUserSession(user);
 
@@ -476,7 +476,7 @@ public class ServerUserSessionIT {
   public void hasComponentPermissionByDtoOrUuid_returns_false_for_anonymous_user_for_inserted_permissions_on_group_on_public_projects() {
     ProjectData publicProject = db.components().insertPublicProject();
     GroupDto group = db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group, "p1", publicProject.getProjectDto());
+    db.users().insertEntityPermissionOnGroup(group, "p1", publicProject.getProjectDto());
 
     ServerUserSession underTest = newAnonymousSession();
 
@@ -487,7 +487,7 @@ public class ServerUserSessionIT {
   public void hasComponentPermissionByDtoOrUuid_returns_false_for_anonymous_user_for_inserted_permissions_on_group_on_private_projects() {
     ProjectData privateProject = db.components().insertPrivateProject();
     GroupDto group = db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group, "p1", privateProject.getProjectDto());
+    db.users().insertEntityPermissionOnGroup(group, "p1", privateProject.getProjectDto());
 
     ServerUserSession underTest = newAnonymousSession();
 
index f18989a6759cc9fac8b936b1483f639e309f528f..b7573bf1840d09a52d021a832ac7c3bbd67d8423 100644 (file)
@@ -38,9 +38,12 @@ import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ProjectData;
 import org.sonar.db.permission.GroupPermissionDto;
+import org.sonar.db.portfolio.PortfolioDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDbTester;
 import org.sonar.db.user.UserDto;
+import org.sonar.server.project.Project;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.singletonList;
@@ -54,19 +57,19 @@ import static org.sonar.api.web.UserRole.USER;
 public class PermissionIndexerDaoIT {
 
   @Rule
-  public DbTester dbTester = DbTester.create(System2.INSTANCE);
+  public DbTester dbTester = DbTester.create(System2.INSTANCE,true);
 
   private final DbClient dbClient = dbTester.getDbClient();
   private final DbSession dbSession = dbTester.getSession();
   private final ComponentDbTester componentDbTester = new ComponentDbTester(dbTester);
   private final UserDbTester userDbTester = new UserDbTester(dbTester);
 
-  private ComponentDto publicProject;
-  private ComponentDto privateProject1;
-  private ComponentDto privateProject2;
-  private ComponentDto view1;
-  private ComponentDto view2;
-  private ComponentDto application;
+  private ProjectDto publicProject;
+  private ProjectDto privateProject1;
+  private ProjectDto privateProject2;
+  private PortfolioDto view1;
+  private PortfolioDto view2;
+  private ProjectDto application;
   private UserDto user1;
   private UserDto user2;
   private GroupDto group;
@@ -75,12 +78,12 @@ public class PermissionIndexerDaoIT {
 
   @Before
   public void setUp() {
-    publicProject = componentDbTester.insertPublicProject().getMainBranchComponent();
-    privateProject1 = componentDbTester.insertPrivateProject().getMainBranchComponent();
-    privateProject2 = componentDbTester.insertPrivateProject().getMainBranchComponent();
-    view1 = componentDbTester.insertPublicPortfolio();
-    view2 = componentDbTester.insertPublicPortfolio();
-    application = componentDbTester.insertPublicApplication().getMainBranchComponent();
+    publicProject = componentDbTester.insertPublicProject().getProjectDto();
+    privateProject1 = componentDbTester.insertPrivateProject().getProjectDto();
+    privateProject2 = componentDbTester.insertPrivateProject().getProjectDto();
+    view1 = componentDbTester.insertPublicPortfolioDto();
+    view2 = componentDbTester.insertPublicPortfolioDto();
+    application = componentDbTester.insertPublicApplication().getProjectDto();
     user1 = userDbTester.insertUser();
     user2 = userDbTester.insertUser();
     group = userDbTester.insertGroup();
@@ -93,28 +96,28 @@ public class PermissionIndexerDaoIT {
     Collection<IndexPermissions> dtos = underTest.selectAll(dbClient, dbSession);
     Assertions.assertThat(dtos).hasSize(6);
 
-    IndexPermissions publicProjectAuthorization = getByProjectUuid(publicProject.uuid(), dtos);
+    IndexPermissions publicProjectAuthorization = getByProjectUuid(publicProject.getUuid(), dtos);
     isPublic(publicProjectAuthorization, PROJECT);
 
-    IndexPermissions view1Authorization = getByProjectUuid(view1.uuid(), dtos);
+    IndexPermissions view1Authorization = getByProjectUuid(view1.getUuid(), dtos);
     isPublic(view1Authorization, VIEW);
 
-    IndexPermissions applicationAuthorization = getByProjectUuid(application.uuid(), dtos);
+    IndexPermissions applicationAuthorization = getByProjectUuid(application.getUuid(), dtos);
     isPublic(applicationAuthorization, APP);
 
-    IndexPermissions privateProject1Authorization = getByProjectUuid(privateProject1.uuid(), dtos);
+    IndexPermissions privateProject1Authorization = getByProjectUuid(privateProject1.getUuid(), dtos);
     assertThat(privateProject1Authorization.getGroupUuids()).containsOnly(group.getUuid());
     assertThat(privateProject1Authorization.isAllowAnyone()).isFalse();
     assertThat(privateProject1Authorization.getUserUuids()).containsOnly(user1.getUuid(), user2.getUuid());
     assertThat(privateProject1Authorization.getQualifier()).isEqualTo(PROJECT);
 
-    IndexPermissions privateProject2Authorization = getByProjectUuid(privateProject2.uuid(), dtos);
+    IndexPermissions privateProject2Authorization = getByProjectUuid(privateProject2.getUuid(), dtos);
     assertThat(privateProject2Authorization.getGroupUuids()).isEmpty();
     assertThat(privateProject2Authorization.isAllowAnyone()).isFalse();
     assertThat(privateProject2Authorization.getUserUuids()).containsOnly(user1.getUuid());
     assertThat(privateProject2Authorization.getQualifier()).isEqualTo(PROJECT);
 
-    IndexPermissions view2Authorization = getByProjectUuid(view2.uuid(), dtos);
+    IndexPermissions view2Authorization = getByProjectUuid(view2.getUuid(), dtos);
     isPublic(view2Authorization, VIEW);
   }
 
@@ -123,33 +126,34 @@ public class PermissionIndexerDaoIT {
     insertTestDataForProjectsAndViews();
 
     Map<String, IndexPermissions> dtos = underTest
-      .selectByUuids(dbClient, dbSession, asList(publicProject.uuid(), privateProject1.uuid(), privateProject2.uuid(), view1.uuid(), view2.uuid(), application.uuid()))
+      .selectByUuids(dbClient, dbSession,
+        asList(publicProject.getUuid(), privateProject1.getUuid(), privateProject2.getUuid(), view1.getUuid(), view2.getUuid(), application.getUuid()))
       .stream()
       .collect(MoreCollectors.uniqueIndex(IndexPermissions::getProjectUuid, Function.identity()));
     Assertions.assertThat(dtos).hasSize(6);
 
-    IndexPermissions publicProjectAuthorization = dtos.get(publicProject.uuid());
+    IndexPermissions publicProjectAuthorization = dtos.get(publicProject.getUuid());
     isPublic(publicProjectAuthorization, PROJECT);
 
-    IndexPermissions view1Authorization = dtos.get(view1.uuid());
+    IndexPermissions view1Authorization = dtos.get(view1.getUuid());
     isPublic(view1Authorization, VIEW);
 
-    IndexPermissions applicationAuthorization = dtos.get(application.uuid());
+    IndexPermissions applicationAuthorization = dtos.get(application.getUuid());
     isPublic(applicationAuthorization, APP);
 
-    IndexPermissions privateProject1Authorization = dtos.get(privateProject1.uuid());
+    IndexPermissions privateProject1Authorization = dtos.get(privateProject1.getUuid());
     assertThat(privateProject1Authorization.getGroupUuids()).containsOnly(group.getUuid());
     assertThat(privateProject1Authorization.isAllowAnyone()).isFalse();
     assertThat(privateProject1Authorization.getUserUuids()).containsOnly(user1.getUuid(), user2.getUuid());
     assertThat(privateProject1Authorization.getQualifier()).isEqualTo(PROJECT);
 
-    IndexPermissions privateProject2Authorization = dtos.get(privateProject2.uuid());
+    IndexPermissions privateProject2Authorization = dtos.get(privateProject2.getUuid());
     assertThat(privateProject2Authorization.getGroupUuids()).isEmpty();
     assertThat(privateProject2Authorization.isAllowAnyone()).isFalse();
     assertThat(privateProject2Authorization.getUserUuids()).containsOnly(user1.getUuid());
     assertThat(privateProject2Authorization.getQualifier()).isEqualTo(PROJECT);
 
-    IndexPermissions view2Authorization = dtos.get(view2.uuid());
+    IndexPermissions view2Authorization = dtos.get(view2.getUuid());
     isPublic(view2Authorization, VIEW);
   }
 
@@ -186,7 +190,7 @@ public class PermissionIndexerDaoIT {
 
   @Test
   public void return_private_project_without_any_permission_when_no_permission_in_DB() {
-    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.uuid()));
+    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.getUuid()));
 
     // no permissions
     Assertions.assertThat(dtos).hasSize(1);
@@ -194,50 +198,50 @@ public class PermissionIndexerDaoIT {
     assertThat(dto.getGroupUuids()).isEmpty();
     assertThat(dto.getUserUuids()).isEmpty();
     assertThat(dto.isAllowAnyone()).isFalse();
-    assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid());
-    assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier());
+    assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.getUuid());
+    assertThat(dto.getQualifier()).isEqualTo(privateProject1.getQualifier());
   }
 
   @Test
   public void return_public_project_with_only_AllowAnyone_true_when_no_permission_in_DB() {
-    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(publicProject.uuid()));
+    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(publicProject.getUuid()));
 
     Assertions.assertThat(dtos).hasSize(1);
     IndexPermissions dto = dtos.get(0);
     assertThat(dto.getGroupUuids()).isEmpty();
     assertThat(dto.getUserUuids()).isEmpty();
     assertThat(dto.isAllowAnyone()).isTrue();
-    assertThat(dto.getProjectUuid()).isEqualTo(publicProject.uuid());
-    assertThat(dto.getQualifier()).isEqualTo(publicProject.qualifier());
+    assertThat(dto.getProjectUuid()).isEqualTo(publicProject.getUuid());
+    assertThat(dto.getQualifier()).isEqualTo(publicProject.getQualifier());
   }
 
   @Test
   public void return_private_project_with_AllowAnyone_false_and_user_id_when_user_is_granted_USER_permission_directly() {
     dbTester.users().insertProjectPermissionOnUser(user1, USER, privateProject1);
-    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.uuid()));
+    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.getUuid()));
 
     Assertions.assertThat(dtos).hasSize(1);
     IndexPermissions dto = dtos.get(0);
     assertThat(dto.getGroupUuids()).isEmpty();
     assertThat(dto.getUserUuids()).containsOnly(user1.getUuid());
     assertThat(dto.isAllowAnyone()).isFalse();
-    assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid());
-    assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier());
+    assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.getUuid());
+    assertThat(dto.getQualifier()).isEqualTo(privateProject1.getQualifier());
   }
 
   @Test
   public void return_private_project_with_AllowAnyone_false_and_group_id_but_not_user_id_when_user_is_granted_USER_permission_through_group() {
     dbTester.users().insertMember(group, user1);
-    dbTester.users().insertProjectPermissionOnGroup(group, USER, privateProject1);
-    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.uuid()));
+    dbTester.users().insertEntityPermissionOnGroup(group, USER, privateProject1);
+    List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(privateProject1.getUuid()));
 
     Assertions.assertThat(dtos).hasSize(1);
     IndexPermissions dto = dtos.get(0);
     assertThat(dto.getGroupUuids()).containsOnly(group.getUuid());
     assertThat(dto.getUserUuids()).isEmpty();
     assertThat(dto.isAllowAnyone()).isFalse();
-    assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.uuid());
-    assertThat(dto.getQualifier()).isEqualTo(privateProject1.qualifier());
+    assertThat(dto.getProjectUuid()).isEqualTo(privateProject1.getUuid());
+    assertThat(dto.getQualifier()).isEqualTo(privateProject1.getQualifier());
   }
 
   private void isPublic(IndexPermissions view1Authorization, String qualifier) {
@@ -264,9 +268,9 @@ public class PermissionIndexerDaoIT {
     userDbTester.insertProjectPermissionOnUser(user2, ADMIN, privateProject2);
 
     // group1 has USER access on privateProject1 only
-    userDbTester.insertProjectPermissionOnGroup(group, USER, privateProject1);
-    userDbTester.insertProjectPermissionOnGroup(group, ADMIN, privateProject1);
-    userDbTester.insertProjectPermissionOnGroup(group, ADMIN, view1);
-    userDbTester.insertProjectPermissionOnGroup(group, ADMIN, application);
+    userDbTester.insertEntityPermissionOnGroup(group, USER, privateProject1);
+    userDbTester.insertEntityPermissionOnGroup(group, ADMIN, privateProject1);
+    userDbTester.insertEntityPermissionOnGroup(group, ADMIN, view1);
+    userDbTester.insertEntityPermissionOnGroup(group, ADMIN, application);
   }
 }
index 48a7045ce42a6d590de4f2f1a672e1c9b6d4e275..84f58c913d92ef7669c2d9d1148df14ef95494a8 100644 (file)
@@ -44,157 +44,124 @@ public class PermissionIndexerDao {
     USER, GROUP, ANYONE, NONE
   }
 
-  private static final String SQL_TEMPLATE = "SELECT " +
-    "  project_authorization.kind as kind, " +
-    "  project_authorization.project as project, " +
-    "  project_authorization.user_uuid as user_uuid, " +
-    "  project_authorization.group_uuid as group_uuid, " +
-    "  project_authorization.qualifier as qualifier " +
-    "FROM ( " +
-
-    // users
-
-    "      SELECT '" + RowKind.USER + "' as kind," +
-    "      c.uuid AS project, " +
-    "      c.qualifier AS qualifier, " +
-    "      user_roles.user_uuid  AS user_uuid, " +
-    "      NULL  AS group_uuid " +
-    "      FROM components c " +
-    "      INNER JOIN user_roles ON user_roles.component_uuid = c.uuid AND user_roles.role = 'user' " +
-    "      WHERE " +
-    "        (c.qualifier = 'TRK' " +
-    "         or  c.qualifier = 'VW' " +
-    "         or  c.qualifier = 'APP') " +
-    "        AND c.copy_component_uuid is NULL " +
-    "        {projectsCondition} " +
-    "      UNION " +
-
-    // groups
-
-    "      SELECT '" + RowKind.GROUP + "' as kind," +
-    "      c.uuid AS project, " +
-    "      c.qualifier AS qualifier, " +
-    "      NULL  AS user_uuid, " +
-    "      groups.uuid  AS group_uuid " +
-    "      FROM components c " +
-    "      INNER JOIN group_roles ON group_roles.component_uuid = c.uuid AND group_roles.role = 'user' " +
-    "      INNER JOIN groups ON groups.uuid = group_roles.group_uuid " +
-    "      WHERE " +
-    "        (c.qualifier = 'TRK' " +
-    "         or  c.qualifier = 'VW' " +
-    "         or  c.qualifier = 'APP') " +
-    "        AND c.copy_component_uuid is NULL " +
-    "        {projectsCondition} " +
-    "        AND group_uuid IS NOT NULL " +
-    "      UNION " +
-
-    // public projects are accessible to any one
-
-    "      SELECT '" + RowKind.ANYONE + "' as kind," +
-    "      c.uuid AS project, " +
-    "      c.qualifier AS qualifier, " +
-    "      NULL         AS user_uuid, " +
-    "      NULL     AS group_uuid " +
-    "      FROM components c " +
-    "      WHERE " +
-    "        (c.qualifier = 'TRK' " +
-    "         or  c.qualifier = 'VW' " +
-    "         or  c.qualifier = 'APP') " +
-    "        AND c.copy_component_uuid is NULL " +
-    "        AND c.private = ? " +
-    "        {projectsCondition} " +
-    "      UNION " +
-
-    // private project is returned when no authorization
-    "      SELECT '" + RowKind.NONE + "' as kind," +
-    "      c.uuid AS project, " +
-    "      c.qualifier AS qualifier, " +
-    "      NULL AS user_uuid, " +
-    "      NULL  AS group_uuid " +
-    "      FROM components c " +
-    "      WHERE " +
-    "        (c.qualifier = 'TRK' " +
-    "         or  c.qualifier = 'VW' " +
-    "         or  c.qualifier = 'APP') " +
-    "        AND c.copy_component_uuid is NULL " +
-    "        AND c.private = ? " +
-    "        {projectsCondition} " +
-
-    "    ) project_authorization";
+  private static final String SQL_TEMPLATE = """
+    with entity as ((select prj.uuid      as uuid,
+                            prj.private   as isPrivate,
+                            prj.qualifier as qualifier
+                     from projects prj)
+                    union
+                    (select p.uuid    as uuid,
+                            p.private as isPrivate,
+                            'VW'      as qualifier
+                     from portfolios p
+                     where p.parent_uuid is null))
+    SELECT entity_authorization.kind       as kind,
+           entity_authorization.entity     as entity,
+           entity_authorization.user_uuid  as user_uuid,
+           entity_authorization.group_uuid as group_uuid,
+           entity_authorization.qualifier  as qualifier
+    FROM (SELECT '%s'                 as kind,
+                 e.uuid               AS entity,
+                 e.qualifier          AS qualifier,
+                 user_roles.user_uuid AS user_uuid,
+                 NULL                 AS group_uuid
+          FROM entity e
+                   INNER JOIN user_roles ON user_roles.component_uuid = e.uuid AND user_roles.role = 'user'
+          WHERE (1 = 1)
+                {entitiesCondition}
+          UNION
+          SELECT '%s' as kind, e.uuid AS entity, e.qualifier AS qualifier, NULL AS user_uuid, groups.uuid AS group_uuid
+          FROM entity e
+                   INNER JOIN group_roles
+                              ON group_roles.component_uuid = e.uuid AND group_roles.role = 'user'
+                   INNER JOIN groups ON groups.uuid = group_roles.group_uuid
+          WHERE group_uuid IS NOT NULL
+                {entitiesCondition}
+          UNION
+          SELECT '%s' as kind, e.uuid AS entity, e.qualifier AS qualifier, NULL AS user_uuid, NULL AS group_uuid
+          FROM entity e
+          WHERE e.isPrivate = ?
+                {entitiesCondition}
+          UNION
+          SELECT '%s' as kind, e.uuid AS entity, e.qualifier AS qualifier, NULL AS user_uuid, NULL AS group_uuid
+          FROM entity e
+          WHERE e.isPrivate = ?
+             {entitiesCondition}
+         ) entity_authorization""".formatted(RowKind.USER, RowKind.GROUP, RowKind.ANYONE, RowKind.NONE);
 
   List<IndexPermissions> selectAll(DbClient dbClient, DbSession session) {
-    return doSelectByProjects(dbClient, session, Collections.emptyList());
+    return doSelectByEntities(dbClient, session, Collections.emptyList());
   }
 
-  public List<IndexPermissions> selectByUuids(DbClient dbClient, DbSession session, Collection<String> projectOrViewUuids) {
-    // we use a smaller partitionSize because the SQL_TEMPLATE contain 4x the list of project uuid.
+  public List<IndexPermissions> selectByUuids(DbClient dbClient, DbSession session, Collection<String> entitiesUuid) {
+    // we use a smaller partitionSize because the SQL_TEMPLATE contain 4x the list of entity uuid.
     // the MsSQL jdbc driver accept a maximum of 2100 prepareStatement parameter. To stay under the limit,
-    // we go with batch of 1000/2=500 project uuids, to stay under the limit (4x500 < 2100)
-    return executeLargeInputs(projectOrViewUuids, subProjectOrViewUuids -> doSelectByProjects(dbClient, session, subProjectOrViewUuids), i -> i / 2);
+    // we go with batch of 1000/2=500 entities uuids, to stay under the limit (4x500 < 2100)
+    return executeLargeInputs(entitiesUuid, entity -> doSelectByEntities(dbClient, session, entity), i -> i / 2);
   }
 
-  private static List<IndexPermissions> doSelectByProjects(DbClient dbClient, DbSession session, List<String> projectUuids) {
+  private static List<IndexPermissions> doSelectByEntities(DbClient dbClient, DbSession session, List<String> entitiesUuids) {
     try {
-      Map<String, IndexPermissions> dtosByProjectUuid = new HashMap<>();
-      try (PreparedStatement stmt = createStatement(dbClient, session, projectUuids);
+      Map<String, IndexPermissions> dtosByEntityUuid = new HashMap<>();
+      try (PreparedStatement stmt = createStatement(dbClient, session, entitiesUuids);
         ResultSet rs = stmt.executeQuery()) {
         while (rs.next()) {
-          processRow(rs, dtosByProjectUuid);
+          processRow(rs, dtosByEntityUuid);
         }
-        return ImmutableList.copyOf(dtosByProjectUuid.values());
+        return ImmutableList.copyOf(dtosByEntityUuid.values());
       }
     } catch (SQLException e) {
       throw new IllegalStateException("Fail to select authorizations", e);
     }
   }
 
-  private static PreparedStatement createStatement(DbClient dbClient, DbSession session, List<String> projectUuids) throws SQLException {
+  private static PreparedStatement createStatement(DbClient dbClient, DbSession session, List<String> entityUuids) throws SQLException {
     String sql;
-    if (projectUuids.isEmpty()) {
-      sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", "");
+    if (entityUuids.isEmpty()) {
+      sql = StringUtils.replace(SQL_TEMPLATE, "{entitiesCondition}", "");
     } else {
-      sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", " AND c.uuid in (" + repeat("?", ", ", projectUuids.size()) + ")");
+      sql = StringUtils.replace(SQL_TEMPLATE, "{entitiesCondition}", " AND e.uuid in (" + repeat("?", ", ", entityUuids.size()) + ")");
     }
     PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql);
     int index = 1;
     // query for RowKind.USER
-    index = populateProjectUuidPlaceholders(stmt, projectUuids, index);
+    index = populateEntityUuidPlaceholders(stmt, entityUuids, index);
     // query for RowKind.GROUP
-    index = populateProjectUuidPlaceholders(stmt, projectUuids, index);
+    index = populateEntityUuidPlaceholders(stmt, entityUuids, index);
     // query for RowKind.ANYONE
-    index = setPrivateProjectPlaceHolder(stmt, index, false);
-    index = populateProjectUuidPlaceholders(stmt, projectUuids, index);
+    index = setPrivateEntityPlaceHolder(stmt, index, false);
+    index = populateEntityUuidPlaceholders(stmt, entityUuids, index);
     // query for RowKind.NONE
-    index = setPrivateProjectPlaceHolder(stmt, index, true);
-    populateProjectUuidPlaceholders(stmt, projectUuids, index);
+    index = setPrivateEntityPlaceHolder(stmt, index, true);
+    populateEntityUuidPlaceholders(stmt, entityUuids, index);
     return stmt;
   }
 
-  private static int populateProjectUuidPlaceholders(PreparedStatement stmt, List<String> projectUuids, int index) throws SQLException {
+  private static int populateEntityUuidPlaceholders(PreparedStatement stmt, List<String> entityUuids, int index) throws SQLException {
     int newIndex = index;
-    for (String projectUuid : projectUuids) {
-      stmt.setString(newIndex, projectUuid);
+    for (String entityUuid : entityUuids) {
+      stmt.setString(newIndex, entityUuid);
       newIndex++;
     }
     return newIndex;
   }
 
-  private static int setPrivateProjectPlaceHolder(PreparedStatement stmt, int index, boolean isPrivate) throws SQLException {
+  private static int setPrivateEntityPlaceHolder(PreparedStatement stmt, int index, boolean isPrivate) throws SQLException {
     int newIndex = index;
     stmt.setBoolean(newIndex, isPrivate);
     newIndex++;
     return newIndex;
   }
 
-  private static void processRow(ResultSet rs, Map<String, IndexPermissions> dtosByProjectUuid) throws SQLException {
+  private static void processRow(ResultSet rs, Map<String, IndexPermissions> dtosByEntityUuid) throws SQLException {
     RowKind rowKind = RowKind.valueOf(rs.getString(1));
-    String projectUuid = rs.getString(2);
+    String entityUuid = rs.getString(2);
 
-    IndexPermissions dto = dtosByProjectUuid.get(projectUuid);
+    IndexPermissions dto = dtosByEntityUuid.get(entityUuid);
     if (dto == null) {
       String qualifier = rs.getString(5);
-      dto = new IndexPermissions(projectUuid, qualifier);
-      dtosByProjectUuid.put(projectUuid, dto);
+      dto = new IndexPermissions(entityUuid, qualifier);
+      dtosByEntityUuid.put(entityUuid, dto);
     }
     switch (rowKind) {
       case NONE:
index e5652b5ff256a8b40b66ed0f929957f9440524f2..be278b496c0f6a99b20585ddd2aba778d379dedd 100644 (file)
@@ -25,8 +25,10 @@ import org.junit.Test;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.entity.EntityDto;
 import org.sonar.db.es.EsQueueDto;
+import org.sonar.db.portfolio.PortfolioDto;
+import org.sonar.db.project.ProjectDto;
 import org.sonar.db.user.GroupDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.es.EsTester;
@@ -50,7 +52,7 @@ public class PermissionIndexerTest {
   private static final IndexMainType INDEX_TYPE_FOO_AUTH = IndexType.main(FooIndexDefinition.DESCRIPTOR, TYPE_AUTHORIZATION);
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(System2.INSTANCE, true);
   @Rule
   public EsTester es = EsTester.createCustom(new FooIndexDefinition());
   @Rule
@@ -62,7 +64,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_grants_access_to_any_user_and_to_group_Anyone_on_public_projects() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
 
@@ -75,7 +77,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexAll_grants_access_to_any_user_and_to_group_Anyone_on_public_projects() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
 
@@ -88,15 +90,15 @@ public class PermissionIndexerTest {
 
   @Test
   public void deletion_resilience_will_deindex_projects() {
-    ComponentDto project1 = createUnindexedPublicProject();
-    ComponentDto project2 = createUnindexedPublicProject();
+    ProjectDto project1 = createUnindexedPublicProject();
+    ProjectDto project2 = createUnindexedPublicProject();
     // UserDto user1 = db.users().insertUser();
     indexOnStartup();
     assertThat(es.countDocuments(INDEX_TYPE_FOO_AUTH)).isEqualTo(2);
 
     // Simulate a indexation issue
-    db.getDbClient().purgeDao().deleteProject(db.getSession(), project1.uuid(), PROJECT, project1.name(), project1.getKey());
-    underTest.prepareForRecovery(db.getSession(), asList(project1.uuid()), ProjectIndexer.Cause.PROJECT_DELETION);
+    db.getDbClient().purgeDao().deleteProject(db.getSession(), project1.getUuid(), PROJECT, project1.getName(), project1.getKey());
+    underTest.prepareForRecovery(db.getSession(), asList(project1.getUuid()), ProjectIndexer.Cause.PROJECT_DELETION);
     assertThat(db.countRowsOfTable(db.getSession(), "es_queue")).isOne();
     Collection<EsQueueDto> esQueueDtos = db.getDbClient().esQueueDao().selectForRecovery(db.getSession(), Long.MAX_VALUE, 2);
 
@@ -108,7 +110,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_grants_access_to_user() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
     db.users().insertProjectPermissionOnUser(user1, USER, project);
@@ -128,14 +130,14 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_grants_access_to_group_on_private_project() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
     UserDto user3 = db.users().insertUser();
     GroupDto group1 = db.users().insertGroup();
     GroupDto group2 = db.users().insertGroup();
-    db.users().insertProjectPermissionOnGroup(group1, USER, project);
-    db.users().insertProjectPermissionOnGroup(group2, ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group1, USER, project);
+    db.users().insertEntityPermissionOnGroup(group2, ADMIN, project);
 
     indexOnStartup();
 
@@ -154,13 +156,13 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_grants_access_to_user_and_group() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
     GroupDto group = db.users().insertGroup();
     db.users().insertMember(group, user2);
     db.users().insertProjectPermissionOnUser(user1, USER, project);
-    db.users().insertProjectPermissionOnGroup(group, USER, project);
+    db.users().insertEntityPermissionOnGroup(group, USER, project);
 
     indexOnStartup();
 
@@ -179,7 +181,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_does_not_grant_access_to_anybody_on_private_project() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user = db.users().insertUser();
     GroupDto group = db.users().insertGroup();
 
@@ -192,7 +194,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_grants_access_to_anybody_on_public_project() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
     UserDto user = db.users().insertUser();
     GroupDto group = db.users().insertGroup();
 
@@ -205,7 +207,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnStartup_grants_access_to_anybody_on_view() {
-    ComponentDto view = createAndIndexView();
+    PortfolioDto view = createAndIndexPortfolio();
     UserDto user = db.users().insertUser();
     GroupDto group = db.users().insertGroup();
 
@@ -220,7 +222,7 @@ public class PermissionIndexerTest {
   public void indexOnStartup_grants_access_on_many_projects() {
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
-    ComponentDto project = null;
+    ProjectDto project = null;
     for (int i = 0; i < 10; i++) {
       project = createAndIndexPrivateProject();
       db.users().insertProjectPermissionOnUser(user1, USER, project);
@@ -235,7 +237,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void public_projects_are_visible_to_anybody() {
-    ComponentDto projectOnOrg1 = createAndIndexPublicProject();
+    ProjectDto projectOnOrg1 = createAndIndexPublicProject();
     UserDto user = db.users().insertUser();
 
     indexOnStartup();
@@ -246,9 +248,9 @@ public class PermissionIndexerTest {
 
   @Test
   public void indexOnAnalysis_does_nothing_because_CE_does_not_touch_permissions() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
 
-    underTest.indexOnAnalysis(project.uuid());
+    underTest.indexOnAnalysis(project.getUuid());
 
     assertThatAuthIndexHasSize(0);
     verifyAnyoneNotAuthorized(project);
@@ -256,7 +258,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void permissions_are_not_updated_on_project_tags_update() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
 
     indexPermissions(project, ProjectIndexer.Cause.PROJECT_TAGS_UPDATE);
 
@@ -266,7 +268,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void permissions_are_not_updated_on_project_key_update() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
 
     indexPermissions(project, ProjectIndexer.Cause.PROJECT_TAGS_UPDATE);
 
@@ -276,7 +278,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void index_permissions_on_project_creation() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user = db.users().insertUser();
     db.users().insertProjectPermissionOnUser(user, USER, project);
 
@@ -288,7 +290,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void index_permissions_on_permission_change() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user1 = db.users().insertUser();
     UserDto user2 = db.users().insertUser();
     db.users().insertProjectPermissionOnUser(user1, USER, project);
@@ -305,13 +307,13 @@ public class PermissionIndexerTest {
 
   @Test
   public void delete_permissions_on_project_deletion() {
-    ComponentDto project = createAndIndexPrivateProject();
+    ProjectDto project = createAndIndexPrivateProject();
     UserDto user = db.users().insertUser();
     db.users().insertProjectPermissionOnUser(user, USER, project);
     indexPermissions(project, ProjectIndexer.Cause.PROJECT_CREATION);
     verifyAuthorized(project, user);
 
-    db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), PROJECT, project.name(), project.getKey());
+    db.getDbClient().purgeDao().deleteProject(db.getSession(), project.getUuid(), PROJECT, project.getUuid(), project.getKey());
     indexPermissions(project, ProjectIndexer.Cause.PROJECT_DELETION);
 
     verifyNotAuthorized(project, user);
@@ -320,7 +322,7 @@ public class PermissionIndexerTest {
 
   @Test
   public void errors_during_indexing_are_recovered() {
-    ComponentDto project = createAndIndexPublicProject();
+    ProjectDto project = createAndIndexPublicProject();
     es.lockWrites(INDEX_TYPE_FOO_AUTH);
 
     IndexingResult result = indexPermissions(project, PERMISSION_CHANGE);
@@ -351,38 +353,38 @@ public class PermissionIndexerTest {
     underTest.indexOnStartup(underTest.getIndexTypes());
   }
 
-  private void verifyAuthorized(ComponentDto project, UserDto user) {
+  private void verifyAuthorized(EntityDto entity, UserDto user) {
     logIn(user);
-    verifyAuthorized(project, true);
+    verifyAuthorized(entity, true);
   }
 
-  private void verifyAuthorized(ComponentDto project, UserDto user, GroupDto group) {
+  private void verifyAuthorized(EntityDto entity, UserDto user, GroupDto group) {
     logIn(user).setGroups(group);
-    verifyAuthorized(project, true);
+    verifyAuthorized(entity, true);
   }
 
-  private void verifyNotAuthorized(ComponentDto project, UserDto user) {
+  private void verifyNotAuthorized(EntityDto entity, UserDto user) {
     logIn(user);
-    verifyAuthorized(project, false);
+    verifyAuthorized(entity, false);
   }
 
-  private void verifyNotAuthorized(ComponentDto project, UserDto user, GroupDto group) {
+  private void verifyNotAuthorized(EntityDto entity, UserDto user, GroupDto group) {
     logIn(user).setGroups(group);
-    verifyAuthorized(project, false);
+    verifyAuthorized(entity, false);
   }
 
-  private void verifyAnyoneAuthorized(ComponentDto project) {
+  private void verifyAnyoneAuthorized(EntityDto entity) {
     userSession.anonymous();
-    verifyAuthorized(project, true);
+    verifyAuthorized(entity, true);
   }
 
-  private void verifyAnyoneNotAuthorized(ComponentDto project) {
+  private void verifyAnyoneNotAuthorized(EntityDto entity) {
     userSession.anonymous();
-    verifyAuthorized(project, false);
+    verifyAuthorized(entity, false);
   }
 
-  private void verifyAuthorized(ComponentDto project, boolean expectedAccess) {
-    assertThat(fooIndex.hasAccessToProject(project.uuid())).isEqualTo(expectedAccess);
+  private void verifyAuthorized(EntityDto entity, boolean expectedAccess) {
+    assertThat(fooIndex.hasAccessToProject(entity.getUuid())).isEqualTo(expectedAccess);
   }
 
   private UserSessionRule logIn(UserDto u) {
@@ -390,32 +392,32 @@ public class PermissionIndexerTest {
     return userSession;
   }
 
-  private IndexingResult indexPermissions(ComponentDto project, ProjectIndexer.Cause cause) {
+  private IndexingResult indexPermissions(EntityDto entity, ProjectIndexer.Cause cause) {
     DbSession dbSession = db.getSession();
-    Collection<EsQueueDto> items = underTest.prepareForRecovery(dbSession, singletonList(project.uuid()), cause);
+    Collection<EsQueueDto> items = underTest.prepareForRecovery(dbSession, singletonList(entity.getUuid()), cause);
     dbSession.commit();
     return underTest.index(dbSession, items);
   }
 
-  private ComponentDto createUnindexedPublicProject() {
-    return db.components().insertPublicProject().getMainBranchComponent();
+  private ProjectDto createUnindexedPublicProject() {
+    return db.components().insertPublicProject().getProjectDto();
   }
 
-  private ComponentDto createAndIndexPrivateProject() {
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    fooIndexer.indexOnAnalysis(project.uuid());
+  private ProjectDto createAndIndexPrivateProject() {
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+    fooIndexer.indexOnAnalysis(project.getUuid());
     return project;
   }
 
-  private ComponentDto createAndIndexPublicProject() {
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    fooIndexer.indexOnAnalysis(project.uuid());
+  private ProjectDto createAndIndexPublicProject() {
+    ProjectDto project = db.components().insertPublicProject().getProjectDto();
+    fooIndexer.indexOnAnalysis(project.getUuid());
     return project;
   }
 
-  private ComponentDto createAndIndexView() {
-    ComponentDto view = db.components().insertPublicPortfolio();
-    fooIndexer.indexOnAnalysis(view.uuid());
+  private PortfolioDto createAndIndexPortfolio() {
+    PortfolioDto view = db.components().insertPublicPortfolioDto();
+    fooIndexer.indexOnAnalysis(view.getUuid());
     return view;
   }
 
index 09f4e0c5ae0ffd5809e82de79389bf26bd9e66bd..b104d571d7f5fc4997bf24bf19626087625db932 100644 (file)
@@ -30,8 +30,6 @@ import org.sonar.api.web.UserRole;
 import org.sonar.core.util.SequenceUuidFactory;
 import org.sonar.core.util.Uuids;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
-import org.sonar.db.component.ProjectData;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.permission.GlobalPermission;
 import org.sonar.db.permission.GroupPermissionDto;
@@ -176,7 +174,7 @@ public class GroupPermissionChangerIT {
 
   private void applyRemovesPermissionFromGroupOnPrivateProject(String permission) {
     GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group);
-    db.users().insertProjectPermissionOnGroup(group, permission, privateProject);
+    db.users().insertEntityPermissionOnGroup(group, permission, privateProject);
 
     apply(new GroupPermissionChange(PermissionChange.Operation.ADD, permission, privateProject, groupUuid, permissionService));
 
@@ -376,8 +374,8 @@ public class GroupPermissionChangerIT {
   public void remove_project_permission_from_group() {
     GroupUuidOrAnyone groupUuid = GroupUuidOrAnyone.from(group);
     db.users().insertPermissionOnGroup(group, ADMINISTER_QUALITY_GATES);
-    db.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, privateProject);
-    db.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, privateProject);
+    db.users().insertEntityPermissionOnGroup(group, UserRole.ISSUE_ADMIN, privateProject);
+    db.users().insertEntityPermissionOnGroup(group, UserRole.CODEVIEWER, privateProject);
 
     apply(new GroupPermissionChange(PermissionChange.Operation.REMOVE, UserRole.ISSUE_ADMIN, privateProject, groupUuid, permissionService));
 
index e6623c5544a09183b187c96a915ff87ded5aad68..02c060a3a3dc8f7b532fd9f4d5958f121c99ae01 100644 (file)
@@ -186,11 +186,11 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> {
   public void search_groups_with_project_permissions() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     GroupDto group = db.users().insertGroup("project-group-name");
-    db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group, ISSUE_ADMIN, project);
 
     ProjectDto anotherProject = db.components().insertPrivateProject().getProjectDto();
     GroupDto anotherGroup = db.users().insertGroup("another-project-group-name");
-    db.users().insertProjectPermissionOnGroup(anotherGroup, ISSUE_ADMIN, anotherProject);
+    db.users().insertEntityPermissionOnGroup(anotherGroup, ISSUE_ADMIN, anotherProject);
 
     GroupDto groupWithoutPermission = db.users().insertGroup("group-without-permission");
 
@@ -210,7 +210,7 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> {
   public void return_also_groups_without_permission_when_search_query() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     GroupDto group = db.users().insertGroup("group-with-permission");
-    db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group, ISSUE_ADMIN, project);
 
     GroupDto groupWithoutPermission = db.users().insertGroup("group-without-permission");
     GroupDto anotherGroup = db.users().insertGroup("another-group");
@@ -232,7 +232,7 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> {
   public void return_only_groups_with_permission_when_no_search_query() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     GroupDto group = db.users().insertGroup("project-group-name");
-    db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group, ISSUE_ADMIN, project);
 
     GroupDto groupWithoutPermission = db.users().insertGroup("group-without-permission");
 
@@ -250,7 +250,7 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> {
   public void return_anyone_group_when_search_query_and_no_param_permission() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
     GroupDto group = db.users().insertGroup("group-with-permission");
-    db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group, ISSUE_ADMIN, project);
 
     loginAsAdmin();
     String result = newRequest()
@@ -266,7 +266,7 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> {
   public void search_groups_on_views() {
     PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("view-uuid");
     GroupDto group = db.users().insertGroup("project-group-name");
-    db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, portfolio);
+    db.users().insertEntityPermissionOnGroup(group, ISSUE_ADMIN, portfolio);
 
     loginAsAdmin();
     String result = newRequest()
@@ -286,8 +286,8 @@ public class GroupsActionIT extends BasePermissionWsIT<GroupsAction> {
     PortfolioDto portfolio = db.components().insertPrivatePortfolioDto("view-uuid");
     GroupDto managedGroup = db.users().insertGroup("managed-group");
     GroupDto localGroup = db.users().insertGroup("local-group");
-    db.users().insertProjectPermissionOnGroup(managedGroup, ISSUE_ADMIN, portfolio);
-    db.users().insertProjectPermissionOnGroup(localGroup, ISSUE_ADMIN, portfolio);
+    db.users().insertEntityPermissionOnGroup(managedGroup, ISSUE_ADMIN, portfolio);
+    db.users().insertEntityPermissionOnGroup(localGroup, ISSUE_ADMIN, portfolio);
     mockGroupsAsManaged(managedGroup.getUuid());
 
     loginAsAdmin();
index cb598e07c29c602c19e9dd2b4ed8e27aeb9f3942..803de6d34a8fdd6b8ca3743e37f8b843bfd6cd49 100644 (file)
@@ -103,8 +103,8 @@ public class RemoveGroupActionIT extends BasePermissionWsIT<RemoveGroupAction> {
   public void wsAction_shouldRemoveProjectPermission() {
     ProjectDto project = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnGroup(aGroup, GlobalPermission.ADMINISTER);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ADMIN, project);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, project);
     loginAsAdmin();
 
     newRequest()
@@ -121,8 +121,8 @@ public class RemoveGroupActionIT extends BasePermissionWsIT<RemoveGroupAction> {
   public void wsAction_whenUsingViewUuid_shouldRemovePermission() {
     EntityDto portfolio = db.components().insertPrivatePortfolioDto();
     db.users().insertPermissionOnGroup(aGroup, GlobalPermission.ADMINISTER);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ADMIN, portfolio);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, portfolio);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ADMIN, portfolio);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, portfolio);
     loginAsAdmin();
 
     newRequest()
@@ -139,8 +139,8 @@ public class RemoveGroupActionIT extends BasePermissionWsIT<RemoveGroupAction> {
   public void wsAction_whenUsingProjectKey_shouldRemovePermission() {
     ProjectDto project = db.components().insertPublicProject().getProjectDto();
     db.users().insertPermissionOnGroup(aGroup, GlobalPermission.ADMINISTER);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ADMIN, project);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, project);
     loginAsAdmin();
 
     newRequest()
@@ -297,8 +297,8 @@ public class RemoveGroupActionIT extends BasePermissionWsIT<RemoveGroupAction> {
   @Test
   public void wsAction_whenRemovingProjectPermissionAsProjectAdminButNotSystemAdmin_shouldRemovePermission() {
     ProjectDto project = db.components().insertPrivateProject().getProjectDto();
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.CODEVIEWER, project);
-    db.users().insertProjectPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.CODEVIEWER, project);
+    db.users().insertEntityPermissionOnGroup(aGroup, UserRole.ISSUE_ADMIN, project);
 
     userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
     newRequest()
index ac1d148cb876f55c19f6e2eccc7219898646cc3d..ddceb1083724ca801e467e1fad6da87c04494a9c 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.Test;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.util.SequenceUuidFactory;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ResourceTypesRule;
 import org.sonar.db.entity.EntityDto;
 import org.sonar.db.permission.PermissionQuery;
@@ -101,8 +100,8 @@ public class ApplyTemplateActionIT extends BasePermissionWsIT<ApplyTemplateActio
     project = db.components().insertPrivateProject().getProjectDto();
     db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project);
     db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, project);
-    db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, project);
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group1, UserRole.ADMIN, project);
+    db.users().insertEntityPermissionOnGroup(group2, UserRole.ADMIN, project);
   }
 
   @Test
index 6d4de12ed794cac629e83e04b645f411c05f4fb1..8f0952eeb0867cc83094de51f7cc17e1ac1fd44a 100644 (file)
@@ -470,9 +470,9 @@ public class UpdateVisibilityActionIT {
     GroupDto group1 = dbTester.users().insertGroup();
     GroupDto group2 = dbTester.users().insertGroup();
     GroupDto group3 = dbTester.users().insertGroup();
-    dbTester.users().insertProjectPermissionOnGroup(group1, "p1", project);
-    dbTester.users().insertProjectPermissionOnGroup(group1, "p2", project);
-    dbTester.users().insertProjectPermissionOnGroup(group2, "p2", project);
+    dbTester.users().insertEntityPermissionOnGroup(group1, "p1", project);
+    dbTester.users().insertEntityPermissionOnGroup(group1, "p2", project);
+    dbTester.users().insertEntityPermissionOnGroup(group2, "p2", project);
     userSessionRule.addProjectPermission(UserRole.ADMIN, project);
 
     request.setParam(PARAM_PROJECT, project.getKey())
@@ -491,7 +491,7 @@ public class UpdateVisibilityActionIT {
   public void update_a_portfolio_to_private() {
     PortfolioDto portfolio = dbTester.components().insertPublicPortfolioDto();
     GroupDto group = dbTester.users().insertGroup();
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, portfolio);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.ISSUE_ADMIN, portfolio);
     UserDto user = dbTester.users().insertUser();
     dbTester.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, portfolio);
     userSessionRule.addPortfolioPermission(UserRole.ADMIN, portfolio);
@@ -512,9 +512,9 @@ public class UpdateVisibilityActionIT {
     PortfolioDto portfolio = dbTester.components().insertPrivatePortfolioDto();
     userSessionRule.addPortfolioPermission(UserRole.ADMIN, portfolio);
     GroupDto group = dbTester.users().insertGroup();
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, portfolio);
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.USER, portfolio);
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, portfolio);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.ISSUE_ADMIN, portfolio);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.USER, portfolio);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.CODEVIEWER, portfolio);
     UserDto user = dbTester.users().insertUser();
     dbTester.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, portfolio);
     dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, portfolio);
@@ -535,7 +535,7 @@ public class UpdateVisibilityActionIT {
   public void update_an_application_to_private() {
     ProjectDto application = dbTester.components().insertPublicApplication().getProjectDto();
     GroupDto group = dbTester.users().insertGroup();
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, application);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.ISSUE_ADMIN, application);
     UserDto user = dbTester.users().insertUser();
     dbTester.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, application);
     userSessionRule.addProjectPermission(UserRole.ADMIN, application);
@@ -556,9 +556,9 @@ public class UpdateVisibilityActionIT {
     ProjectDto application = dbTester.components().insertPrivateApplication().getProjectDto();
     userSessionRule.addProjectPermission(UserRole.ADMIN, application);
     GroupDto group = dbTester.users().insertGroup();
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.ISSUE_ADMIN, application);
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.USER, application);
-    dbTester.users().insertProjectPermissionOnGroup(group, UserRole.CODEVIEWER, application);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.ISSUE_ADMIN, application);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.USER, application);
+    dbTester.users().insertEntityPermissionOnGroup(group, UserRole.CODEVIEWER, application);
     UserDto user = dbTester.users().insertUser();
     dbTester.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, application);
     dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, application);