aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>2023-06-12 11:05:54 +0200
committersonartech <sonartech@sonarsource.com>2023-06-19 20:03:14 +0000
commit662aa306ee814d748d87b403d5ac03cf04727a2a (patch)
treefd86512cd5156a3e6a7059adad7e397093875b92
parent15d898d6139d8c661aeb27ae5079a737230b7216 (diff)
downloadsonarqube-662aa306ee814d748d87b403d5ac03cf04727a2a.tar.gz
sonarqube-662aa306ee814d748d87b403d5ac03cf04727a2a.zip
SONAR-19445 renamed permissions' component_uuid column to entity_uuid
-rw-r--r--server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java19
-rw-r--r--server/sonar-db-core/src/main/java/org/sonar/db/ColumnMetadata.java24
-rw-r--r--server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java37
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java62
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterIT.java4
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/permission/UserPermissionDaoIT.java12
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/user/RoleDaoIT.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java20
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java14
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java6
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java8
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml56
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml70
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml38
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml8
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml12
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDtoTest.java37
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java24
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java2
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java59
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java47
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRoles.java35
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRoles.java34
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/package-info.java23
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102Test.java40
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java52
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java52
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest/schema.sql9
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest/schema.sql9
-rw-r--r--server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java4
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/GroupPermissionChangerIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java4
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java4
44 files changed, 679 insertions, 210 deletions
diff --git a/server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java b/server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java
index 7d532a01d7a..eb3a3273a00 100644
--- a/server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java
+++ b/server/sonar-db-core/src/it/java/org/sonar/db/DatabaseUtilsIT.java
@@ -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;
@@ -144,6 +145,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()) {
assertThat(isClosed(connection)).isFalse();
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
index 00000000000..cca97b942cc
--- /dev/null
+++ b/server/sonar-db-core/src/main/java/org/sonar/db/ColumnMetadata.java
@@ -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) {
+
+}
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
index 64936983ade..a20a470e39a 100644
--- a/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
+++ b/server/sonar-db-core/src/main/java/org/sonar/db/DatabaseUtils.java
@@ -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) {
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java
index cbd12a7e6a1..f8baeec0a39 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java
@@ -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) {
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterIT.java
index ac48f49dd61..08aa8807aa5 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoWithPersisterIT.java
@@ -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) {
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/permission/UserPermissionDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/permission/UserPermissionDaoIT.java
index c0c1d370973..708c619a343 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/permission/UserPermissionDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/permission/UserPermissionDaoIT.java
@@ -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();
}
}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/user/RoleDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/user/RoleDaoIT.java
index 6449d81d0d3..fda4a64bcb8 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/user/RoleDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/user/RoleDaoIT.java
@@ -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());
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
index 2b217dcbae1..a849fdf29b4 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/GroupPermissionNewValue.java
@@ -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
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
index 7eef54bc022..ed851470f05 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/audit/model/UserPermissionNewValue.java
@@ -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;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
index eb8a6341775..4ede301bed2 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
@@ -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;
}
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
index 4fe4382228b..69d7564bc04 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/UserPermissionDto.java
@@ -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();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
index 104cfecbbcf..2bd50fd0d8e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -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();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 5082748e834..37d18192b92 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -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);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
index 40d65220572..afea4198291 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleDao.java
@@ -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) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
index d8bc3586231..722a79bd40c 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/user/RoleMapper.java
@@ -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);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
index dfed7b50a7f..23a60601945 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml
@@ -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
@@ -25,14 +25,14 @@
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>
@@ -107,7 +107,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.group_uuid != #{groupUuid, jdbcType=VARCHAR} or gu.user_uuid != #{userUuid, jdbcType=VARCHAR})
@@ -116,7 +116,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>
@@ -129,7 +129,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
@@ -137,7 +137,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 != #{userUuid, jdbcType=VARCHAR}
) remaining
@@ -145,7 +145,7 @@
<select id="keepAuthorizedEntityUuidsForUser" parameterType="map" resultType="String">
select
- gr.component_uuid
+ gr.entity_uuid
from
group_roles gr
where
@@ -163,7 +163,7 @@
)
)
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
@@ -173,7 +173,7 @@
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}
@@ -201,14 +201,14 @@
<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
@@ -224,7 +224,7 @@
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=",">
@@ -238,7 +238,7 @@
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=",">
@@ -271,7 +271,7 @@
<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}
@@ -281,7 +281,7 @@
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}
@@ -301,7 +301,7 @@
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
@@ -317,7 +317,7 @@
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
@@ -333,7 +333,7 @@
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
@@ -348,7 +348,7 @@
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}
@@ -356,7 +356,7 @@
) 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}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
index e31b5bff31a..d8b05631817 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
@@ -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}
@@ -60,14 +60,14 @@
<!-- 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">
@@ -86,26 +86,26 @@
<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
@@ -113,7 +113,7 @@
</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 '/'
@@ -122,7 +122,7 @@
<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}
@@ -135,17 +135,17 @@
</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
@@ -156,10 +156,10 @@
#{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>
@@ -167,7 +167,7 @@
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}
@@ -182,7 +182,7 @@
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}
@@ -194,7 +194,7 @@
</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>
@@ -205,7 +205,7 @@
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
@@ -213,7 +213,7 @@
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}
)
@@ -234,26 +234,26 @@
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}
@@ -268,7 +268,7 @@
delete from
group_roles
where
- component_uuid=#{entityUuid,jdbcType=VARCHAR}
+ entity_uuid=#{entityUuid,jdbcType=VARCHAR}
and role=#{permission,jdbcType=VARCHAR}
</delete>
@@ -278,10 +278,10 @@
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
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
index f4436d624cd..afcb58e7867 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/UserPermissionMapper.xml
@@ -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>
@@ -33,13 +33,13 @@
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">
@@ -97,17 +97,17 @@
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">
@@ -116,7 +116,7 @@
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
@@ -124,7 +124,7 @@
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}
)
@@ -134,12 +134,12 @@
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>
@@ -149,7 +149,7 @@
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">
@@ -157,20 +157,20 @@
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>
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index 1b8f8582740..4185dc33127 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -246,16 +246,16 @@
</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">
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
index f40dd2ab25b..a70f2b509e1 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/user/RoleMapper.xml
@@ -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">
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index 8474365add5..bc0e9947b30 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -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
index 00000000000..5212b23d6c6
--- /dev/null
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/UserPermissionDtoTest.java
@@ -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"));
+ }
+}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
index a7cdf783102..40b45e9c8a1 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/user/UserDbTester.java
@@ -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;
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
index dbf2cc0f7fb..5eba25e5f8e 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java
@@ -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
index 00000000000..ec5d97057ff
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/RenameVarcharColumnChange.java
@@ -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
index 00000000000..a306b61bbe5
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
@@ -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
index 00000000000..1ff350ab8bf
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRoles.java
@@ -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
index 00000000000..b5057284c40
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRoles.java
@@ -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
index 00000000000..45880caa19e
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/package-info.java
@@ -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
index 00000000000..ebfb569891e
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102Test.java
@@ -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
index 00000000000..33419e2a005
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest.java
@@ -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
index 00000000000..18a5e5633a5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest.java
@@ -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
index 00000000000..28453ffd067
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInGroupRolesTest/schema.sql
@@ -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
index 00000000000..f19732423ab
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameComponentUuidInUserRolesTest/schema.sql
@@ -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);
diff --git a/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java b/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
index b7573bf1840..7133efd4c54 100644
--- a/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
+++ b/server/sonar-webserver-es/src/it/java/org/sonar/server/permission/index/PermissionIndexerDaoIT.java
@@ -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();
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
index 84f58c913d9..14656ebf5c8 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java
@@ -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}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
index e512b989b44..07e45cb9b15 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java
@@ -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();
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/GroupPermissionChangerIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/GroupPermissionChangerIT.java
index b104d571d7f..dc4ac0794c2 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/GroupPermissionChangerIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/GroupPermissionChangerIT.java
@@ -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();
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java
index 803de6d34a8..72a47beef4d 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java
@@ -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();
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
index 8f0952eeb08..54800a9a8dd 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/project/ws/UpdateVisibilityActionIT.java
@@ -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();
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
index 68a9a8bdc46..6b08f4e7b85 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/GroupPermissionChanger.java
@@ -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))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
index 9cfdb873b28..7390880e6cd 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionTemplateService.java
@@ -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);
});
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
index 62486215e00..5aa2b9bd038 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/SearchMyProjectsAction.java
@@ -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))))
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
index d29872e7c89..aca277a46c0 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/project/ws/UpdateVisibilityAction.java
@@ -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) {