executeLargeUpdates(qProfiles.stream().map(QProfileDto::getKee).collect(toList()), p -> mapper(dbSession).deleteByQProfiles(p));
}
+ public void deleteByUser(DbSession dbSession, UserDto user) {
+ mapper(dbSession).deleteByUser(user.getId());
+ }
+
private static QProfileEditUsersMapper mapper(DbSession dbSession) {
return dbSession.getMapper(QProfileEditUsersMapper.class);
}
void delete(@Param("qProfileUuid") String qProfileUuid, @Param("userId") int userId);
void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
+
+ void deleteByUser(@Param("userId") int userId);
}
where qprofile_uuid in <foreach collection="qProfileUuids" open="(" close=")" item="qProfileUuid" separator=",">#{qProfileUuid, jdbcType=VARCHAR}</foreach>
</delete>
+ <delete id="deleteByUser" parameterType="map">
+ delete from qprofile_edit_users
+ where user_id = #{userId, jdbcType=INTEGER}
+ </delete>
+
</mapper>
assertThat(underTest.exists(db.getSession(), profile3, user1)).isTrue();
assertThat(underTest.exists(db.getSession(), anotherProfile, user1)).isTrue();
}
+
+ @Test
+ public void deleteByUser() {
+ OrganizationDto organization1 = db.organizations().insert();
+ OrganizationDto organization2 = db.organizations().insert();
+ QProfileDto profile1 = db.qualityProfiles().insert(organization1);
+ QProfileDto profile2 = db.qualityProfiles().insert(organization2);
+ QProfileDto profile3 = db.qualityProfiles().insert(organization1);
+ UserDto user1 = db.users().insertUser();
+ UserDto user2 = db.users().insertUser();
+ db.qualityProfiles().addUserPermission(profile1, user1);
+ db.qualityProfiles().addUserPermission(profile2, user1);
+ db.qualityProfiles().addUserPermission(profile3, user2);
+
+ underTest.deleteByUser(db.getSession(), user1);
+
+ assertThat(underTest.exists(db.getSession(), profile1, user1)).isFalse();
+ assertThat(underTest.exists(db.getSession(), profile2, user1)).isFalse();
+ assertThat(underTest.exists(db.getSession(), profile3, user2)).isTrue();
+ }
}
dbClient.userGroupDao().deleteByUserId(dbSession, userId);
dbClient.userPermissionDao().deleteByUserId(dbSession, userId);
dbClient.permissionTemplateDao().deleteUserPermissionsByUserId(dbSession, userId);
+ dbClient.qProfileEditUsersDao().deleteByUser(dbSession, user);
dbClient.organizationMemberDao().deleteByUserId(dbSession, userId);
dbClient.userDao().deactivateUser(dbSession, user);
userIndexer.commitAndIndex(dbSession, user);
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;
assertThat(db.getDbClient().permissionTemplateDao().selectUserPermissionsByTemplateId(dbSession, anotherTemplate.getId())).extracting(PermissionTemplateUserDto::getUserId).isEmpty();
}
+ @Test
+ public void deactivate_user_deletes_his_qprofiles_permissions() {
+ logInAsSystemAdministrator();
+ UserDto user = insertUser(newUserDto());
+ QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization());
+ db.qualityProfiles().addUserPermission(profile, user);
+
+ deactivate(user.getLogin()).getInput();
+
+ assertThat(db.getDbClient().qProfileEditUsersDao().exists(dbSession, profile, user)).isFalse();
+ }
+
@Test
public void deactivate_user_deletes_his_default_assignee_settings() {
logInAsSystemAdministrator();