diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-09-27 18:24:40 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-02 17:18:15 +0200 |
commit | b21a14010c4941746cffb5de4296ec99a4ebf981 (patch) | |
tree | acc9a82a24c01d0a70b2572f232af0a38e7b75d5 /server | |
parent | f0af72abc18ccbe6eb0227d38dc898f052e04eda (diff) | |
download | sonarqube-b21a14010c4941746cffb5de4296ec99a4ebf981.tar.gz sonarqube-b21a14010c4941746cffb5de4296ec99a4ebf981.zip |
SONAR-1330 Purge edit permissions when removing organization member
Diffstat (limited to 'server')
6 files changed, 53 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersDao.java index c41940af852..6a8350fb094 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersDao.java @@ -70,6 +70,10 @@ public class QProfileEditUsersDao implements Dao { mapper(dbSession).deleteByUser(user.getId()); } + public void deleteByOrganizationAndUser(DbSession dbSession, OrganizationDto organization, UserDto user) { + mapper(dbSession).deleteByOrganizationAndUser(organization.getUuid(), user.getId()); + } + private static QProfileEditUsersMapper mapper(DbSession dbSession) { return dbSession.getMapper(QProfileEditUsersMapper.class); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersMapper.java index 399a0e58f4d..25b2b18907e 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualityprofile/QProfileEditUsersMapper.java @@ -41,4 +41,6 @@ public interface QProfileEditUsersMapper { void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids); void deleteByUser(@Param("userId") int userId); + + void deleteByOrganizationAndUser(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId); } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml index 2365902336a..0256e05d9a2 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualityprofile/QProfileEditUsersMapper.xml @@ -115,5 +115,17 @@ where user_id = #{userId, jdbcType=INTEGER} </delete> + <delete id="deleteByOrganizationAndUser" parameterType="map"> + delete from qprofile_edit_users + <where> + user_id=#{userId, jdbcType=INTEGER} + and qprofile_uuid in ( + select oq.uuid + from org_qprofiles oq + where oq.organization_uuid=#{organizationUuid, jdbcType=VARCHAR} + ) + </where> + </delete> + </mapper> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java index 35c8ee81f3d..67f9f1ca1d0 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QProfileEditUsersDaoTest.java @@ -329,4 +329,22 @@ public class QProfileEditUsersDaoTest { assertThat(underTest.exists(db.getSession(), profile2, user1)).isFalse(); assertThat(underTest.exists(db.getSession(), profile3, user2)).isTrue(); } + + @Test + public void deleteByOrganizationAndUser() { + OrganizationDto organization1 = db.organizations().insert(); + OrganizationDto organization2 = db.organizations().insert(); + QProfileDto profile1 = db.qualityProfiles().insert(organization1); + QProfileDto profile2 = db.qualityProfiles().insert(organization2); + UserDto user = db.users().insertUser(); + db.organizations().addMember(organization1, user); + db.organizations().addMember(organization2, user); + db.qualityProfiles().addUserPermission(profile1, user); + db.qualityProfiles().addUserPermission(profile2, user); + + underTest.deleteByOrganizationAndUser(db.getSession(), organization1, user); + + assertThat(underTest.exists(db.getSession(), profile1, user)).isFalse(); + assertThat(underTest.exists(db.getSession(), profile2, user)).isTrue(); + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java index a927bdfcbd5..688e2dbdba9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/organization/ws/RemoveMemberAction.java @@ -98,6 +98,7 @@ public class RemoveMemberAction implements OrganizationsWsAction { String organizationUuid = organization.getUuid(); dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userId); dbClient.permissionTemplateDao().deleteUserPermissionsByOrganization(dbSession, organizationUuid, userId); + dbClient.qProfileEditUsersDao().deleteByOrganizationAndUser(dbSession, organization, user); dbClient.userGroupDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); dbClient.propertiesDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId); dbClient.propertiesDao().deleteByOrganizationAndMatchingLogin(dbSession, organizationUuid, user.getLogin(), singletonList(DEFAULT_ISSUE_ASSIGNEE)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java index fe6a84f5132..a6bfbb75049 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/RemoveMemberActionTest.java @@ -38,6 +38,7 @@ import org.sonar.db.permission.template.PermissionTemplateDto; import org.sonar.db.permission.template.PermissionTemplateUserDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; +import org.sonar.db.qualityprofile.QProfileDto; import org.sonar.db.user.GroupDto; import org.sonar.db.user.UserDto; import org.sonar.server.es.EsTester; @@ -186,6 +187,21 @@ public class RemoveMemberActionTest { } @Test + public void remove_qprofiles_user_permission() { + OrganizationDto anotherOrganization = db.organizations().insert(); + db.organizations().addMember(anotherOrganization, user); + QProfileDto profile = db.qualityProfiles().insert(organization); + QProfileDto anotherProfile = db.qualityProfiles().insert(anotherOrganization); + db.qualityProfiles().addUserPermission(profile, user); + db.qualityProfiles().addUserPermission(anotherProfile, user); + + call(organization.getKey(), user.getLogin()); + + assertThat(db.getDbClient().qProfileEditUsersDao().exists(dbSession, profile, user)).isFalse(); + assertThat(db.getDbClient().qProfileEditUsersDao().exists(dbSession, anotherProfile, user)).isTrue(); + } + + @Test public void remove_from_organization_groups() { OrganizationDto anotherOrganization = db.organizations().insert(); UserDto anotherUser = db.users().insertUser(); |