Search in sources :

Example 1 with EmailSubscriberDto

use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.

the class PropertiesDaoTest method findEmailRecipientsForNotification_returns_empty_on_empty_properties_table.

@Test
public void findEmailRecipientsForNotification_returns_empty_on_empty_properties_table() {
    db.users().insertUser();
    String dispatcherKey = randomAlphabetic(5);
    String channelKey = randomAlphabetic(6);
    String projectKey = randomAlphabetic(7);
    Set<EmailSubscriberDto> subscribers = underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey);
    assertThat(subscribers).isEmpty();
}
Also used : EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 2 with EmailSubscriberDto

use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.

the class DefaultNotificationManager method findSubscribedEmailRecipients.

@Override
public Set<EmailRecipient> findSubscribedEmailRecipients(String dispatcherKey, String projectKey, Set<String> logins, SubscriberPermissionsOnProject subscriberPermissionsOnProject) {
    verifyProjectKey(projectKey);
    requireNonNull(logins, "logins can't be null");
    if (logins.isEmpty()) {
        return emptySet();
    }
    try (DbSession dbSession = dbClient.openSession(false)) {
        Set<EmailSubscriberDto> emailSubscribers = dbClient.propertiesDao().findEmailSubscribersForNotification(dbSession, dispatcherKey, EmailNotificationChannel.class.getSimpleName(), projectKey, logins);
        return keepAuthorizedEmailSubscribers(dbSession, projectKey, subscriberPermissionsOnProject, emailSubscribers);
    }
}
Also used : DbSession(org.sonar.db.DbSession) EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) EmailNotificationChannel(org.sonar.server.notification.email.EmailNotificationChannel)

Example 3 with EmailSubscriberDto

use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.

the class AuthorizationDaoTest method selectGlobalAdministerEmailSubscribers_returns_only_global_administers.

@Test
public void selectGlobalAdministerEmailSubscribers_returns_only_global_administers() {
    UserDto user1 = db.users().insertUser(withEmail("user1"));
    db.users().insertPermissionOnUser(user1, ADMINISTER);
    UserDto user2 = db.users().insertUser(withEmail("user2"));
    db.users().insertPermissionOnUser(user2, ADMINISTER);
    // user3 is global administer via a group
    GroupDto administratorGroup2 = db.users().insertGroup();
    db.users().insertPermissionOnGroup(administratorGroup2, ADMINISTER);
    UserDto user3 = db.users().insertUser(withEmail("user3"));
    db.users().insertMember(administratorGroup2, user3);
    // user4 has another global permission via a group
    GroupDto administratorGroup3 = db.users().insertGroup();
    db.users().insertPermissionOnGroup(administratorGroup3, QUALITY_PROFILE_ADMIN);
    UserDto user4 = db.users().insertUser(withEmail("user4"));
    db.users().insertMember(administratorGroup3, user4);
    ComponentDto project = db.components().insertPrivateProject();
    // user5 is only project level administer
    UserDto user5 = db.users().insertUser(withEmail("user5"));
    // db.users().insertPermissionOnUser(user5, ADMINISTER);
    db.users().insertProjectPermissionOnUser(user5, "admin", project);
    // user6 has other global permission
    UserDto user6 = db.users().insertUser(withEmail("user6"));
    db.users().insertPermissionOnUser(user6, ADMINISTER_QUALITY_PROFILES);
    // user7 has no permission
    db.users().insertUser(withEmail("user7"));
    Set<EmailSubscriberDto> subscribers = underTest.selectGlobalAdministerEmailSubscribers(dbSession);
    assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1), globalEmailSubscriberOf(user2), globalEmailSubscriberOf(user3));
}
Also used : EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with EmailSubscriberDto

use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.

the class AuthorizationDaoTest method selectQualityProfileAdministratorLogins_does_not_return_non_quality_profile_administrator.

@Test
public void selectQualityProfileAdministratorLogins_does_not_return_non_quality_profile_administrator() {
    UserDto user1 = db.users().insertUser(withEmail("user1"));
    db.users().insertPermissionOnUser(user1, ADMINISTER);
    db.users().insertUser(withoutEmail("user2"));
    Set<EmailSubscriberDto> subscribers = underTest.selectQualityProfileAdministratorLogins(dbSession);
    assertThat(subscribers).isEmpty();
}
Also used : EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 5 with EmailSubscriberDto

