use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectGlobalAdministerEmailSubscribers_ignores_global_administers_without_email.
@Test
public void selectGlobalAdministerEmailSubscribers_ignores_global_administers_without_email() {
// user1 and user1NoEmail are global administers
UserDto user1 = db.users().insertUser(withEmail("user1"));
db.users().insertPermissionOnUser(user1, ADMINISTER);
UserDto user1NoEmail = db.users().insertUser(withoutEmail("user1NoEmail"));
db.users().insertPermissionOnUser(user1NoEmail, ADMINISTER);
// user2 and user2NoEmail are global administers
UserDto user2 = db.users().insertUser(withEmail("user2"));
db.users().insertPermissionOnUser(user2, ADMINISTER);
UserDto user2NoEmail = db.users().insertUser(withoutEmail("user2NoEmail"));
db.users().insertPermissionOnUser(user2NoEmail, ADMINISTER);
// user3 and user3NoEmail are 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);
UserDto user3NoEmail = db.users().insertUser(withoutEmail("user3NoEmail"));
db.users().insertMember(administratorGroup2, user3NoEmail);
Set<EmailSubscriberDto> subscribers = underTest.selectGlobalAdministerEmailSubscribers(dbSession);
assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1), globalEmailSubscriberOf(user2), globalEmailSubscriberOf(user3));
}
use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.
the class AuthorizationDaoTest method selectQualityProfileAdministratorLogins_return_users_within_quality_profile_administrator_group.
@Test
public void selectQualityProfileAdministratorLogins_return_users_within_quality_profile_administrator_group() {
GroupDto qualityProfileAdministratorGroup1 = db.users().insertGroup();
db.users().insertPermissionOnGroup(qualityProfileAdministratorGroup1, ADMINISTER_QUALITY_PROFILES);
UserDto user1 = db.users().insertUser(withEmail("user1"));
db.users().insertMember(qualityProfileAdministratorGroup1, user1);
GroupDto qualityProfileAdministratorGroup2 = db.users().insertGroup();
db.users().insertPermissionOnGroup(qualityProfileAdministratorGroup2, ADMINISTER_QUALITY_PROFILES);
UserDto user2 = db.users().insertUser(withEmail("user2"));
db.users().insertMember(qualityProfileAdministratorGroup2, user2);
Set<EmailSubscriberDto> subscribers = underTest.selectQualityProfileAdministratorLogins(dbSession);
assertThat(subscribers).containsOnly(globalEmailSubscriberOf(user1), globalEmailSubscriberOf(user2));
}
use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method findSubscribedEmailRecipients_does_not_call_db_for_project_permission_filtering_if_there_is_no_project_subscriber.
@Test
public void findSubscribedEmailRecipients_does_not_call_db_for_project_permission_filtering_if_there_is_no_project_subscriber() {
String dispatcherKey = randomAlphabetic(12);
String globalPermission = randomAlphanumeric(4);
String projectPermission = randomAlphanumeric(5);
String projectKey = randomAlphabetic(6);
Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> EmailSubscriberDto.create("user" + i, true, "user" + i + "@sonarsource.com")).collect(Collectors.toSet());
Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet());
when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey)).thenReturn(subscribers);
when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, globalPermission)).thenReturn(logins);
Set<EmailRecipient> emailRecipients = underTest.findSubscribedEmailRecipients(dispatcherKey, projectKey, new SubscriberPermissionsOnProject(globalPermission, projectPermission));
Set<EmailRecipient> expected = subscribers.stream().map(i -> new EmailRecipient(i.getLogin(), i.getEmail())).collect(Collectors.toSet());
assertThat(emailRecipients).isEqualTo(expected);
verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(globalPermission));
verify(authorizationDao, times(0)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(projectPermission));
}
use of org.sonar.db.EmailSubscriberDto in project sonarqube by SonarSource.
the class DefaultNotificationManagerTest method findSubscribedEmailRecipients_with_logins_does_not_call_db_for_project_permission_filtering_if_there_is_no_project_subscriber.
@Test
public void findSubscribedEmailRecipients_with_logins_does_not_call_db_for_project_permission_filtering_if_there_is_no_project_subscriber() {
String dispatcherKey = randomAlphabetic(12);
String globalPermission = randomAlphanumeric(4);
String projectPermission = randomAlphanumeric(5);
String projectKey = randomAlphabetic(6);
Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)).mapToObj(i -> EmailSubscriberDto.create("user" + i, true, "user" + i + "@sonarsource.com")).collect(Collectors.toSet());
Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet());
when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey, logins)).thenReturn(subscribers);
when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, globalPermission)).thenReturn(logins);
Set<EmailRecipient> emailRecipients = underTest.findSubscribedEmailRecipients(dispatcherKey, projectKey, logins, new SubscriberPermissionsOnProject(globalPermission, projectPermission));
Set<EmailRecipient> expected = subscribers.stream().map(i -> new EmailRecipient(i.getLogin(), i.getEmail())).collect(Collectors.toSet());
assertThat(emailRecipients).isEqualTo(expected);
verify(authorizationDao, times(1)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(globalPermission));
verify(authorizationDao, times(0)).keepAuthorizedLoginsOnProject(eq(dbSession), anySet(), anyString(), eq(projectPermission));
}
Aggregations