use of org.sonar.db.user.UserDismissedMessageDto in project sonarqube by SonarSource.
the class PurgeDaoTest method delete_rows_in_user_dismissed_messages_when_deleting_project.
@Test
public void delete_rows_in_user_dismissed_messages_when_deleting_project() {
UserDto user1 = db.users().insertUser();
UserDto user2 = db.users().insertUser();
ProjectDto project = db.components().insertPrivateProjectDto();
ProjectDto anotherProject = db.components().insertPrivateProjectDto();
UserDismissedMessageDto msg1 = db.users().insertUserDismissedMessage(user1, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
UserDismissedMessageDto msg2 = db.users().insertUserDismissedMessage(user2, project, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
UserDismissedMessageDto msg3 = db.users().insertUserDismissedMessage(user1, anotherProject, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
assertThat(uuidsIn("user_dismissed_messages")).containsOnly(msg1.getUuid(), msg2.getUuid(), msg3.getUuid());
underTest.deleteProject(dbSession, project.getUuid(), project.getQualifier(), project.getName(), project.getKey());
dbSession.commit();
assertThat(uuidsIn("user_dismissed_messages")).containsOnly(msg3.getUuid());
}
use of org.sonar.db.user.UserDismissedMessageDto in project sonarqube by SonarSource.
the class DeactivateActionTest method deactivate_user_deletes_their_dismissed_messages.
@Test
public void deactivate_user_deletes_their_dismissed_messages() {
createAdminUser();
logInAsSystemAdministrator();
ProjectDto project1 = db.components().insertPrivateProjectDto();
ProjectDto project2 = db.components().insertPrivateProjectDto();
UserDto user = db.users().insertUser();
db.users().insertUserDismissedMessage(user, project1, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
db.users().insertUserDismissedMessage(user, project2, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
UserDto anotherUser = db.users().insertUser();
UserDismissedMessageDto msg3 = db.users().insertUserDismissedMessage(anotherUser, project1, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
UserDismissedMessageDto msg4 = db.users().insertUserDismissedMessage(anotherUser, project2, CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
deactivate(user.getLogin());
assertThat(db.getDbClient().userDismissedMessagesDao().selectByUser(dbSession, user)).isEmpty();
assertThat(db.getDbClient().userDismissedMessagesDao().selectByUser(dbSession, anotherUser)).extracting(UserDismissedMessageDto::getUuid).containsExactlyInAnyOrder(msg3.getUuid(), msg4.getUuid());
}
use of org.sonar.db.user.UserDismissedMessageDto in project sonarqube by SonarSource.
the class DismissAnalysisWarningAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String userLogin = requireNonNull(userSession.getLogin());
String projectKey = request.mandatoryParam(PARAM_COMPONENT_KEY);
String messageKey = request.mandatoryParam(PARAM_MESSAGE_KEY);
try (DbSession dbSession = dbClient.openSession(false)) {
UserDto user = getUser(dbSession, userLogin);
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
userSession.checkProjectPermission(UserRole.USER, project);
CeTaskMessageDto messageDto = dbClient.ceTaskMessageDao().selectByUuid(dbSession, messageKey).orElseThrow(() -> new NotFoundException(format(MESSAGE_NOT_FOUND, messageKey)));
if (!messageDto.getType().isDismissible()) {
throw new IllegalArgumentException(format(MESSAGE_CANNOT_BE_DISMISSED, messageKey));
}
Optional<UserDismissedMessageDto> result = dbClient.userDismissedMessagesDao().selectByUserAndProjectAndMessageType(dbSession, user, project, messageDto.getType());
if (!result.isPresent()) {
dbClient.userDismissedMessagesDao().insert(dbSession, new UserDismissedMessageDto().setUuid(Uuids.create()).setUserUuid(user.getUuid()).setProjectUuid(project.getUuid()).setCeMessageType(messageDto.getType()));
dbSession.commit();
}
response.noContent();
}
}
use of org.sonar.db.user.UserDismissedMessageDto in project sonarqube by SonarSource.
the class UpgradeSuggestionsCleanerTest method insertInUserDismissedMessages.
private void insertInUserDismissedMessages(String uuid, CeTaskMessageType messageType) {
UserDismissedMessageDto dto = new UserDismissedMessageDto().setUuid(uuid).setUserUuid(user.getUuid()).setProjectUuid("PROJECT_1").setCeMessageType(messageType);
dbTester.getDbClient().userDismissedMessagesDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
}
Aggregations