]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19445 renamed permissions' component_uuid column to entity_uuid
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Mon, 12 Jun 2023 09:05:54 +0000 (11:05 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 19 Jun 2023 20:03:14 +0000 (20:03 +0000)
44 files changed:
server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java
server/sonar-db-core/src/main/java/org/sonar/db/ColumnMetadata.java [new file with mode: 0644]
server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/permission/UserPermissionDaoIT.java
server/sonar-db-dao/src/it/java/org/sonar/db/user/RoleDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
server/sonar-db-dao/src/schema/schema-sq.ddl
server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDtoTest.java [new file with mode: 0644]
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRoles.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRoles.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/package-info.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102Test.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest/schema.sql [new file with mode: 0644]
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-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.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/RemoveGroupActionIT.java
server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java

index 7d532a01d7abc51e80bf24e16307ecedbe2ac668..eb3a3273a005d67c8cf25a3cb589ee8f4ab35d9e 100644 (file)
@@ -62,6 +62,7 @@ import static org.sonar.db.DatabaseUtils.closeQuietly;
 import static org.sonar.db.DatabaseUtils.getDriver;
 import static org.sonar.db.DatabaseUtils.log;
 import static org.sonar.db.DatabaseUtils.tableColumnExists;
+import static org.sonar.db.DatabaseUtils.getColumnMetadata;
 import static org.sonar.db.DatabaseUtils.tableExists;
 import static org.sonar.db.DatabaseUtils.toUniqueAndSortedList;
 
@@ -143,6 +144,24 @@ public class DatabaseUtilsIT {
     }
   }
 
+  @Test
+  public void getColumnMetadata_whenTableNameLowerCaseColumnUpperCase_shouldFindColumn() throws SQLException {
+    String tableName = "tablea";
+    String columnName = "COLUMNA";
+    try (Connection connection = dbTester.openConnection()) {
+      assertThat(getColumnMetadata(connection, tableName, columnName)).isNotNull();
+    }
+  }
+
+  @Test
+  public void getColumnMetadata_whenArgumentInUpperCase_shouldFindColumn() throws SQLException {
+    String tableName = "TABLEA";
+    String columnName = "COLUMNA";
+    try (Connection connection = dbTester.openConnection()) {
+      assertThat(getColumnMetadata(connection, tableName, columnName)).isNotNull();
+    }
+  }
+
   @Test
   public void closeQuietly_shouldCloseConnection() throws SQLException {
     try (Connection connection = dbTester.openConnection()) {
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/ColumnMetadata.java b/server/sonar-db-core/src/main/java/org/sonar/db/ColumnMetadata.java
new file mode 100644 (file)
index 0000000..cca97b9
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db;
+
+public record ColumnMetadata(String name, boolean nullable, int sqlType, int limit) {
+
+}
index 64936983adee1f46514a1460e052766e18a5fc15..a20a470e39ae37e93df11c20b8575045c3228f84 100644 (file)
@@ -106,7 +106,7 @@ public class DatabaseUtils {
 
   /**
    * Partition by 1000 elements a list of input and execute a function on each part.
-   *
+   * <p>
    * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
    * and with MsSQL when there's more than 2000 parameters in a query
    */
@@ -116,7 +116,7 @@ public class DatabaseUtils {
 
   /**
    * Partition by 1000 elements a list of input and execute a function on each part.
-   *
+   * <p>
    * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
    * and with MsSQL when there's more than 2000 parameters in a query
    */
@@ -147,7 +147,7 @@ public class DatabaseUtils {
 
   /**
    * Partition by 1000 elements a list of input and execute a consumer on each part.
-   *
+   * <p>
    * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
    * and with MsSQL when there's more than 2000 parameters in a query
    */
@@ -157,7 +157,7 @@ public class DatabaseUtils {
 
   /**
    * Partition by 1000 elements a list of input and execute a consumer on each part.
-   *
+   * <p>
    * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
    * and with MsSQL when there's more than 2000 parameters in a query
    *
@@ -206,7 +206,7 @@ public class DatabaseUtils {
 
   /**
    * Partition by 1000 elements a list of input and execute a consumer on each part.
-   *
+   * <p>
    * The goal is to prevent issue with ORACLE when there's more than 1000 elements in a 'in ('X', 'Y', ...)'
    * and with MsSQL when there's more than 2000 parameters in a query
    */
@@ -403,6 +403,8 @@ public class DatabaseUtils {
     String schema = getSchema(connection);
     try (ResultSet rs = connection.getMetaData().getColumns(connection.getCatalog(), schema, tableName, null)) {
       while (rs.next()) {
+        // this is wrong and could lead to bugs, there is no point of going through each column - only one column contains column name
+        // see the contract (javadoc) of java.sql.DatabaseMetaData.getColumns
         for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
           String name = rs.getString(i);
           if (columnName.equalsIgnoreCase(name)) {
@@ -413,6 +415,31 @@ public class DatabaseUtils {
       return false;
     }
   }
+  @CheckForNull
+  public static ColumnMetadata getColumnMetadata(Connection connection, String tableName, String columnName) throws SQLException {
+    ColumnMetadata columnMetadataLowerCase = getColumnMetadataWithCaseSensitiveTableName(connection, tableName.toLowerCase(Locale.US), columnName);
+    if (columnMetadataLowerCase != null) {
+      return columnMetadataLowerCase;
+    }
+    return getColumnMetadataWithCaseSensitiveTableName(connection, tableName.toUpperCase(Locale.US), columnName);
+  }
+
+  @CheckForNull
+  public static ColumnMetadata getColumnMetadataWithCaseSensitiveTableName(Connection connection, String tableName, String columnName) throws SQLException {
+    String schema = getSchema(connection);
+    try (ResultSet rs = connection.getMetaData().getColumns(connection.getCatalog(), schema, tableName, null)) {
+      while (rs.next()) {
+        String name = rs.getString(4);
+        int type = rs.getInt(5);
+        int limit = rs.getInt(7);
+        boolean nullable = rs.getBoolean(11);
+        if (columnName.equalsIgnoreCase(name)) {
+          return new ColumnMetadata(name, nullable, type, limit);
+        }
+      }
+      return null;
+    }
+  }
 
   @CheckForNull
   static String getDriver(Connection connection) {
index cbd12a7e6a14165650a62deca545ee300d578993..f8baeec0a393ebd3813746866d0bc071997c89e3 100644 (file)
@@ -293,8 +293,8 @@ public class GroupPermissionDaoIT {
     db.users().insertPermissionOnGroup(group1, GlobalPermission.SCAN);
 
     GroupDto group2 = db.users().insertGroup("Group-2");
-    ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent();
-    db.users().insertProjectPermissionOnGroup(group2, UserRole.ADMIN, project);
+    ProjectDto project = db.components().insertPrivateProject().getProjectDto();
+    db.users().insertEntityPermissionOnGroup(group2, UserRole.ADMIN, project);
 
     GroupDto group3 = db.users().insertGroup("Group-3");
     db.users().insertPermissionOnGroup(group3, GlobalPermission.ADMINISTER);
@@ -304,17 +304,17 @@ public class GroupPermissionDaoIT {
     db.users().insertPermissionOnAnyone(GlobalPermission.PROVISION_PROJECTS);
 
     assertThat(underTest.selectByGroupUuids(dbSession, List.of(group1.getUuid()), null))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
       .containsOnly(tuple(group1.getUuid(), GlobalPermission.SCAN.getKey(), null));
 
     assertThat(underTest.selectByGroupUuids(dbSession, List.of(group2.getUuid()), null)).isEmpty();
 
     assertThat(underTest.selectByGroupUuids(dbSession, List.of(group3.getUuid()), null))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
       .containsOnly(tuple(group3.getUuid(), GlobalPermission.ADMINISTER.getKey(), null));
 
     assertThat(underTest.selectByGroupUuids(dbSession, List.of(ANYONE_UUID), null))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
       .containsOnly(
         tuple(ANYONE_UUID, GlobalPermission.SCAN.getKey(), null),
         tuple(ANYONE_UUID, GlobalPermission.PROVISION_PROJECTS.getKey(), null));
@@ -330,34 +330,34 @@ public class GroupPermissionDaoIT {
     db.users().insertPermissionOnGroup(group1, "p1");
 
     GroupDto group2 = db.users().insertGroup("Group-2");
-    ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
-    db.users().insertProjectPermissionOnGroup(group2, "p2", project);
+    ProjectDto project = db.components().insertPublicProject().getProjectDto();
+    db.users().insertEntityPermissionOnGroup(group2, "p2", project);
 
     GroupDto group3 = db.users().insertGroup("Group-3");
-    db.users().insertProjectPermissionOnGroup(group3, "p2", project);
+    db.users().insertEntityPermissionOnGroup(group3, "p2", project);
 
     // Anyone group
     db.users().insertPermissionOnAnyone("p3");
     db.users().insertProjectPermissionOnAnyone("p4", project);
 
-    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group1.getUuid()), project.uuid())).isEmpty();
+    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group1.getUuid()), project.getUuid())).isEmpty();
 
-    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group2.getUuid()), project.uuid()))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
-      .containsOnly(tuple(group2.getUuid(), "p2", project.uuid()));
+    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group2.getUuid()), project.getUuid()))
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
+      .containsOnly(tuple(group2.getUuid(), "p2", project.getUuid()));
 
-    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group3.getUuid()), project.uuid()))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
-      .containsOnly(tuple(group3.getUuid(), "p2", project.uuid()));
+    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group3.getUuid()), project.getUuid()))
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
+      .containsOnly(tuple(group3.getUuid(), "p2", project.getUuid()));
 
