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;
}
}
+ @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()) {
--- /dev/null
+/*
+ * 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) {
+
+}
/**
* 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
*/
/**
* 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
*/
/**
* 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
*/
/**
* 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
*
/**
* 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
*/
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)) {
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) {
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);
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));
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
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()))
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"));
}
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"));
}
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);
}
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);
}
}
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) {
.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) {
// 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);
}
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()));
}
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();
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();
}
}
@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
// 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
// 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());
}
}
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
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;
}
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;
}
@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;
}
}
@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;
}
}
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() {
}
/**
- * @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
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();
}
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();
}
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);
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) {
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);
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
from group_roles gr
where
gr.group_uuid is null and
- gr.component_uuid is null
+ gr.entity_uuid is null
union
from user_roles ur
where
ur.user_uuid=#{userUuid, jdbcType=VARCHAR}
- and ur.component_uuid is null
+ and ur.entity_uuid is null
</select>
<select id="selectGlobalPermissionsOfAnonymous" parameterType="map" resultType="string">
select gr.role
from group_roles gr
where
- gr.component_uuid is null and
+ gr.entity_uuid is null and
gr.group_uuid is null
</select>
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}
select ur.user_uuid
from user_roles ur
where
- ur.component_uuid is null and
+ ur.entity_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR}
) remaining
</select>
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.component_uuid is null and
+ gr.entity_uuid is null and
gr.group_uuid is not null and
gu.user_uuid != #{excludedUserUuid, jdbcType=VARCHAR}
select ur.user_uuid
from user_roles ur
where
- ur.component_uuid is null and
+ ur.entity_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR} and
ur.user_uuid != #{excludedUserUuid, jdbcType=VARCHAR}
) remaining
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.component_uuid is null and
+ gr.entity_uuid is null and
gr.group_uuid is not null
union
select ur.user_uuid
from user_roles ur
where
- ur.component_uuid is null and
+ ur.entity_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR}
</select>
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.component_uuid is null and
+ gr.entity_uuid is null and
gr.group_uuid is not null and
(gu.group_uuid != #{groupUuid, jdbcType=VARCHAR} or gu.user_uuid != #{userUuid, jdbcType=VARCHAR})
select ur.user_uuid
from user_roles ur
where
- ur.component_uuid is null and
+ ur.entity_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR}
) remaining
</select>
inner join group_roles gr on gr.group_uuid = gu.group_uuid
where
gr.role = #{permission, jdbcType=VARCHAR} and
- gr.component_uuid is null and
+ gr.entity_uuid is null and
gr.group_uuid is not null
union
select ur.user_uuid
from user_roles ur
where
- ur.component_uuid is null and
+ ur.entity_uuid is null and
ur.role = #{permission, jdbcType=VARCHAR} and
ur.user_uuid != #{userUuid, jdbcType=VARCHAR}
) remaining
<select id="keepAuthorizedEntityUuidsForUser" parameterType="map" resultType="String">
select
- gr.component_uuid
+ gr.entity_uuid
from
group_roles gr
where
)
)
and <foreach collection="entityUuids" open="(" close=")" item="element" index="index" separator=" or ">
- gr.component_uuid=#{element, jdbcType=VARCHAR}
+ gr.entity_uuid=#{element, jdbcType=VARCHAR}
</foreach>
union
from
user_roles ur
inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on
- entity.uuid = ur.component_uuid
+ entity.uuid = ur.entity_uuid
where
ur.role=#{role, jdbcType=VARCHAR}
and ur.user_uuid=#{userUuid, jdbcType=INTEGER}
<select id="keepAuthorizedEntityUuidsForAnonymous" parameterType="map" resultType="String">
select
- gr.component_uuid
+ gr.entity_uuid
from
group_roles gr
where
gr.role=#{role, jdbcType=VARCHAR}
and gr.group_uuid is null
and <foreach collection="entityUuids" open="(" close=")" item="element" index="index" separator=" or ">
- gr.component_uuid=#{element, jdbcType=VARCHAR}
+ gr.entity_uuid=#{element, jdbcType=VARCHAR}
</foreach>
union
inner join group_roles gr on
gr.group_uuid=gu.group_uuid
where
- gr.component_uuid=#{entityUuid, jdbcType=VARCHAR}
+ gr.entity_uuid=#{entityUuid, jdbcType=VARCHAR}
and gr.role=#{role, jdbcType=VARCHAR}
and gu.user_uuid in
<foreach collection="userUuids" open="(" close=")" item="uuid" separator=",">
from
user_roles ur
where
- ur.component_uuid=#{entityUuid, jdbcType=VARCHAR}
+ ur.entity_uuid=#{entityUuid, jdbcType=VARCHAR}
and ur.role=#{role, jdbcType=VARCHAR}
and ur.user_uuid IN
<foreach collection="userUuids" open="(" close=")" item="uuid" separator=",">
<select id="selectEntityPermissions" parameterType="map" resultType="String">
select ur.role
from user_roles ur
- inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.component_uuid
+ inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.entity_uuid
where
entity.uuid = #{entityUuid, jdbcType=VARCHAR} and
ur.user_uuid = #{userUuid, jdbcType=VARCHAR}
select gr.role
from group_roles gr
inner join groups_users gu on gr.group_uuid = gu.group_uuid
- inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = gr.component_uuid
+ inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = gr.entity_uuid
where
entity.uuid = #{entityUuid, jdbcType=VARCHAR} and
gu.user_uuid = #{userUuid, jdbcType=VARCHAR}
from
group_roles gr
inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on
- entity.uuid = gr.component_uuid
+ entity.uuid = gr.entity_uuid
where
entity.uuid = #{entityUuid, jdbcType=VARCHAR}
and gr.group_uuid is null
inner join user_roles ur on
ur.user_uuid = u.uuid
and ur.role=#{permission, jdbcType=VARCHAR}
- and ur.component_uuid is null
+ and ur.entity_uuid is null
where
u.email is not null
inner join group_roles gr on
gr.group_uuid = gu.group_uuid
and gr.role = #{permission, jdbcType=VARCHAR}
- and gr.component_uuid is null
+ and gr.entity_uuid is null
where
u.email is not null
exists (
select 1
from user_roles ur
- inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.component_uuid
+ inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on entity.uuid = ur.entity_uuid
where
entity.kee = #{entityKey, jdbcType=VARCHAR}
and ur.role = #{permission, jdbcType=VARCHAR}
) or exists (
select 1
from (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity
- inner join group_roles gr on gr.component_uuid = entity.uuid
+ inner join group_roles gr on gr.entity_uuid = entity.uuid
inner join groups_users gu on gu.group_uuid = gr.group_uuid
where
entity.kee = #{entityKey, jdbcType=VARCHAR}
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
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
<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>
<!-- 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 <= #{max}
<!-- SQL Server -->
<select id="selectProjectKeysWithAnyonePermissions" parameterType="int" resultType="string" databaseId="mssql">
select distinct top(#{max}) p.kee as kee from group_roles gr
- left join projects p on gr.component_uuid = p.uuid
- where gr.group_uuid is null and gr.component_uuid is not null
+ left join projects p on gr.entity_uuid = p.uuid
+ where gr.group_uuid is null and gr.entity_uuid is not null
ORDER BY kee ASC
</select>
<select id="countEntitiesWithAnyonePermissions" resultType="int">
- select count(distinct(gr.component_uuid))
- from group_roles gr where gr.group_uuid is null and gr.component_uuid is not null
+ select count(distinct(gr.entity_uuid))
+ from group_roles gr where gr.group_uuid is null and gr.entity_uuid is not null
</select>
<select id="selectGroupNamesByQuery" parameterType="map" resultType="string">
<sql id="groupsByQuery">
from (
- select g.uuid as groupUuid, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
+ select g.uuid as groupUuid, g.name as name, gr.role as permission, gr.entity_uuid as entityUuid, gr.uuid as uuid
from groups g
left join group_roles gr on g.uuid = gr.group_uuid
<if test="query.entityUuid == null">
- and gr.component_uuid is null
+ and gr.entity_uuid is null
</if>
<if test="query.entityUuid != null">
- and gr.component_uuid = #{query.entityUuid,jdbcType=VARCHAR}
+ and gr.entity_uuid = #{query.entityUuid,jdbcType=VARCHAR}
</if>
union all
- select 'Anyone' as groupUuid, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
+ select 'Anyone' as groupUuid, 'Anyone' as name, gr.role as permission, gr.entity_uuid as entityUuid, gr.uuid as uuid
from group_roles gr
<where>
<if test="query.entityUuid == null">
- and gr.component_uuid is null
+ and gr.entity_uuid is null
</if>
<if test="query.entityUuid != null">
- and gr.component_uuid = #{query.entityUuid,jdbcType=VARCHAR}
+ and gr.entity_uuid = #{query.entityUuid,jdbcType=VARCHAR}
</if>
<if test="query.withAtLeastOnePermission()">
and gr.group_uuid is null
</where>
) sub
- left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on sub.componentUuid = entity.uuid
+ left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on sub.entityUuid = entity.uuid
<where>
<if test="query.searchQueryToSql != null">
and lower(sub.name) like #{query.searchQueryToSqlLowercase,jdbcType=VARCHAR} ESCAPE '/'
<if test="query.withAtLeastOnePermission()">
and sub.permission is not null
<if test="query.entityUuid==null">
- and sub.componentUuid is null
+ and sub.entityUuid is null
</if>
<if test="query.entityUuid!=null">
and entity.uuid = #{query.entityUuid,jdbcType=VARCHAR}
</sql>
<select id="selectByGroupUuids" parameterType="map" resultType="GroupPermission">
- select sub.groupUuid as groupUuid, sub.componentUuid as componentUuid, sub.permission as role
+ select sub.groupUuid as groupUuid, sub.entityUuid as entityUuid, sub.permission as role
from
(
- select gr.group_uuid as groupUuid, gr.component_uuid as componentUuid, gr.role as permission, g.name as name
+ select gr.group_uuid as groupUuid, gr.entity_uuid as entityUuid, gr.role as permission, g.name as name
from group_roles gr
inner join groups g ON g.uuid = gr.group_uuid
where gr.group_uuid is not null
union all
- select 'Anyone' as groupUuid, gr.component_uuid as componentUuid, gr.role as permission, 'Anyone' as name
+ select 'Anyone' as groupUuid, gr.entity_uuid as entityUuid, gr.role as permission, 'Anyone' as name
from group_roles gr
where
gr.group_uuid is null
#{groupUuid,jdbcType=VARCHAR}
</foreach>
<if test="entityUuid != null">
- and sub.componentUuid=#{entityUuid,jdbcType=VARCHAR}
+ and sub.entityUuid = #{entityUuid,jdbcType=VARCHAR}
</if>
<if test="entityUuid==null">
- and sub.componentUuid is null
+ and sub.entityUuid is null
</if>
</select>
select gr.role
from group_roles gr
where
- gr.component_uuid is null and
+ gr.entity_uuid is null and
<choose>
<when test="groupUuid != null">
gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
select gr.role
from group_roles gr
where
- gr.component_uuid = #{entityUuid,jdbcType=VARCHAR} and
+ gr.entity_uuid = #{entityUuid,jdbcType=VARCHAR} and
<choose>
<when test="groupUuid != null">
gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
</select>
<select id="selectAllPermissionsByGroupUuid" parameterType="map" resultType="GroupPermission">
- select gr.group_uuid as groupUuid, gr.component_uuid as componentUuid, gr.role as role
+ select gr.group_uuid as groupUuid, gr.entity_uuid as entityUuid, gr.role as role
from group_roles gr
where gr.group_uuid = #{groupUuid,jdbcType=VARCHAR}
</select>
from
group_roles gr1
where
- gr1.component_uuid = #{entityUuid,jdbcType=VARCHAR}
+ gr1.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
and gr1.group_uuid is not null
and not exists (
select
from
group_roles gr2
where
- gr2.component_uuid = gr1.component_uuid
+ gr2.entity_uuid = gr1.entity_uuid
and gr2.group_uuid = gr1.group_uuid
and gr2.role = #{role,jdbcType=VARCHAR}
)
insert into group_roles (
uuid,
group_uuid,
- component_uuid,
+ entity_uuid,
role
) values (
#{uuid,jdbcType=VARCHAR},
#{groupUuid,jdbcType=VARCHAR},
- #{componentUuid,jdbcType=BIGINT},
+ #{entityUuid,jdbcType=BIGINT},<!--Why big int?-->
#{role,jdbcType=VARCHAR}
)
</insert>
<delete id="deleteByEntityUuid" parameterType="String">
delete from group_roles
- where component_uuid=#{entityUuid,jdbcType=VARCHAR}
+ where entity_uuid=#{entityUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteByEntityUuidAndGroupUuid">
delete from
group_roles
where
- component_uuid=#{entityUuid,jdbcType=VARCHAR}
+ entity_uuid=#{entityUuid,jdbcType=VARCHAR}
<choose>
<when test="groupUuid != null">
and group_uuid = #{groupUuid,jdbcType=VARCHAR}
delete from
group_roles
where
- component_uuid=#{entityUuid,jdbcType=VARCHAR}
+ entity_uuid=#{entityUuid,jdbcType=VARCHAR}
and role=#{permission,jdbcType=VARCHAR}
</delete>
role=#{permission,jdbcType=VARCHAR} and
<choose>
<when test="entityUuid != null">
- component_uuid=#{entityUuid,jdbcType=BIGINT}
+ entity_uuid=#{entityUuid,jdbcType=BIGINT}
</when>
<otherwise>
- component_uuid is null
+ entity_uuid is null
</otherwise>
</choose>
and
<select id="selectUserPermissionsByQueryAndUserUuids" parameterType="map" resultType="org.sonar.db.permission.UserPermissionDto">
select
u.uuid as userUuid,
- ur.component_uuid as componentUuid,
+ ur.entity_uuid as entityUuid,
ur.role as permission
<include refid="sqlQueryJoins"/>
<where>
left join user_roles ur on ur.user_uuid = u.uuid
<choose>
<when test="query.entityUuid == null">
- and ur.component_uuid is null
+ and ur.entity_uuid is null
</when>
<otherwise>
- and ur.component_uuid = #{query.entityUuid,jdbcType=VARCHAR}
+ and ur.entity_uuid = #{query.entityUuid,jdbcType=VARCHAR}
</otherwise>
</choose>
- left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.component_uuid = entity.uuid
+ left join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.entity_uuid = entity.uuid
<where>
<include refid="sqlQueryFilters"/>
</where>
<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">
<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}
from user_roles ur
where
ur.user_uuid = #{userUuid,jdbcType=VARCHAR} and
- ur.component_uuid is null
+ ur.entity_uuid is null
</select>
<select id="selectEntityPermissionsOfUser" parameterType="map" resultType="string">
from user_roles ur
where
ur.user_uuid = #{userUuid,jdbcType=VARCHAR} and
- ur.component_uuid = #{entityUuid,jdbcType=VARCHAR}
+ ur.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
</select>
<select id="countUsersByEntityPermission" resultType="org.sonar.db.permission.CountPerEntityPermission">
- select ur.component_uuid as entityUuid, ur.role as permission, count(u.login) as count
+ select ur.entity_uuid as entityUuid, ur.role as permission, count(u.login) as count
from users u
inner join user_roles ur on ur.user_uuid = u.uuid
- inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.component_uuid = entity.uuid
+ inner join (<include refid="org.sonar.db.entity.EntityMapper.selectAll"/>) entity on ur.entity_uuid = entity.uuid
where u.active = ${_true}
and entity.uuid in <foreach collection="entityUuids" open="(" close=")" item="entityUuid" separator=",">#{entityUuid}</foreach>
- group by ur.component_uuid, ur.role
+ group by ur.entity_uuid, ur.role
</select>
<select id="selectUserIdsWithPermissionOnEntityBut" resultType="org.sonar.db.user.UserIdDto">
from
user_roles ur1 inner join users u on ur1.user_uuid = u.uuid
where
- ur1.component_uuid = #{entityUuid,jdbcType=VARCHAR}
+ ur1.entity_uuid = #{entityUuid,jdbcType=VARCHAR}
and role <> #{permission,jdbcType=VARCHAR}
and not exists (
select
from
user_roles ur2
where
- ur2.component_uuid = ur1.component_uuid
+ ur2.entity_uuid = ur1.entity_uuid
and ur2.user_uuid = ur1.user_uuid
and role = #{permission,jdbcType=VARCHAR}
)
insert into user_roles (
uuid,
user_uuid,
- component_uuid,
+ entity_uuid,
role
) values (
#{dto.uuid,jdbcType=VARCHAR},
#{dto.userUuid,jdbcType=VARCHAR},
- #{dto.componentUuid,jdbcType=VARCHAR},
+ #{dto.entityUuid,jdbcType=VARCHAR},
#{dto.permission,jdbcType=VARCHAR}
)
</insert>
where
role = #{permission,jdbcType=VARCHAR} and
user_uuid = #{userUuid,jdbcType=VARCHAR} and
- component_uuid is null
+ entity_uuid is null
</delete>
<delete id="deleteEntityPermission" parameterType="map">
where
role = #{permission,jdbcType=VARCHAR} and
user_uuid = #{userUuid,jdbcType=VARCHAR} and
- component_uuid = #{entityUuid,jdbcType=VARCHAR}
+ entity_uuid = #{entityUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteEntityPermissions" parameterType="map">
delete from user_roles
where
- component_uuid = #{entityUuid,jdbcType=VARCHAR}
+ entity_uuid = #{entityUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteEntityPermissionOfAnyUser" parameterType="map">
delete from
user_roles
where
- component_uuid = #{entityUuid,jdbcType=VARCHAR}
+ entity_uuid = #{entityUuid,jdbcType=VARCHAR}
and role = #{permission,jdbcType=VARCHAR}
</delete>
</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">
<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">
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,
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"(
--- /dev/null
+/*
+ * 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"));
+ }
+}
.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();
.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;
.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();
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()
.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;
}
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
DbVersion00.class,
DbVersion100.class,
DbVersion101.class,
+ DbVersion102.class,
// migration steps
MigrationStepRegistryImpl.class,
--- /dev/null
+/*
+ * 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());
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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;
--- /dev/null
+/*
+ * 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);
+ }
+
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+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);
--- /dev/null
+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);
.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();
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}
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();
.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();
}
.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();
}
.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();
}
.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();
}
.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))
.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);
});
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))))
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) {