Search in sources :

Example 1 with UserDismissedMessageDto

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());
}
Also used : PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto) Test(org.junit.Test)

Example 2 with UserDismissedMessageDto

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());
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) PermissionTemplateUserDto(org.sonar.db.permission.template.PermissionTemplateUserDto) UserDto(org.sonar.db.user.UserDto) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto) Test(org.junit.Test)

Example 3 with UserDismissedMessageDto

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();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto)

Example 4 with UserDismissedMessageDto

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();
}
Also used : UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto)

Aggregations

UserDismissedMessageDto (org.sonar.db.user.UserDismissedMessageDto)4 ProjectDto (org.sonar.db.project.ProjectDto)3 UserDto (org.sonar.db.user.UserDto)3 Test (org.junit.Test)2 DbSession (org.sonar.db.DbSession)1 CeTaskMessageDto (org.sonar.db.ce.CeTaskMessageDto)1 PermissionTemplateUserDto (org.sonar.db.permission.template.PermissionTemplateUserDto)1 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1