-    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(ANYONE_UUID), project.uuid()))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
-      .containsOnly(tuple(ANYONE_UUID, "p4", project.uuid()));
+    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(ANYONE_UUID), project.getUuid()))
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
+      .containsOnly(tuple(ANYONE_UUID, "p4", project.getUuid()));
 
-    assertThat(underTest.selectByGroupUuids(dbSession, asList(group1.getUuid(), group2.getUuid(), ANYONE_UUID), project.uuid())).hasSize(2);
-    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(MISSING_UUID), project.uuid())).isEmpty();
+    assertThat(underTest.selectByGroupUuids(dbSession, asList(group1.getUuid(), group2.getUuid(), ANYONE_UUID), project.getUuid())).hasSize(2);
+    assertThat(underTest.selectByGroupUuids(dbSession, singletonList(MISSING_UUID), project.getUuid())).isEmpty();
     assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group1.getUuid()), "123")).isEmpty();
-    assertThat(underTest.selectByGroupUuids(dbSession, Collections.emptyList(), project.uuid())).isEmpty();
+    assertThat(underTest.selectByGroupUuids(dbSession, Collections.emptyList(), project.getUuid())).isEmpty();
   }
 
   @Test
@@ -378,11 +378,11 @@ public class GroupPermissionDaoIT {
     assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group1.getUuid()), project.uuid())).isEmpty();
 
     assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group2.getUuid()), project.uuid()))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
       .containsOnly(tuple(group2.getUuid(), UserRole.USER, project.uuid()));
 
     assertThat(underTest.selectByGroupUuids(dbSession, singletonList(group3.getUuid()), project.uuid()))
-      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getComponentUuid)
+      .extracting(GroupPermissionDto::getGroupUuid, GroupPermissionDto::getRole, GroupPermissionDto::getEntityUuid)
       .containsOnly(tuple(group3.getUuid(), UserRole.USER, project.uuid()));
 
     assertThat(underTest.selectByGroupUuids(dbSession, singletonList(ANYONE_UUID), project.uuid()))
@@ -530,7 +530,7 @@ public class GroupPermissionDaoIT {
 
     List<GroupPermissionDto> result = new ArrayList<>();
     underTest.selectAllPermissionsByGroupUuid(dbSession, group1.getUuid(), context -> result.add(context.getResultObject()));
-    assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
+    assertThat(result).extracting(GroupPermissionDto::getEntityUuid, GroupPermissionDto::getRole).containsOnly(
       tuple(null, "perm2"),
       tuple(project1.uuid(), "perm3"), tuple(project1.uuid(), "perm4"), tuple(project2.uuid(), "perm5"));
   }
@@ -548,7 +548,7 @@ public class GroupPermissionDaoIT {
 
     List<GroupPermissionDto> result = new ArrayList<>();
     underTest.selectAllPermissionsByGroupUuid(dbSession, group1.getUuid(), context -> result.add(context.getResultObject()));
-    assertThat(result).extracting(GroupPermissionDto::getComponentUuid, GroupPermissionDto::getRole).containsOnly(
+    assertThat(result).extracting(GroupPermissionDto::getEntityUuid, GroupPermissionDto::getRole).containsOnly(
       tuple(null, "perm2"),
       tuple(project1.uuid(), "perm3"), tuple(project1.uuid(), "perm4"), tuple(project2.uuid(), "perm5"));
   }
@@ -622,7 +622,7 @@ public class GroupPermissionDaoIT {
     underTest.deleteByEntityUuid(dbSession, project1);
     dbSession.commit();
 
-    assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.getUuid() + "'")).isZero();
+    assertThat(db.countSql("select count(uuid) from group_roles where entity_uuid ='" + project1.getUuid() + "'")).isZero();
     assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
   }
 
@@ -641,7 +641,7 @@ public class GroupPermissionDaoIT {
     underTest.deleteByEntityUuid(dbSession, project1);
     dbSession.commit();
 
-    assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.getUuid() + "'")).isZero();
+    assertThat(db.countSql("select count(uuid) from group_roles where entity_uuid ='" + project1.getUuid() + "'")).isZero();
     assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
   }
 
@@ -989,19 +989,19 @@ public class GroupPermissionDaoIT {
   }
 
   private Collection<String> getGlobalPermissionsForAnyone() {
-    return getPermissions("group_uuid is null and component_uuid is null");
+    return getPermissions("group_uuid is null and entity_uuid is null");
   }
 
   private Collection<String> getGlobalPermissionsForGroup(GroupDto groupDto) {
-    return getPermissions("group_uuid = '" + groupDto.getUuid() + "' and component_uuid is null");
+    return getPermissions("group_uuid = '" + groupDto.getUuid() + "' and entity_uuid is null");
   }
 
   private Collection<String> getProjectPermissionsForAnyOne(String projectUuid) {
-    return getPermissions("group_uuid is null and component_uuid = '" + projectUuid + "'");
+    return getPermissions("group_uuid is null and entity_uuid = '" + projectUuid + "'");
   }
 
   private Collection<String> getProjectPermissionsForGroup(String projectUuid, GroupDto group) {
-    return getPermissions("group_uuid = '" + group.getUuid() + "' and component_uuid = '" + projectUuid + "'");
+    return getPermissions("group_uuid = '" + group.getUuid() + "' and entity_uuid = '" + projectUuid + "'");
   }
 
   private Collection<String> getPermissions(String whereClauses) {
index ac48f49dd6114bdf45e990ec5b78efd5723f39dc..08aa8807aa520ba942a88811bec4e862ba7d286e 100644 (file)
@@ -201,8 +201,8 @@ public class GroupPermissionDaoWithPersisterIT {
       .setGroupUuid(group != null ? group.getUuid() : null)
       .setGroupName(group != null ? group.getName() : null)
       .setRole(ADMIN)
-      .setComponentUuid(project != null ? project.getUuid() : null)
-      .setComponentName(project != null ? project.getName(): null);
+      .setEntityUuid(project != null ? project.getUuid() : null)
+      .setEntityName(project != null ? project.getName(): null);
   }
 
   private GroupPermissionDto getGroupPermission(GroupDto group) {
index c0c1d3709731459354eddc78780c9aa0a6d12a24..708c619a34330ed24e48602b687d614df9644a1c 100644 (file)
@@ -377,7 +377,7 @@ public class UserPermissionDaoIT {
     // global permission exists -> delete it, but not the project permission with the same name !
     underTest.deleteGlobalPermission(dbSession, user1, "perm1");
 
-    assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='perm1' and component_uuid is null")).isZero();
+    assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='perm1' and entity_uuid is null")).isZero();
     assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4);
   }
 
@@ -512,7 +512,7 @@ public class UserPermissionDaoIT {
     underTest.deleteByUserUuid(dbSession, user1);
     dbSession.commit();
 
-    assertThat(db.select("select user_uuid as \"userUuid\", component_uuid as \"entityUuid\", role as \"permission\" from user_roles"))
+    assertThat(db.select("select user_uuid as \"userUuid\", entity_uuid as \"entityUuid\", role as \"permission\" from user_roles"))
       .extracting((row) -> row.get("userUuid"), (row) -> row.get("entityUuid"), (row) -> row.get("permission"))
       .containsOnly(tuple(user2.getUuid(), null, GlobalPermission.SCAN.getKey()), tuple(user2.getUuid(), project.getUuid(), GlobalPermission.ADMINISTER_QUALITY_GATES.getKey()));
   }
@@ -620,10 +620,10 @@ public class UserPermissionDaoIT {
     List<UserPermissionDto> currentPermissions = underTest.selectUserPermissionsByQuery(dbSession, query, expectedUserUuids);
     assertThat(currentPermissions).hasSize(expectedPermissions.length);
     Tuple[] expectedPermissionsAsTuple = Arrays.stream(expectedPermissions)
-      .map(expectedPermission -> tuple(expectedPermission.getUserUuid(), expectedPermission.getPermission(), expectedPermission.getComponentUuid()))
+      .map(expectedPermission -> tuple(expectedPermission.getUserUuid(), expectedPermission.getPermission(), expectedPermission.getEntityUuid()))
       .toArray(Tuple[]::new);
     assertThat(currentPermissions)
-      .extracting(UserPermissionDto::getUserUuid, UserPermissionDto::getPermission, UserPermissionDto::getComponentUuid)
+      .extracting(UserPermissionDto::getUserUuid, UserPermissionDto::getPermission, UserPermissionDto::getEntityUuid)
       .containsOnly(expectedPermissionsAsTuple);
 
     long distinctUsers = stream(expectedPermissions).map(UserPermissionDto::getUserUuid).distinct().count();
@@ -646,11 +646,11 @@ public class UserPermissionDaoIT {
 
   private void assertThatProjectPermissionDoesNotExist(UserDto user, String permission, String projectUuid) {
     assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where role='" + permission + "' and user_uuid='" + user.getUuid()
-      + "' and component_uuid='" + projectUuid + "'"))
+      + "' and entity_uuid ='" + projectUuid + "'"))
       .isZero();
   }
 
   private void assertThatProjectHasNoPermissions(String projectUuid) {
-    assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where component_uuid='" + projectUuid + "'")).isZero();
+    assertThat(db.countSql(dbSession, "select count(uuid) from user_roles where entity_uuid='" + projectUuid + "'")).isZero();
   }
 }