use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.

the class AuthorizationDaoTest method selectQualityProfileAdministratorLogins_does_not_return_quality_profile_administrator_without_email.

@Test
public void selectQualityProfileAdministratorLogins_does_not_return_quality_profile_administrator_without_email() {
    UserDto user1NoEmail = db.users().insertUser(withoutEmail("user1NoEmail"));
    db.users().insertPermissionOnUser(user1NoEmail, ADMINISTER_QUALITY_PROFILES);
    UserDto user1WithEmail = db.users().insertUser(withEmail("user1WithEmail"));
    db.users().insertPermissionOnUser(user1WithEmail, ADMINISTER_QUALITY_PROFILES);
    GroupDto qualityProfileAdministratorGroup1 = db.users().insertGroup();
    db.users().insertPermissionOnGroup(qualityProfileAdministratorGroup1, ADMINISTER_QUALITY_PROFILES);
    UserDto user2NoEmail = db.users().insertUser(withoutEmail("user2NoEmail"));
    db.users().insertMember(qualityProfileAdministratorGroup1, user2NoEmail);
    UserDto user2WithEmail = db.users().insertUser(withEmail("user2WithEmail"));
    db.users().insertMember(qualityProfileAdministratorGroup1, user2WithEmail);
    GroupDto qualityProfileAdministratorGroup2 = db.users().insertGroup();
    db.users().insertPermissionOnGroup(qualityProfileAdministratorGroup2, ADMINISTER_QUALITY_PROFILES);
    UserDto user3NoEmail = db.users().insertUser(withoutEmail("user3NoEmail"));
    db.users().insertMember(qualityProfileAdministratorGroup2, user3NoEmail);
    UserDto user3WithEmail = db.users().insertUser(withEmail("user3WithEmail"));
    db.users().insertMember(qualityProfileAdministratorGroup2, user3WithEmail);
    UserDto user4NoEmail = db.users().insertUser(withoutEmail("user4NoEmail"));
    db.users().insertPermissionOnUser(user4NoEmail, ADMINISTER_QUALITY_PROFILES);
    UserDto user4WithEmail = db.users().insertUser(withEmail("user4WithEmail"));
    db.users().insertPermissionOnUser(user4WithEmail, ADMINISTER_QUALITY_PROFILES);
    UserDto user5NoEmail = db.users().insertUser(withoutEmail("user5NoEmail"));
    db.users().insertPermissionOnUser(user5NoEmail, ADMINISTER_QUALITY_PROFILES);
    UserDto user5WithEmail = db.users().insertUser(withEmail("user5WithEmail"));
    db.users().insertPermissionOnUser(user5WithEmail, ADMINISTER_QUALITY_PROFILES);
    db.users().insertUser(withoutEmail("user6NoEmail"));
    db.users().insertUser(withEmail("user6WithEmail"));
    Set<EmailSubscriberDto> subscribers = underTest.selectQualityProfileAdministratorLogins(dbSession);
    assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1WithEmail), globalEmailSubscriberOf(user2WithEmail), globalEmailSubscriberOf(user3WithEmail), globalEmailSubscriberOf(user4WithEmail), globalEmailSubscriberOf(user5WithEmail));
}
Also used : EmailSubscriberDto(org.sonar.db.EmailSubscriberDto) UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Aggregations

EmailSubscriberDto (org.sonar.db.EmailSubscriberDto)14 Test (org.junit.Test)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 DbSession (org.sonar.db.DbSession)6 Random (java.util.Random)5 Set (java.util.Set)5 IntStream (java.util.stream.IntStream)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Before (org.junit.Before)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.verify (org.mockito.Mockito.verify)5 Mockito.when (org.mockito.Mockito.when)5 DbClient (org.sonar.db.DbClient)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Multimap (com.google.common.collect.Multimap)4 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)4 InvalidClassException (java.io.InvalidClassException)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4