]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19445 Fix new mapper query from master
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Mon, 12 Jun 2023 13:09:46 +0000 (15:09 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 19 Jun 2023 20:03:14 +0000 (20:03 +0000)
server/sonar-db-dao/src/it/java/org/sonar/db/permission/GroupPermissionDaoIT.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
server/sonar-webserver-webapi/src/it/java/org/sonar/server/permission/ws/RemoveGroupActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/PermissionWsSupport.java

index f8baeec0a393ebd3813746866d0bc071997c89e3..4e09747640e60c7d189daadc985ba79674bd97bb 100644 (file)
@@ -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<String> results = underTest.selectGroupUuidsWithPermissionOnProject(dbSession, project.uuid(), anyPermission);
+    Set<String> results = underTest.selectGroupUuidsWithPermissionOnEntity(dbSession, project.getUuid(), anyPermission);
 
     assertThat(results).containsOnly(group1.getUuid());
   }
index f759a5f0ca4207dad3bdf0a21b1440b44b4e6c2b..f9fd9265632a1c6b89bb079db5055e04678cf273 100644 (file)
@@ -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<String> selectGroupUuidsWithPermissionOnProject(DbSession session, String projectUuid, String permission) {
-    return mapper(session).selectGroupUuidsWithPermissionOnProject(projectUuid, permission);
+  public Set<String> 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) {
index a21ce003a7a7d3afa46a2d53a1056fb7fa119bf7..9305b3a7ecd4c89f2b62bf660b2607dd86c8c4ee 100644 (file)
@@ -58,7 +58,7 @@ public interface GroupPermissionMapper {
    */
   Set<String> selectGroupUuidsWithPermissionOnEntityBut(@Param("entityUuid") String entityUuid, @Param("role") String permission);
 
-  Set<String> selectGroupUuidsWithPermissionOnProject(@Param("projectUuid") String projectUuid, @Param("role") String permission);
+  Set<String> selectGroupUuidsWithPermissionOnEntity(@Param("entityUuid") String entityUuid, @Param("role") String permission);
 
   int deleteByEntityUuid(@Param("entityUuid") String entityUuid);
 
index d8b056318178cb4d8bc96cfb9bc816573dc01672..f6cef3a74a746c9aae5bbcdfde942ba03e4001b8 100644 (file)
       )
   </select>
 
-   <select id="selectGroupUuidsWithPermissionOnProject" resultType="string">
+   <select id="selectGroupUuidsWithPermissionOnEntity" resultType="string">
     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}
   </select>
index 72a47beef4d441b677b531c17ba848f5a7a1d2a6..5475fb725f1a0871062a9a252fd12622fe0a95d0 100644 (file)
@@ -430,18 +430,18 @@ public class RemoveGroupActionIT extends BasePermissionWsIT<RemoveGroupAction> {
 
   @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();
index ccdc882894b722b0fac3e766928b3d3f2f2b73c2..ff3ef6ce765acc41316aecc3c54a2c43fc8e52ea 100644 (file)
@@ -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<String> groupUuidsWithPermission = dbClient.groupPermissionDao().selectGroupUuidsWithPermissionOnProject(dbSession, project.uuid(), UserRole.USER);
+    Set<String> 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) ;
   }
 
 }