index 6449d81d0d372e95b60987290bdf87ff77b6dff1..fda4a64bcb87525ffee4895429d8c9e09d5599f1 100644 (file)
@@ -58,22 +58,22 @@ public class RoleDaoIT {
 
   @Test
   public void selectComponentUuidsByPermissionAndUserId_throws_IAR_if_permission_USER_is_specified() {
-    expectUnsupportedUserAndCodeViewerPermission(() -> underTest.selectComponentUuidsByPermissionAndUserUuid(dbSession, UserRole.USER, Uuids.createFast()));
+    expectUnsupportedUserAndCodeViewerPermission(() -> underTest.selectEntityUuidsByPermissionAndUserUuid(dbSession, UserRole.USER, Uuids.createFast()));
   }
 
   @Test
   public void selectComponentUuidsByPermissionAndUserId_throws_IAR_if_permission_CODEVIEWER_is_specified() {
-    expectUnsupportedUserAndCodeViewerPermission(() -> underTest.selectComponentUuidsByPermissionAndUserUuid(dbSession, UserRole.CODEVIEWER, Uuids.createFast()));
+    expectUnsupportedUserAndCodeViewerPermission(() -> underTest.selectEntityUuidsByPermissionAndUserUuid(dbSession, UserRole.CODEVIEWER, Uuids.createFast()));
   }
 
   private void expectUnsupportedUserAndCodeViewerPermission(ThrowingCallable callback) {
     assertThatThrownBy(callback)
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessage("Permissions [user, codeviewer] are not supported by selectComponentUuidsByPermissionAndUserUuid");
+      .hasMessage("Permissions [user, codeviewer] are not supported by selectEntityUuidsByPermissionAndUserUuid");
   }
 
   @Test
-  public void selectComponentIdsByPermissionAndUserUuid() {
+  public void selectEntityIdsByPermissionAndUserUuid() {
     db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project1);
     db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project2);
     // global permission - not returned
@@ -83,9 +83,9 @@ public class RoleDaoIT {
     // project permission on another permission - not returned
     db.users().insertProjectPermissionOnUser(user1, UserRole.ISSUE_ADMIN, project1);
 
-    List<String> projectUuids = underTest.selectComponentUuidsByPermissionAndUserUuid(dbSession, UserRole.ADMIN, user1.getUuid());
+    List<String> entityUuids = underTest.selectEntityUuidsByPermissionAndUserUuid(dbSession, UserRole.ADMIN, user1.getUuid());
 
-    assertThat(projectUuids).containsExactly(project1.uuid(), project2.uuid());
+    assertThat(entityUuids).containsExactly(project1.uuid(), project2.uuid());
   }
 
   @Test
@@ -104,7 +104,7 @@ public class RoleDaoIT {
     // project permission on another permission - not returned
     db.users().insertProjectPermissionOnGroup(group1, UserRole.ISSUE_ADMIN, project1);
 
-    List<String> result = underTest.selectComponentUuidsByPermissionAndUserUuid(dbSession, UserRole.ADMIN, user1.getUuid());
+    List<String> result = underTest.selectEntityUuidsByPermissionAndUserUuid(dbSession, UserRole.ADMIN, user1.getUuid());
 
     assertThat(result).containsExactly(project1.uuid(), project2.uuid());
   }
index 2b217dcbae1ede30627f613899a7097914f83b93..a849fdf29b4a57b010418ef52a86237570d047b5 100644 (file)
@@ -42,7 +42,7 @@ public class GroupPermissionNewValue extends PermissionNewValue {
   }
 
   public GroupPermissionNewValue(GroupPermissionDto dto, @Nullable String componentKey, @Nullable String qualifier, @Nullable PermissionTemplateDto permissionTemplate) {
-    this(dto.getUuid(), dto.getComponentUuid(), componentKey, dto.getComponentName(), dto.getRole(), dto.getGroupUuid(), dto.getGroupName(), qualifier, permissionTemplate);
+    this(dto.getUuid(), dto.getEntityUuid(), componentKey, dto.getEntityName(), dto.getRole(), dto.getGroupUuid(), dto.getGroupName(), qualifier, permissionTemplate);
   }
 
   @Nullable
index 7eef54bc022da93a193b6378f7fbc31d779dc449..ed851470f05fbe5c09469c7e6b2388ed770f3132 100644 (file)
@@ -34,7 +34,7 @@ public class UserPermissionNewValue extends PermissionNewValue {
 
   public UserPermissionNewValue(UserPermissionDto permissionDto, @Nullable String componentKey, @Nullable String componentName,
     @Nullable UserId userId, @Nullable String qualifier, @Nullable PermissionTemplateDto templateDto) {
-    super(permissionDto.getUuid(), permissionDto.getComponentUuid(), componentKey, componentName, permissionDto.getPermission(), qualifier, templateDto);
+    super(permissionDto.getUuid(), permissionDto.getEntityUuid(), componentKey, componentName, permissionDto.getPermission(), qualifier, templateDto);
     this.userUuid = userId != null ? userId.getUuid() : null;
     this.userLogin = userId != null ? userId.getLogin() : null;
   }
index eb8a6341775d2fc8dab76c779bfd11a2a7cb460e..4ede301bed20a9d49b919114c5f5059f59534dde 100644 (file)
@@ -26,8 +26,8 @@ public class GroupPermissionDto {
   private String role;
   private String groupUuid;
   private String groupName;
-  private String componentUuid;
-  private String componentName;
+  private String entityUuid;
+  private String entityName;
 
   public String getUuid() {
     return uuid;
@@ -51,12 +51,12 @@ public class GroupPermissionDto {
   }
 
   @Nullable
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getEntityUuid() {
+    return entityUuid;
   }
 
-  public GroupPermissionDto setComponentUuid(@Nullable String componentUuid) {
-    this.componentUuid = componentUuid;
+  public GroupPermissionDto setEntityUuid(@Nullable String entityUuid) {
+    this.entityUuid = entityUuid;
     return this;
   }
 
@@ -80,12 +80,12 @@ public class GroupPermissionDto {
   }
 
   @Nullable
-  public String getComponentName() {
-    return componentName;
+  public String getEntityName() {
+    return entityName;
   }
 
-  public GroupPermissionDto setComponentName(@Nullable String componentName) {
-    this.componentName = componentName;
+  public GroupPermissionDto setEntityName(@Nullable String entityName) {
+    this.entityName = entityName;
     return this;
   }
 }
index 4fe4382228bdf41aab8c664e8bdf01f41e66b72f..69d7564bc042e0a684bbda18ae5a54948c4e4922 100644 (file)
@@ -26,17 +26,17 @@ public class UserPermissionDto {
   private String uuid;
   private String permission;
   private String userUuid;
-  private String componentUuid;
+  private String entityUuid;
 
   public UserPermissionDto() {
     // used by MyBatis
   }
 
-  public UserPermissionDto(String uuid, String permission, String userUuid, @Nullable String componentUuid) {
+  public UserPermissionDto(String uuid, String permission, String userUuid, @Nullable String entityUuid) {
     this.uuid = uuid;
     this.permission = permission;
     this.userUuid = userUuid;
-    this.componentUuid = componentUuid;
+    this.entityUuid = entityUuid;
   }
 
   public String getUuid() {
@@ -52,11 +52,11 @@ public class UserPermissionDto {
   }
 
   /**
-   * @return {@code null} if it's a global permission, otherwise return the project uiid.
+   * @return {@code null} if it's a global permission, otherwise return the entity uiid.
    */
   @CheckForNull
-  public String getComponentUuid() {
-    return componentUuid;
+  public String getEntityUuid() {
+    return entityUuid;
   }
 
   @Override
@@ -64,7 +64,7 @@ public class UserPermissionDto {
     StringBuilder sb = new StringBuilder("UserPermissionDto{");
     sb.append("permission='").append(permission).append('\'');
     sb.append(", userUuid=").append(userUuid);
-    sb.append(", componentUuid=").append(componentUuid);
+    sb.append(", entityUuid=").append(entityUuid);
     sb.append('}');
     return sb.toString();
   }
index 104cfecbbcf1792d5d362c5a14f536fe9b0e07e3..2bd50fd0d8e57870d8360d9b46e4c800f1af70f5 100644 (file)
@@ -188,14 +188,14 @@ class PurgeCommands {
     profiler.stop();
   }
 
-  void deletePermissions(String rootUuid) {
+  void deletePermissions(String entityUuid) {
     profiler.start("deletePermissions (group_roles)");
-    purgeMapper.deleteGroupRolesByComponentUuid(rootUuid);
+    purgeMapper.deleteGroupRolesByEntityUuid(entityUuid);
     session.commit();
     profiler.stop();
 
     profiler.start("deletePermissions (user_roles)");
-    purgeMapper.deleteUserRolesByComponentUuid(rootUuid);
+    purgeMapper.deleteUserRolesByEntityUuid(entityUuid);
     session.commit();
     profiler.stop();
   }
index 5082748e83419cc6e7e1b1118e69514ed650962c..37d18192b924595386a12931d50952dc61615f0a 100644 (file)
@@ -74,9 +74,9 @@ public interface PurgeMapper {
 
   void deleteComponentsByUuids(@Param("componentUuids") List<String> componentUuids);
 
-  void deleteGroupRolesByComponentUuid(@Param("rootUuid") String rootUuid);
+  void deleteGroupRolesByEntityUuid(@Param("entityUuid") String entityUuid);
 
-  void deleteUserRolesByComponentUuid(@Param("rootUuid") String rootUuid);
+  void deleteUserRolesByEntityUuid(@Param("entityUuid") String entityUuid);
 
   void deleteEventsByComponentUuid(@Param("componentUuid") String componentUuid);
 
index 40d65220572983bdaf08bbfc450c5eb0f1460d76..afea419829197915d10460584534988a5e5f16ab 100644 (file)
@@ -34,17 +34,17 @@ public class RoleDao implements Dao {
   private static final Set<String> UNSUPPORTED_PROJECT_PERMISSIONS = ImmutableSet.of(USER, CODEVIEWER);
 
   /**
-   * All the projects on which the user has {@code permission}, directly or through
+   * All the entities on which the user has {@code permission}, directly or through
    * groups.
    *
    * @throws IllegalArgumentException this method does not support permissions {@link UserRole#USER user} nor
    *         {@link UserRole#CODEVIEWER codeviewer} because it does not support public root components.
    */
-  public List<String> selectComponentUuidsByPermissionAndUserUuid(DbSession dbSession, String permission, String userUuid) {
+  public List<String> selectEntityUuidsByPermissionAndUserUuid(DbSession dbSession, String permission, String userUuid) {
     checkArgument(
       !UNSUPPORTED_PROJECT_PERMISSIONS.contains(permission),
-      "Permissions %s are not supported by selectComponentUuidsByPermissionAndUserUuid", UNSUPPORTED_PROJECT_PERMISSIONS);
-    return mapper(dbSession).selectComponentUuidsByPermissionAndUserUuid(permission, userUuid);
+      "Permissions %s are not supported by selectEntityUuidsByPermissionAndUserUuid", UNSUPPORTED_PROJECT_PERMISSIONS);
+    return mapper(dbSession).selectEntityUuidsByPermissionAndUserUuid(permission, userUuid);
   }
 
   public void deleteGroupRolesByGroupUuid(DbSession session, String groupUuid) {
index d8bc3586231ccc51d6fd14159c875c2a15e860d1..722a79bd40c0656e3570f577b028de1638b061cf 100644 (file)
@@ -24,7 +24,7 @@ import org.apache.ibatis.annotations.Param;
 
 public interface RoleMapper {
 
-  List<String> selectComponentUuidsByPermissionAndUserUuid(@Param("permission") String permission, @Param("userUuid") String userUuid);
+  List<String> selectEntityUuidsByPermissionAndUserUuid(@Param("permission") String permission, @Param("userUuid") String userUuid);
 
   void deleteGroupRolesByGroupUuid(String groupUuid);
 
index dfed7b50a7fd3c76689e6bef850ad4afcd7e7e4c..23a60601945414912284e9c2dd1b331761df79cc 100644 (file)
@@ -8,7 +8,7 @@
     from group_roles gr
     inner join groups_users gu on gr.group_uuid=gu.group_uuid
     where
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     gu.user_uuid=#{userUuid, jdbcType=VARCHAR}
 
     union
@@ -17,7 +17,7 @@
     from group_roles gr
     where
     gr.group_uuid is null and
-    gr.component_uuid is null
+    gr.entity_uuid is null
 
     union
 
     from user_roles ur
     where
     ur.user_uuid=#{userUuid, jdbcType=VARCHAR}
-    and ur.component_uuid is null
+    and ur.entity_uuid is null
   </select>
 
     <select id="selectGlobalPermissionsOfAnonymous" parameterType="map" resultType="string">
     select gr.role
     from group_roles gr
     where
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     gr.group_uuid is null
   </select>
 
@@ -44,7 +44,7 @@
       inner join group_roles gr on gr.group_uuid = gu.group_uuid
       where
       gr.role = #{permission, jdbcType=VARCHAR} and
-      gr.component_uuid is null and
+      gr.entity_uuid is null and
       gr.group_uuid is not null and
       gr.group_uuid != #{excludedGroupUuid, jdbcType=VARCHAR}
 
@@ -53,7 +53,7 @@
       select ur.user_uuid
       from user_roles ur
       where
-      ur.component_uuid is null and
+      ur.entity_uuid is null and
       ur.role = #{permission, jdbcType=VARCHAR}
     ) remaining
   </select>
@@ -66,7 +66,7 @@
     inner join group_roles gr on gr.group_uuid = gu.group_uuid
     where
     gr.role = #{permission, jdbcType=VARCHAR} and
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     gr.group_uuid is not null and
     gu.user_uuid != #{excludedUserUuid, jdbcType=VARCHAR}
 
@@ -75,7 +75,7 @@
     select ur.user_uuid
     from user_roles ur
     where
-    ur.component_uuid is null and
+    ur.entity_uuid is null and
     ur.role = #{permission, jdbcType=VARCHAR} and
     ur.user_uuid != #{excludedUserUuid, jdbcType=VARCHAR}
     ) remaining
@@ -87,7 +87,7 @@
     inner join group_roles gr on gr.group_uuid = gu.group_uuid
     where
     gr.role = #{permission, jdbcType=VARCHAR} and
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     gr.group_uuid is not null
 
     union
@@ -95,7 +95,7 @@
     select ur.user_uuid
     from user_roles ur
     where
-    ur.component_uuid is null and
+    ur.entity_uuid is null and
     ur.role = #{permission, jdbcType=VARCHAR}
   </select>
 
     inner join group_roles gr on gr.group_uuid = gu.group_uuid
     where
     gr.role = #{permission, jdbcType=VARCHAR} and
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     gr.group_uuid is not null and
     (gu.group_uuid != #{groupUuid, jdbcType=VARCHAR} or gu.user_uuid != #{userUuid, jdbcType=VARCHAR})
 
     select ur.user_uuid
     from user_roles ur
     where
-    ur.component_uuid is null and
+    ur.entity_uuid is null and
     ur.role = #{permission, jdbcType=VARCHAR}
     ) remaining
   </select>
     inner join group_roles gr on gr.group_uuid = gu.group_uuid
     where
     gr.role = #{permission, jdbcType=VARCHAR} and
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     gr.group_uuid is not null
 
     union
     select ur.user_uuid
     from user_roles ur
     where
-    ur.component_uuid is null and
+    ur.entity_uuid is null and
     ur.role = #{permission, jdbcType=VARCHAR} and
     ur.user_uuid != #{userUuid, jdbcType=VARCHAR}
     ) remaining
 
   <select id="keepAuthorizedEntityUuidsForUser" parameterType="map" resultType="String">
     select
-      gr.component_uuid
+      gr.entity_uuid
     from
       group_roles gr
     where
         )
       )
       and <foreach collection="entityUuids" open="(" close=")" item="element" index="index" separator=" or ">
-            gr.component_uuid=#{element, jdbcType=VARCHAR}
+            gr.entity_uuid=#{element, jdbcType=VARCHAR}
           </foreach>
 
     union
     from
       user_roles ur
     inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on
-      entity.uuid = ur.component_uuid
+      entity.uuid = ur.entity_uuid
     where
       ur.role=#{role, jdbcType=VARCHAR}
       and ur.user_uuid=#{userUuid, jdbcType=INTEGER}
 
     <select id="keepAuthorizedEntityUuidsForAnonymous" parameterType="map" resultType="String">
     select
-      gr.component_uuid
+      gr.entity_uuid
     from
       group_roles gr
     where
       gr.role=#{role, jdbcType=VARCHAR}
       and gr.group_uuid is null
       and <foreach collection="entityUuids" open="(" close=")" item="element" index="index" separator=" or ">
-            gr.component_uuid=#{element, jdbcType=VARCHAR}
+            gr.entity_uuid=#{element, jdbcType=VARCHAR}
           </foreach>
 
     union
     inner join group_roles gr on
       gr.group_uuid=gu.group_uuid
     where
-      gr.component_uuid=#{entityUuid, jdbcType=VARCHAR}
+      gr.entity_uuid=#{entityUuid, jdbcType=VARCHAR}
       and gr.role=#{role, jdbcType=VARCHAR}
       and gu.user_uuid in
         <foreach collection="userUuids" open="(" close=")" item="uuid" separator=",">
     from
       user_roles ur
     where
-      ur.component_uuid=#{entityUuid, jdbcType=VARCHAR}
+      ur.entity_uuid=#{entityUuid, jdbcType=VARCHAR}
       and ur.role=#{role, jdbcType=VARCHAR}
       and ur.user_uuid IN
         <foreach collection="userUuids" open="(" close=")" item="uuid" separator=",">
   <select id="selectEntityPermissions" parameterType="map" resultType="String">
     select ur.role
     from user_roles ur
-    inner join  (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.component_uuid
+    inner join  (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.entity_uuid
     where
       entity.uuid = #{entityUuid, jdbcType=VARCHAR} and
       ur.user_uuid = #{userUuid, jdbcType=VARCHAR}
     select gr.role
     from group_roles gr
     inner join groups_users gu on gr.group_uuid = gu.group_uuid
-    inner join  (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = gr.component_uuid
+    inner join  (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = gr.entity_uuid
     where
       entity.uuid = #{entityUuid, jdbcType=VARCHAR} and
       gu.user_uuid = #{userUuid, jdbcType=VARCHAR}
     from
       group_roles gr
     inner join  (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on
-      entity.uuid = gr.component_uuid
+      entity.uuid = gr.entity_uuid
     where
       entity.uuid = #{entityUuid, jdbcType=VARCHAR}
       and gr.group_uuid is null
     inner join user_roles ur on
       ur.user_uuid = u.uuid
       and ur.role=#{permission, jdbcType=VARCHAR}
-      and ur.component_uuid is null
+      and ur.entity_uuid is null
     where
       u.email is not null
 
     inner join group_roles gr on
       gr.group_uuid = gu.group_uuid
       and gr.role = #{permission, jdbcType=VARCHAR}
-      and gr.component_uuid is null
+      and gr.entity_uuid is null
     where
       u.email is not null
 
         exists (
           select 1
           from user_roles ur
-          inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.component_uuid
+          inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.entity_uuid
           where
             entity.kee =  #{entityKey, jdbcType=VARCHAR}
             and ur.role = #{permission, jdbcType=VARCHAR}
         ) or exists (
           select 1
           from (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity
-          inner join group_roles gr on gr.component_uuid = entity.uuid
+          inner join group_roles gr on gr.entity_uuid = entity.uuid
           inner join groups_users gu on gu.group_uuid = gr.group_uuid
           where
             entity.kee  =  #{entityKey, jdbcType=VARCHAR}
index e31b5bff31ae75d635bcd1ccef7fd296d6bfbe32..d8b056318178cb4d8bc96cfb9bc816573dc01672 100644 (file)
@@ -13,7 +13,7 @@
       SELECT
         g.name as name,
         group_role.role as permission,
-        group_role.component_uuid as entityUuid
+        group_role.entity_uuid as entityUuid
       FROM
         groups g
       INNER JOIN group_roles group_role ON
@@ -23,7 +23,7 @@
       SELECT
         #{anyoneGroup} as name,
         group_role.role as permission,
-        group_role.component_uuid as entityUuid
+        group_role.entity_uuid as entityUuid
       FROM
         group_roles group_role
       where
@@ -41,8 +41,8 @@
 
   <select id="selectProjectKeysWithAnyonePermissions" parameterType="int" resultType="string">
     select distinct(p.kee) as kee from group_roles gr
-    left join projects p on gr.component_uuid = p.uuid
-    where gr.group_uuid is null and gr.component_uuid is not null
+    left join projects p on gr.entity_uuid = p.uuid
+    where gr.group_uuid is null and gr.entity_uuid is not null
     ORDER BY kee ASC
     limit #{max}
   </select>
@@ -50,8 +50,8 @@
   <!-- Oracle -->
   <select id="selectProjectKeysWithAnyonePermissions" parameterType="int" resultType="string" databaseId="oracle">
     select * from (select distinct p.kee as kee from group_roles gr
-    left join projects p on gr.component_uuid = p.uuid
-    where gr.group_uuid is null and gr.component_uuid is not null
+    left join projects p on gr.entity_uuid = p.uuid
+    where gr.group_uuid is null and gr.entity_uuid is not null
     ORDER BY kee ASC
     )
     where rownum &lt;= #{max}
   <!-- SQL Server -->
   <select id="selectProjectKeysWithAnyonePermissions" parameterType="int" resultType="string" databaseId="mssql">
     select distinct top(#{max}) p.kee as kee from group_roles gr
-    left join projects p on gr.component_uuid = p.uuid
-    where gr.group_uuid is null and gr.component_uuid is not null
+    left join projects p on gr.entity_uuid = p.uuid
+    where gr.group_uuid is null and gr.entity_uuid is not null
     ORDER BY kee ASC
   </select>
 
   <select id="countEntitiesWithAnyonePermissions" resultType="int">
-    select count(distinct(gr.component_uuid))
-    from group_roles gr where gr.group_uuid is null and gr.component_uuid is not null
+    select count(distinct(gr.entity_uuid))
+    from group_roles gr where gr.group_uuid is null and gr.entity_uuid is not null
   </select>
 
   <select id="selectGroupNamesByQuery" parameterType="map" resultType="string">
 
   <sql id="groupsByQuery">
     from (
-      select g.uuid as groupUuid, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
+      select g.uuid as groupUuid, g.name as name, gr.role as permission, gr.entity_uuid as entityUuid, gr.uuid as uuid
       from groups g
       left join group_roles gr on g.uuid = gr.group_uuid
       <if test="query.entityUuid == null">
-        and gr.component_uuid is null
+        and gr.entity_uuid is null
       </if>
       <if test="query.entityUuid != null">
-        and gr.component_uuid = #{query.entityUuid,jdbcType=VARCHAR}
+        and gr.entity_uuid = #{query.entityUuid,jdbcType=VARCHAR}
       </if>
 
     union all
 
-    select 'Anyone' as groupUuid, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
+    select 'Anyone' as groupUuid, 'Anyone' as name, gr.role as permission, gr.entity_uuid as entityUuid, gr.uuid as uuid
     from group_roles gr
     <where>
       <if test="query.entityUuid == null">
-        and gr.component_uuid is null
+        and gr.entity_uuid is null
       </if>
       <if test="query.entityUuid != null">
-        and gr.component_uuid = #{query.entityUuid,jdbcType=VARCHAR}
+        and gr.entity_uuid = #{query.entityUuid,jdbcType=VARCHAR}
       </if>
       <if test="query.withAtLeastOnePermission()">
         and gr.group_uuid is null
     </where>
 
     ) sub
-    left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on sub.componentUuid = entity.uuid
+    left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on sub.entityUuid = entity.uuid
     <where>
       <if test="query.searchQueryToSql != null">
         and lower(sub.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/'
       <if test="query.withAtLeastOnePermission()">
         and sub.permission is not null
         <if test="query.entityUuid==null">
-          and sub.componentUuid is null
+          and sub.entityUuid is null
         </if>
         <if test="query.entityUuid!=null">
           and entity.uuid = #{query.entityUuid,jdbcType=VARCHAR}
   </sql>
 
   <select id="selectByGroupUuids" parameterType="map" resultType="GroupPermission">
-    select sub.groupUuid as groupUuid, sub.componentUuid as componentUuid, sub.permission as role
+    select sub.groupUuid as groupUuid, sub.entityUuid as entityUuid, sub.permission as role
     from
       (
-      select gr.group_uuid as groupUuid, gr.component_uuid as componentUuid, gr.role as permission, g.name as name
+      select gr.group_uuid as groupUuid, gr.entity_uuid as entityUuid, gr.role as permission, g.name as name
       from group_roles gr
       inner join groups g ON g.uuid = gr.group_uuid
       where gr.group_uuid is not null
 
       union all
 
-      select 'Anyone' as groupUuid, gr.component_uuid as componentUuid, gr.role as permission, 'Anyone' as name
+      select 'Anyone' as groupUuid, gr.entity_uuid as entityUuid, gr.role as permission, 'Anyone' as name
       from group_roles gr
       where
       gr.group_uuid is null
         #{groupUuid,jdbcType=VARCHAR}
       </foreach>
       <if test="entityUuid != null">
-        and sub.componentUuid=#{entityUuid,jdbcType=VARCHAR}
+        and sub.entityUuid = #{entityUuid,jdbcType=VARCHAR}
       </if>
       <if test="entityUuid==null">
-        and sub.componentUuid is null
+        and sub.entityUuid is null
       </if>
   </select>
 
     select gr.role
     from group_roles gr
     where
-    gr.component_uuid is null and
+    gr.entity_uuid is null and
     <choose>
       <when test="groupUuid != null">
         gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
     select gr.role
     from group_roles gr
     where
-    gr.component_uuid = #{entityUuid,jdbcType=VARCHAR} and
+    gr.entity_uuid = #{entityUuid,jdbcType=VARCHAR} and
     <choose>
       <when test="groupUuid != null">
         gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
   </select>
 
   <select id="selectAllPermissionsByGroupUuid" parameterType="map" resultType="GroupPermission">
-    select gr.group_uuid as groupUuid, gr.component_uuid as componentUuid, gr.role as role
+    select gr.group_uuid as groupUuid, gr.entity_uuid as entityUuid, gr.role as role
     from group_roles gr
     where gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
   </select>
     from
       group_roles gr1
     where
-      gr1.component_uuid = #{entityUuid,jdbcType=VARCHAR}
+      gr1.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
       and gr1.group_uuid is not null
       and not exists (
         select
         from
           group_roles gr2
         where
-          gr2.component_uuid = gr1.component_uuid
+          gr2.entity_uuid = gr1.entity_uuid
           and gr2.group_uuid = gr1.group_uuid
           and gr2.role = #{role,jdbcType=VARCHAR}
       )
     insert into group_roles (
     uuid,
     group_uuid,
-    component_uuid,
+    entity_uuid,
     role
     ) values (
     #{uuid,jdbcType=VARCHAR},
     #{groupUuid,jdbcType=VARCHAR},
-    #{componentUuid,jdbcType=BIGINT},
+    #{entityUuid,jdbcType=BIGINT},<!--Why big int?-->
     #{role,jdbcType=VARCHAR}
     )
   </insert>
 
   <delete id="deleteByEntityUuid" parameterType="String">
     delete from group_roles
-    where component_uuid=#{entityUuid,jdbcType=VARCHAR}
+    where entity_uuid=#{entityUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteByEntityUuidAndGroupUuid">
     delete from
       group_roles
     where
-      component_uuid=#{entityUuid,jdbcType=VARCHAR}
+      entity_uuid=#{entityUuid,jdbcType=VARCHAR}
       <choose>
         <when test="groupUuid != null">
           and group_uuid = #{groupUuid,jdbcType=VARCHAR}
     delete from
       group_roles
     where
-      component_uuid=#{entityUuid,jdbcType=VARCHAR}
+      entity_uuid=#{entityUuid,jdbcType=VARCHAR}
       and role=#{permission,jdbcType=VARCHAR}
   </delete>
 
     role=#{permission,jdbcType=VARCHAR} and
     <choose>
       <when test="entityUuid != null">
-        component_uuid=#{entityUuid,jdbcType=BIGINT}
+        entity_uuid=#{entityUuid,jdbcType=BIGINT}
       </when>
       <otherwise>
-        component_uuid is null
+        entity_uuid is null
       </otherwise>
     </choose>
     and
index f4436d624cd71a572db462d07bd3c84afedc65bf..afcb58e7867b3d8c175e4181c461f4b125088df8 100644 (file)
@@ -6,7 +6,7 @@
   <select id="selectUserPermissionsByQueryAndUserUuids" parameterType="map" resultType="org.sonar.db.permission.UserPermissionDto">
     select
       u.uuid as userUuid,
-      ur.component_uuid as componentUuid,
+      ur.entity_uuid as entityUuid,
       ur.role as permission
     <include refid="sqlQueryJoins"/>
     <where>
     left join user_roles ur on ur.user_uuid = u.uuid
     <choose>
       <when test="query.entityUuid == null">
-        and ur.component_uuid is null
+        and ur.entity_uuid is null
       </when>
       <otherwise>
-        and ur.component_uuid = #{query.entityUuid,jdbcType=VARCHAR}
+        and ur.entity_uuid = #{query.entityUuid,jdbcType=VARCHAR}
       </otherwise>
     </choose>
-    left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.component_uuid = entity.uuid
+    left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.entity_uuid = entity.uuid
     <where>
       <include refid="sqlQueryFilters"/>
     </where>
@@ -58,7 +58,7 @@
   <sql id="sqlQueryJoins">
     from users u
     left join user_roles ur on ur.user_uuid = u.uuid
-    left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.component_uuid = entity.uuid
+    left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.entity_uuid = entity.uuid
   </sql>
 
   <sql id="sqlQueryFilters">
@@ -73,7 +73,7 @@
     <if test="query.withAtLeastOnePermission()">
       and ur.role is not null
       <if test="query.entityUuid == null">
-        and ur.component_uuid is null
+        and ur.entity_uuid is null
       </if>
       <if test="query.entityUuid != null">
         and entity.uuid = #{query.entityUuid,jdbcType=VARCHAR}
@@ -89,7 +89,7 @@
     from user_roles ur
     where
     ur.user_uuid = #{userUuid,jdbcType=VARCHAR} and
-    ur.component_uuid is null
+    ur.entity_uuid is null
   </select>
 
   <select id="selectEntityPermissionsOfUser" parameterType="map" resultType="string">
     from user_roles ur
     where
     ur.user_uuid = #{userUuid,jdbcType=VARCHAR} and
-    ur.component_uuid = #{entityUuid,jdbcType=VARCHAR}
+    ur.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
   </select>
 
   <select id="countUsersByEntityPermission" resultType="org.sonar.db.permission.CountPerEntityPermission">
-    select ur.component_uuid as entityUuid, ur.role as permission, count(u.login) as count
+    select ur.entity_uuid as entityUuid, ur.role as permission, count(u.login) as count
     from users u
     inner join user_roles ur on ur.user_uuid = u.uuid
-    inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.component_uuid = entity.uuid
+    inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.entity_uuid = entity.uuid
     where u.active = ${_true}
     and entity.uuid in <foreach collection="entityUuids" open="(" close=")" item="entityUuid" separator=",">#{entityUuid}</foreach>
-    group by ur.component_uuid, ur.role
+    group by ur.entity_uuid, ur.role
   </select>
 
   <select id="selectUserIdsWithPermissionOnEntityBut" resultType="org.sonar.db.user.UserIdDto">
     from
       user_roles ur1 inner join users u on ur1.user_uuid = u.uuid
     where
-      ur1.component_uuid = #{entityUuid,jdbcType=VARCHAR}
+      ur1.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
       and role &lt;&gt; #{permission,jdbcType=VARCHAR}
       and not exists (
         select
         from
           user_roles ur2
         where
-          ur2.component_uuid = ur1.component_uuid
+          ur2.entity_uuid = ur1.entity_uuid
           and ur2.user_uuid = ur1.user_uuid
           and role = #{permission,jdbcType=VARCHAR}
       )
     insert into user_roles (
     uuid,
     user_uuid,
-    component_uuid,
+    entity_uuid,
     role
     ) values (
     #{dto.uuid,jdbcType=VARCHAR},
     #{dto.userUuid,jdbcType=VARCHAR},
-    #{dto.componentUuid,jdbcType=VARCHAR},
+    #{dto.entityUuid,jdbcType=VARCHAR},
     #{dto.permission,jdbcType=VARCHAR}
     )
   </insert>
     where
     role = #{permission,jdbcType=VARCHAR} and
     user_uuid = #{userUuid,jdbcType=VARCHAR} and
-    component_uuid is null
+    entity_uuid is null
   </delete>
 
   <delete id="deleteEntityPermission" parameterType="map">
     where
     role = #{permission,jdbcType=VARCHAR} and
     user_uuid = #{userUuid,jdbcType=VARCHAR} and
-    component_uuid = #{entityUuid,jdbcType=VARCHAR}
+    entity_uuid = #{entityUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteEntityPermissions" parameterType="map">
     delete from user_roles
     where
-    component_uuid = #{entityUuid,jdbcType=VARCHAR}
+    entity_uuid = #{entityUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteEntityPermissionOfAnyUser" parameterType="map">
     delete from
       user_roles
     where
-      component_uuid = #{entityUuid,jdbcType=VARCHAR}
+      entity_uuid = #{entityUuid,jdbcType=VARCHAR}
       and role = #{permission,jdbcType=VARCHAR}
   </delete>
 
index 1b8f85827400011c60f02a3386f8d3fa0f07368c..4185dc33127a7379e805f1a5352bf46a26e045b3 100644 (file)
         </foreach>
   </delete>
 
-  <delete id="deleteGroupRolesByComponentUuid" parameterType="map">
+  <delete id="deleteGroupRolesByEntityUuid" parameterType="map">
     delete from group_roles
     where
-      component_uuid = #{rootUuid,jdbcType=INTEGER}
+      entity_uuid = #{entityUuid,jdbcType=INTEGER}
   </delete>
 
-  <delete id="deleteUserRolesByComponentUuid" parameterType="map">
+  <delete id="deleteUserRolesByEntityUuid" parameterType="map">
     delete from user_roles
     where
-      component_uuid = #{rootUuid,jdbcType=INTEGER}
+      entity_uuid = #{entityUuid,jdbcType=INTEGER}
   </delete>
 
   <delete id="deleteEventsByComponentUuid" parameterType="map">
index f40dd2ab25b9bea40ba6c3038725dd5c60daf161..a70f2b509e18a9f73a066137eff820eb8092d03f 100644 (file)
@@ -3,28 +3,28 @@
 
 <mapper namespace="org.sonar.db.user.RoleMapper">
 
-  <select id="selectComponentUuidsByPermissionAndUserUuid" parameterType="map" resultType="String">
+  <select id="selectEntityUuidsByPermissionAndUserUuid" parameterType="map" resultType="String">
     select
-      ur.component_uuid
+      ur.entity_uuid
     from
       user_roles ur
     where
       ur.user_uuid = #{userUuid,jdbcType=VARCHAR}
       and ur.role = #{permission,jdbcType=VARCHAR}
-      and ur.component_uuid is not null
+      and ur.entity_uuid is not null
     union
     select
-      gr.component_uuid
+      gr.entity_uuid
     from
       group_roles gr
     inner join groups_users gu on
       gr.group_uuid=gu.group_uuid
     where
       gr.role = #{permission,jdbcType=VARCHAR}
-      and gr.component_uuid is not null
+      and gr.entity_uuid is not null
       and gu.user_uuid=#{userUuid,jdbcType=VARCHAR}
     order by
-      component_uuid
+      entity_uuid
   </select>
 
   <delete id="deleteGroupRolesByGroupUuid" parameterType="String">
index 8474365add516ae91cd2dcc7af0011280b4c829b..bc0e9947b3061f6f795bc059b8c1898173799f52 100644 (file)
@@ -341,12 +341,12 @@ CREATE INDEX "FILE_SOURCES_UPDATED_AT" ON "FILE_SOURCES"("UPDATED_AT" NULLS FIRS
 CREATE TABLE "GROUP_ROLES"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "ROLE" CHARACTER VARYING(64) NOT NULL,
-    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "ENTITY_UUID" CHARACTER VARYING(40),
     "GROUP_UUID" CHARACTER VARYING(40)
 );
 ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID");
-CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID" NULLS FIRST);
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "COMPONENT_UUID" NULLS FIRST, "ROLE" NULLS FIRST);
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("ENTITY_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "ENTITY_UUID" NULLS FIRST, "ROLE" NULLS FIRST);
 
 CREATE TABLE "GROUPS"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
@@ -1007,11 +1007,11 @@ CREATE INDEX "UDM_MESSAGE_TYPE" ON "USER_DISMISSED_MESSAGES"("MESSAGE_TYPE" NULL
 CREATE TABLE "USER_ROLES"(
     "UUID" CHARACTER VARYING(40) NOT NULL,
     "ROLE" CHARACTER VARYING(64) NOT NULL,
-    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "ENTITY_UUID" CHARACTER VARYING(40),
     "USER_UUID" CHARACTER VARYING(255)
 );
 ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID");
-CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("ENTITY_UUID" NULLS FIRST);
 CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID" NULLS FIRST);
 
 CREATE TABLE "USER_TOKENS"(
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDtoTest.java
new file mode 100644 (file)
index 0000000..5212b23
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db.permission;
+
+import java.util.List;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class UserPermissionDtoTest {
+
+  @Test
+  public void toString_shouldReturnInformationAboutAllFieldsExceptUuid() {
+    UserPermissionDto userPermissionDto = new UserPermissionDto("someUuid", "somePermission", "someUserUuid", "someEntityUuid");
+
+    String toStringResult = userPermissionDto.toString();
+
+    assertThat(toStringResult).contains(List.of("somePermission", "someUserUuid", "someEntityUuid"));
+  }
+}
index a7cdf78310217bffe5ab4f55d258dca873917861..40b45e9c8a1500c5172ec427ec02470f929e5272 100644 (file)
@@ -267,8 +267,8 @@ public class UserDbTester {
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
       .setRole(permission)
-      .setComponentUuid(project.uuid())
-      .setComponentName(project.name());
+      .setEntityUuid(project.uuid())
+      .setEntityName(project.name());
 
     // TODO, will be removed later
     ProjectDto projectDto = new ProjectDto();
@@ -288,8 +288,8 @@ public class UserDbTester {
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
       .setRole(permission)
-      .setComponentUuid(project.getUuid())
-      .setComponentName(project.getName());
+      .setEntityUuid(project.getUuid())
+      .setEntityName(project.getName());
     db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project, null);
     db.commit();
     return dto;
@@ -311,8 +311,8 @@ public class UserDbTester {
       .setGroupUuid(group.getUuid())
       .setGroupName(group.getName())
       .setRole(permission)
-      .setComponentUuid(project.uuid())
-      .setComponentName(project.name());
+      .setEntityUuid(project.uuid())
+      .setEntityName(project.name());
 
     // TODO, will be removed later
     ProjectDto projectDto = new ProjectDto();
@@ -323,10 +323,10 @@ public class UserDbTester {
     return dto;
   }
 
-  public GroupPermissionDto insertEntityPermissionOnGroup(GroupDto group, String permission, EntityDto entityDto) {
-    checkArgument(entityDto.isPrivate() || !PUBLIC_PERMISSIONS.contains(permission),
+  public GroupPermissionDto insertEntityPermissionOnGroup(GroupDto group, String permission, EntityDto entity) {
+    checkArgument(entity.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());
+    Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), entity.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()
@@ -334,9 +334,9 @@ public class UserDbTester {
       .setGroupUuid(group.getUuid())
       .setGroupName(group.getName())
       .setRole(permission)
-      .setComponentUuid(entityDto.getUuid())
-      .setComponentName(entityDto.getUuid());
-    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, entityDto, null);
+      .setEntityUuid(entity.getUuid())
+      .setEntityName(entity.getName());
+    db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, entity, null);
     db.commit();
     return dto;
   }
index dbf2cc0f7fba02ad27c1b4694e760f0f00e0a0b3..5eba25e5f8e1fccb3ec46140fe0a325d4c5e8258 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.server.platform.db.migration.step.MigrationStepsProvider;
 import org.sonar.server.platform.db.migration.version.v00.DbVersion00;
 import org.sonar.server.platform.db.migration.version.v100.DbVersion100;
 import org.sonar.server.platform.db.migration.version.v101.DbVersion101;
+import org.sonar.server.platform.db.migration.version.v102.DbVersion102;
 
 public class MigrationConfigurationModule extends Module {
   @Override
@@ -40,6 +41,7 @@ public class MigrationConfigurationModule extends Module {
       DbVersion00.class,
       DbVersion100.class,
       DbVersion101.class,
+      DbVersion102.class,
 
       // migration steps
       MigrationStepRegistryImpl.class,
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java
new file mode 100644 (file)
index 0000000..ec5d970
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.step;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.ColumnMetadata;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.ColumnDef;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder;
+
+public abstract class RenameVarcharColumnChange extends DdlChange {
+
+  private final String table;
+  private final String oldColumn;
+  private final String newColumn;
+
+  protected RenameVarcharColumnChange(Database db, String table, String oldColumn, String newColumn) {
+    super(db);
+    this.table = table;
+    this.oldColumn = oldColumn;
+    this.newColumn = newColumn;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    try (Connection c = getDatabase().getDataSource().getConnection()) {
+      ColumnMetadata oldColumnMetadata = DatabaseUtils.getColumnMetadata(c, table, oldColumn);
+      if (!DatabaseUtils.tableColumnExists(c, table, newColumn) && oldColumnMetadata != null) {
+        ColumnDef newColumnDef = new VarcharColumnDef.Builder()
+          .setColumnName(newColumn)
+          .setIsNullable(oldColumnMetadata.nullable())
+          .setLimit(oldColumnMetadata.limit())
+          .build();
+
+        context.execute(new RenameColumnsBuilder(getDialect(), table).renameColumn(oldColumn, newColumnDef).build());
+      }
+    }
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
new file mode 100644 (file)
index 0000000..a306b61
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
+import org.sonar.server.platform.db.migration.version.DbVersion;
+
+// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
+@SuppressWarnings("java:S3937")
+public class DbVersion102 implements DbVersion {
+
+  /**
+   * We use the start of the 10.X cycle as an opportunity to align migration numbers with the SQ version number.
+   * Please follow this pattern:
+   * 10_0_000
+   * 10_0_001
+   * 10_0_002
+   * 10_1_000
+   * 10_1_001
+   * 10_1_002
+   * 10_2_000
+   */
+
+  @Override
+  public void addSteps(MigrationStepRegistry registry) {
+    registry.add(10_2_000, "Rename 'component_uuid' in 'user_roles' table to 'entity_uuid'", RenameComponentUuidInUserRoles.class)
+      .add(10_2_001, "Rename 'component_uuid' in 'group_roles' table to 'entity_uuid'", RenameComponentUuidInGroupRoles.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRoles.java
new file mode 100644 (file)
index 0000000..1ff350a
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameComponentUuidInGroupRoles extends RenameVarcharColumnChange {
+
+  private static final String TABLE_NAME = "group_roles";
+  private static final String OLD_COLUMN_NAME = "component_uuid";
+  private static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  public RenameComponentUuidInGroupRoles(Database db) {
+    super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRoles.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRoles.java
new file mode 100644 (file)
index 0000000..b505728
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameComponentUuidInUserRoles extends RenameVarcharColumnChange {
+
+  private static final String TABLE_NAME = "user_roles";
+  private static final String OLD_COLUMN_NAME = "component_uuid";
+  private static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  public RenameComponentUuidInUserRoles(Database db) {
+    super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/package-info.java
new file mode 100644 (file)
index 0000000..45880ca
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v102;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102Test.java
new file mode 100644 (file)
index 0000000..ebfb569
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import org.junit.Test;
+
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+public class DbVersion102Test {
+  private final DbVersion102 underTest = new DbVersion102();
+
+  @Test
+  public void migrationNumber_starts_at_10_2_000() {
+    verifyMinimumMigrationNumber(underTest, 10_2_000);
+  }
+
+  @Test
+  public void verify_migration_is_not_empty() {
+    verifyMigrationNotEmpty(underTest);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java
new file mode 100644 (file)
index 0000000..33419e2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameComponentUuidInGroupRolesTest {
+  public static final String TABLE_NAME = "group_roles";
+  public static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(RenameComponentUuidInGroupRolesTest.class, "schema.sql");
+
+  private final RenameComponentUuidInGroupRoles underTest = new RenameComponentUuidInGroupRoles(db.database());
+
+  @Test
+  public void columnIsRenamed() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java
new file mode 100644 (file)
index 0000000..18a5e56
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+
+public class RenameComponentUuidInUserRolesTest {
+  public static final String TABLE_NAME = "user_roles";
+  public static final String NEW_COLUMN_NAME = "entity_uuid";
+
+  @Rule
+  public final CoreDbTester db = CoreDbTester.createForSchema(RenameComponentUuidInUserRolesTest.class, "schema.sql");
+
+  private final RenameComponentUuidInUserRoles underTest = new RenameComponentUuidInUserRoles(db.database());
+
+  @Test
+  public void columnIsRenamed() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+    underTest.execute();
+    underTest.execute();
+    db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, VARCHAR, 40, true);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest/schema.sql
new file mode 100644 (file)
index 0000000..28453ff
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "GROUP_ROLES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "ROLE" CHARACTER VARYING(64) NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "GROUP_UUID" CHARACTER VARYING(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("GROUP_UUID" NULLS FIRST, "COMPONENT_UUID" NULLS FIRST, "ROLE" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest/schema.sql
new file mode 100644 (file)
index 0000000..f197324
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE "USER_ROLES"(
+    "UUID" CHARACTER VARYING(40) NOT NULL,
+    "ROLE" CHARACTER VARYING(64) NOT NULL,
+    "COMPONENT_UUID" CHARACTER VARYING(40),
+    "USER_UUID" CHARACTER VARYING(255)
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("UUID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_UUID" NULLS FIRST);
index b7573bf1840d09a52d021a832ac7c3bbd67d8423..7133efd4c540fb8a81358a8bc81c4bc885a2b3e8 100644 (file)
@@ -176,8 +176,8 @@ public class PermissionIndexerDaoIT {
         .setGroupUuid(group.getUuid())
         .setGroupName(group.getName())
         .setRole(USER)
-        .setComponentUuid(project.projectUuid())
-        .setComponentName(project.getProjectDto().getName());
+        .setEntityUuid(project.projectUuid())
+        .setEntityName(project.getProjectDto().getName());
       dbClient.groupPermissionDao().insert(dbSession, dto, project.getProjectDto(), null);
     }
     dbSession.commit();
index 84f58c913d92ef7669c2d9d1148df14ef95494a8..14656ebf5c8a4b0ae66335594cbda8aded6bb957 100644 (file)
@@ -66,14 +66,14 @@ public class PermissionIndexerDao {
                  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'
+                   INNER JOIN user_roles ON user_roles.entity_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'
+                              ON group_roles.entity_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}
index e512b989b4413da5b395bcd15149ec914ecfebca..07e45cb9b15d0d35958574930bc451b573668bf5 100644 (file)
@@ -1871,8 +1871,8 @@ public class SearchActionIT {
       new GroupPermissionDto()
         .setUuid(Uuids.createFast())
         .setGroupUuid(null)
-        .setComponentUuid(project.getUuid())
-        .setComponentName(project.getName())
+        .setEntityUuid(project.getUuid())
+        .setEntityName(project.getName())
         .setRole(permission),
       project, null);
     session.commit();
index b104d571d7f5fc4997bf24bf19626087625db932..dc4ac0794c21ee535d6855c6bf00a0721cee9c6b 100644 (file)
@@ -425,8 +425,8 @@ public class GroupPermissionChangerIT {
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
       .setRole(perm)
-      .setComponentUuid(privateProject.getUuid())
-      .setComponentName(privateProject.getName());
+      .setEntityUuid(privateProject.getUuid())
+      .setEntityName(privateProject.getName());
     db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, privateProject, null);
     db.commit();
   }
index 803de6d34a8fdd6b8ca3743e37f8b843bfd6cd49..72a47beef4d441b677b531c17ba848f5a7a1d2a6 100644 (file)
@@ -455,8 +455,8 @@ public class RemoveGroupActionIT extends BasePermissionWsIT<RemoveGroupAction> {
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
       .setRole(perm)
-      .setComponentUuid(project.getUuid())
-      .setComponentName(project.getName());
+      .setEntityUuid(project.getUuid())
+      .setEntityName(project.getName());
     db.getDbClient().groupPermissionDao().insert(db.getSession(), dto, project, null);
     db.commit();
   }
index 8f0952eeb0867cc83094de51f7cc17e1ac1fd44a..54800a9a8ddec001c7d974c0169d7ced45ce65c6 100644 (file)
@@ -595,8 +595,8 @@ public class UpdateVisibilityActionIT {
       .setUuid(Uuids.createFast())
       .setGroupUuid(null)
       .setRole(permission)
-      .setComponentUuid(projectDto.getUuid())
-      .setComponentName(projectDto.getName());
+      .setEntityUuid(projectDto.getUuid())
+      .setEntityName(projectDto.getName());
     dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto, projectDto, null);
     dbTester.commit();
   }
@@ -607,8 +607,8 @@ public class UpdateVisibilityActionIT {
       .setGroupUuid(group.getUuid())
       .setGroupName(group.getName())
       .setRole(permission)
-      .setComponentUuid(projectDto.getUuid())
-      .setComponentName(projectDto.getName());
+      .setEntityUuid(projectDto.getUuid())
+      .setEntityName(projectDto.getName());
     dbTester.getDbClient().groupPermissionDao().insert(dbTester.getSession(), dto, projectDto, null);
     dbTester.commit();
   }
index 68a9a8bdc46906398faa68ccfdc5a0f1a8ad1d78..6b08f4e7b85442027a4f10efcb8cb540046c2671 100644 (file)
@@ -122,8 +122,8 @@ public class GroupPermissionChanger {
       .setUuid(uuidFactory.create())
       .setRole(change.getPermission())
       .setGroupUuid(groupUuid)
-      .setComponentName(change.getProjectName())
-      .setComponentUuid(change.getProjectUuid());
+      .setEntityName(change.getProjectName())
+      .setEntityUuid(change.getProjectUuid());
 
     Optional.ofNullable(groupUuid)
       .map(uuid -> dbClient.groupDao().selectByUuid(dbSession, groupUuid))
index 9cfdb873b28ce0e36e7a9f7aba95a6eda7091f97..7390880e6cd8e6e9866e44c470e588751dbf513a 100644 (file)
@@ -154,8 +154,8 @@ public class PermissionTemplateService {
           .setGroupUuid(groupUuid)
           .setGroupName(groupName)
           .setRole(gp.getPermission())
-          .setComponentUuid(entity.getUuid())
-          .setComponentName(entity.getName());
+          .setEntityUuid(entity.getUuid())
+          .setEntityName(entity.getName());
 
         dbClient.groupPermissionDao().insert(dbSession, dto, entity, template);
       });
index 62486215e00e28fb78d013a6364727c3b089b240..5aa2b9bd038b3aa35f2fa2cd79262a1c42b3bfd1 100644 (file)
@@ -190,7 +190,7 @@ public class SearchMyProjectsAction implements ProjectsWsAction {
   private ProjectsResult searchProjects(DbSession dbSession, SearchMyProjectsRequest request) {
     String userUuid = requireNonNull(userSession.getUuid(), "Current user must be authenticated");
 
-    List<String> componentUuids = dbClient.roleDao().selectComponentUuidsByPermissionAndUserUuid(dbSession, UserRole.ADMIN, userUuid);
+    List<String> componentUuids = dbClient.roleDao().selectEntityUuidsByPermissionAndUserUuid(dbSession, UserRole.ADMIN, userUuid);
     ComponentQuery dbQuery = ComponentQuery.builder()
       .setQualifiers(Qualifiers.PROJECT)
       .setComponentUuids(ImmutableSet.copyOf(componentUuids.subList(0, Math.min(componentUuids.size(), DatabaseUtils.PARTITION_SIZE_FOR_ORACLE))))
index d29872e7c890686ae7bc2d10d327b44883376238..aca277a46c0c6239e6290045b0519390a84b48d8 100644 (file)
@@ -173,11 +173,11 @@ public class UpdateVisibilityAction implements ProjectsWsAction {
     String groupName = ofNullable(dbClient.groupDao().selectByUuid(dbSession, groupUuid)).map(GroupDto::getName).orElse(null);
     dbClient.groupPermissionDao().insert(dbSession, new GroupPermissionDto()
       .setUuid(uuidFactory.create())
-      .setComponentUuid(entity.getUuid())
+      .setEntityUuid(entity.getUuid())
       .setGroupUuid(groupUuid)
       .setGroupName(groupName)
       .setRole(permission)
-      .setComponentName(entity.getName()), entity, null);
+      .setEntityName(entity.getName()), entity, null);
   }
 
   private void updatePermissionsToPublic(DbSession dbSession, EntityDto entity) {