From b7a5beda61e4d041c73b9eba1395e6e4370578e9 Mon Sep 17 00:00:00 2001 From: Lukasz Jarocki Date: Mon, 12 Jun 2023 15:09:46 +0200 Subject: [PATCH] SONAR-19445 Fix new mapper query from master --- .../sonar/db/permission/GroupPermissionDaoIT.java | 14 +++++++------- .../sonar/db/permission/GroupPermissionDao.java | 6 +++--- .../sonar/db/permission/GroupPermissionMapper.java | 2 +- .../sonar/db/permission/GroupPermissionMapper.xml | 4 ++-- .../server/permission/ws/RemoveGroupActionIT.java | 12 ++++++------ .../server/permission/ws/PermissionWsSupport.java | 14 +++++++------- 6 files changed, 26 insertions(+), 26 deletions(-) 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 f8baeec0a39..4e09747640e 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 @@ -972,18 +972,18 @@ public class GroupPermissionDaoIT { } @Test - public void selectGroupUuidsWithPermissionOnProject_shouldReturnOnlyGroupsWithSpecifiedPermission() { + public void selectGroupUuidsWithPermissionOnEntity_shouldReturnOnlyGroupsWithSpecifiedPermission() { GroupDto group1 = db.users().insertGroup(); GroupDto group2 = db.users().insertGroup(); GroupDto group3 = db.users().insertGroup(); - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); - ComponentDto otherProject = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); + ProjectDto otherProject = db.components().insertPrivateProject().getProjectDto(); String anyPermission = "any_permission"; - db.users().insertProjectPermissionOnGroup(group1, anyPermission, project); - db.users().insertProjectPermissionOnGroup(group2, "otherPermission", project); - db.users().insertProjectPermissionOnGroup(group3, anyPermission, otherProject); + db.users().insertEntityPermissionOnGroup(group1, anyPermission, project); + db.users().insertEntityPermissionOnGroup(group2, "otherPermission", project); + db.users().insertEntityPermissionOnGroup(group3, anyPermission, otherProject); - Set results = underTest.selectGroupUuidsWithPermissionOnProject(dbSession, project.uuid(), anyPermission); + Set results = underTest.selectGroupUuidsWithPermissionOnEntity(dbSession, project.getUuid(), anyPermission); assertThat(results).containsOnly(group1.getUuid()); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index f759a5f0ca4..f9fd9265632 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -130,10 +130,10 @@ public class GroupPermissionDao implements Dao { } /** - * Lists group uuids that have the selected permission on the specified project. + * Lists group uuids that have the selected permission on the specified entity. */ - public Set selectGroupUuidsWithPermissionOnProject(DbSession session, String projectUuid, String permission) { - return mapper(session).selectGroupUuidsWithPermissionOnProject(projectUuid, permission); + public Set selectGroupUuidsWithPermissionOnEntity(DbSession session, String entityUuid, String permission) { + return mapper(session).selectGroupUuidsWithPermissionOnEntity(entityUuid, permission); } public void insert(DbSession dbSession, GroupPermissionDto groupPermissionDto, @Nullable EntityDto entityDto, @Nullable PermissionTemplateDto permissionTemplateDto) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java index a21ce003a7a..9305b3a7ecd 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java @@ -58,7 +58,7 @@ public interface GroupPermissionMapper { */ Set selectGroupUuidsWithPermissionOnEntityBut(@Param("entityUuid") String entityUuid, @Param("role") String permission); - Set selectGroupUuidsWithPermissionOnProject(@Param("projectUuid") String projectUuid, @Param("role") String permission); + Set selectGroupUuidsWithPermissionOnEntity(@Param("entityUuid") String entityUuid, @Param("role") String permission); int deleteByEntityUuid(@Param("entityUuid") String entityUuid); 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 d8b05631817..f6cef3a74a7 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 @@ -219,13 +219,13 @@ ) - select distinct gr1.group_uuid from group_roles gr1 where - gr1.component_uuid = #{projectUuid,jdbcType=VARCHAR} + gr1.entity_uuid = #{entityUuid,jdbcType=VARCHAR} and gr1.group_uuid is not null and gr1.role = #{role,jdbcType=VARCHAR} 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 72a47beef4d..5475fb725f1 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 @@ -430,18 +430,18 @@ public class RemoveGroupActionIT extends BasePermissionWsIT { @Test public void wsAction_whenRemovingOwnBrowsePermissionAndHavePermissionFromOtherGroup_shouldRemovePermission() { - ComponentDto project = db.components().insertPrivateProject().getMainBranchComponent(); + ProjectDto project = db.components().insertPrivateProject().getProjectDto(); UserDto user = db.users().insertUser(); GroupDto projectAdminGroup = db.users().insertGroup(); GroupDto otherProjectAdminGroup = db.users().insertGroup(); - db.users().insertProjectPermissionOnGroup(projectAdminGroup, UserRole.USER, project); - db.users().insertProjectPermissionOnGroup(projectAdminGroup, UserRole.ADMIN, project); - db.users().insertProjectPermissionOnGroup(otherProjectAdminGroup, UserRole.USER, project); - db.users().insertProjectPermissionOnGroup(otherProjectAdminGroup, UserRole.ADMIN, project); + db.users().insertEntityPermissionOnGroup(projectAdminGroup, UserRole.USER, project); + db.users().insertEntityPermissionOnGroup(projectAdminGroup, UserRole.ADMIN, project); + db.users().insertEntityPermissionOnGroup(otherProjectAdminGroup, UserRole.USER, project); + db.users().insertEntityPermissionOnGroup(otherProjectAdminGroup, UserRole.ADMIN, project); userSession.logIn(user).setGroups(projectAdminGroup, otherProjectAdminGroup).addProjectPermission(UserRole.USER, project).addProjectPermission(UserRole.ADMIN, project); newRequest() - .setParam(PARAM_PROJECT_ID, project.uuid()) + .setParam(PARAM_PROJECT_ID, project.getUuid()) .setParam(PARAM_GROUP_NAME, projectAdminGroup.getName()) .setParam(PARAM_PERMISSION, UserRole.USER) .execute(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java index ccdc882894b..ff3ef6ce765 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java @@ -130,14 +130,14 @@ public class PermissionWsSupport { return user.getLogin().equals(userSession.getLogin()); } - public void checkRemovingOwnBrowsePermissionOnPrivateProject(DbSession dbSession, UserSession userSession, @Nullable ComponentDto project, String permission, + public void checkRemovingOwnBrowsePermissionOnPrivateProject(DbSession dbSession, UserSession userSession, @Nullable EntityDto entityDto, String permission, GroupUuidOrAnyone group) { - if (userSession.isSystemAdministrator() || group.isAnyone() || !isUpdatingBrowsePermissionOnPrivateProject(permission, project)) { + if (userSession.isSystemAdministrator() || group.isAnyone() || !isUpdatingBrowsePermissionOnPrivateProject(permission, entityDto)) { return; } - Set groupUuidsWithPermission = dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProject(dbSession, project.uuid(), UserRole.USER); + Set groupUuidsWithPermission = dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnEntity(dbSession, entityDto.getUuid(), UserRole.USER); boolean isUserInAnotherGroupWithPermissionForThisProject = userSession.getGroups().stream() .map(GroupDto::getUuid) .anyMatch(groupDtoUuid -> groupUuidsWithPermission.contains(groupDtoUuid) && !groupDtoUuid.equals(group.getUuid())); @@ -147,14 +147,14 @@ public class PermissionWsSupport { } } - public void checkRemovingOwnBrowsePermissionOnPrivateProject(UserSession userSession, @Nullable ComponentDto project, String permission, UserId user) { - if (isUpdatingBrowsePermissionOnPrivateProject(permission, project) && user.getLogin().equals(userSession.getLogin())) { + public void checkRemovingOwnBrowsePermissionOnPrivateProject(UserSession userSession, @Nullable EntityDto entityDto, String permission, UserId user) { + if (isUpdatingBrowsePermissionOnPrivateProject(permission, entityDto) && user.getLogin().equals(userSession.getLogin())) { throw BadRequestException.create(ERROR_REMOVING_OWN_BROWSE_PERMISSION); } } - public static boolean isUpdatingBrowsePermissionOnPrivateProject(String permission, @Nullable ComponentDto project) { - return project != null && project.isPrivate() && permission.equals(UserRole.USER) ; + public static boolean isUpdatingBrowsePermissionOnPrivateProject(String permission, @Nullable EntityDto entityDto) { + return entityDto != null && entityDto.isPrivate() && permission.equals(UserRole.USER) ; } } -- 2.39.5