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);
}
void deleteByQProfiles(@Param("qProfileUuids") Collection<String> qProfileUuids);
void deleteByUser(@Param("userId") int userId);
+
+ void deleteByOrganizationAndUser(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId);
}
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>
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();
+ }
}
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));
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;
.containsOnly(user.getId());
}
+ @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();