From: Sébastien Lesaint Date: Tue, 3 Oct 2017 15:41:32 +0000 (+0200) Subject: SONAR-4824 support branches when filtering recipients on their perms X-Git-Tag: 6.6-RC1~56 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1b98f493116b447b4f8763399f19b6782ea8e741;p=sonarqube.git SONAR-4824 support branches when filtering recipients on their perms by querying permissions in DB with component key rather than component uuid as computing the target branch's key from the branch's key is easy --- diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java index 56ff394b3eb..9e8538b5217 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationDao.java @@ -177,10 +177,10 @@ public class AuthorizationDao implements Dao { return mapper(dbSession).selectLoginsWithGlobalPermission(ADMINISTER.getKey()); } - public Set keepAuthorizedLoginsOnProject(DbSession dbSession, Set logins, String projectUuid, String permission) { + public Set keepAuthorizedLoginsOnProject(DbSession dbSession, Set logins, String projectKey, String permission) { return executeLargeInputsIntoSet( logins, - partitionOfLogins -> mapper(dbSession).keepAuthorizedLoginsOnProject(partitionOfLogins, projectUuid, permission), + partitionOfLogins -> mapper(dbSession).keepAuthorizedLoginsOnProject(partitionOfLogins, projectKey, permission), partitionSize -> partitionSize / 3); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java index 1c788ea1019..3a7043bfb13 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/AuthorizationMapper.java @@ -63,7 +63,7 @@ public interface AuthorizationMapper { List selectQualityProfileAdministratorLogins(@Param("permission") String permission); - Set keepAuthorizedLoginsOnProject(@Param("logins") List logins, @Param("projectUuid") String projectUuid, @Param("permission") String permission); + Set keepAuthorizedLoginsOnProject(@Param("logins") List logins, @Param("projectKey") String projectKey, @Param("permission") String permission); List selectLoginsWithGlobalPermission(@Param("permission") String permission); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java index db9f924d2f2..46b1d3b4a7c 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesDao.java @@ -66,9 +66,9 @@ public class PropertiesDao implements Dao { * * @return the list of Subscriber (maybe be empty - obviously) */ - public Set findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable String projectUuid) { + public Set findUsersForNotification(String notificationDispatcherKey, String notificationChannelKey, @Nullable String projectKey) { try (DbSession session = mybatis.openSession(false)) { - return getMapper(session).findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, projectUuid); + return getMapper(session).findUsersForNotification(NOTIFICATION_PREFIX + notificationDispatcherKey + "." + notificationChannelKey, projectKey); } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java index 2d9c75df052..4472156d450 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/property/PropertiesMapper.java @@ -26,7 +26,7 @@ import org.apache.ibatis.annotations.Param; public interface PropertiesMapper { - Set findUsersForNotification(@Param("notifKey") String notificationKey, @Nullable @Param("projectUuid") String projectUuid); + Set findUsersForNotification(@Param("notifKey") String notificationKey, @Nullable @Param("projectKey") String projectKey); List selectGlobalProperties(); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml index b43ede52e69..60f105b4ede 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/AuthorizationMapper.xml @@ -401,7 +401,7 @@ SELECT u.login FROM users u INNER JOIN user_roles ur ON ur.user_id = u.id - INNER JOIN projects p ON p.uuid = #{projectUuid,jdbcType=VARCHAR} + INNER JOIN projects p ON p.kee = #{projectKey,jdbcType=VARCHAR} WHERE ur.organization_uuid = p.organization_uuid AND ur.resource_id = p.id @@ -412,7 +412,7 @@ SELECT u.login FROM users u - INNER JOIN projects p ON p.uuid = #{projectUuid,jdbcType=VARCHAR} + INNER JOIN projects p ON p.kee = #{projectKey,jdbcType=VARCHAR} INNER JOIN group_roles gr ON gr.organization_uuid = p.organization_uuid INNER JOIN groups_users gu ON gr.group_id = gu.group_id WHERE @@ -425,7 +425,7 @@ SELECT u.login FROM users u - INNER JOIN projects p ON p.uuid = #{projectUuid,jdbcType=VARCHAR} + INNER JOIN projects p ON p.kee = #{projectKey,jdbcType=VARCHAR} WHERE p.private = ${_false} AND u.login IN #{login} diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml index b41fa68b0b4..f5571ebe90f 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/property/PropertiesMapper.xml @@ -22,7 +22,7 @@ ${_false} as "global" FROM users u - INNER JOIN projects c on c.uuid = #{projectUuid,jdbcType=VARCHAR} + INNER JOIN projects c on c.kee = #{projectKey,jdbcType=VARCHAR} INNER JOIN properties p ON p.user_id = u.id WHERE p.prop_key = #{notifKey,jdbcType=VARCHAR} diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java index 693266f6722..951f8011a03 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java @@ -35,6 +35,7 @@ import org.sonar.core.permission.ProjectPermissions; import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbSession; import org.sonar.db.DbTester; +import org.sonar.db.component.BranchType; import org.sonar.db.component.ComponentDto; import org.sonar.db.organization.OrganizationDto; import org.sonar.db.user.GroupDto; @@ -61,6 +62,7 @@ public class AuthorizationDaoTest { @Rule public DbTester db = DbTester.create(System2.INSTANCE); + private final Random random = new Random(); private DbSession dbSession = db.getSession(); private AuthorizationDao underTest = new AuthorizationDao(); private OrganizationDto organization; @@ -70,7 +72,7 @@ public class AuthorizationDaoTest { private Set randomPublicProjectIds; private Set randomPrivateProjectIds; private Set randomExistingUserIds; - private String randomPermission = "p" + new Random().nextInt(); + private String randomPermission = "p" + random.nextInt(); @Before public void setUp() throws Exception { @@ -78,15 +80,15 @@ public class AuthorizationDaoTest { user = db.users().insertUser(); group1 = db.users().insertGroup(organization, "group1"); group2 = db.users().insertGroup(organization, "group2"); - randomExistingUserIds = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5))) + randomExistingUserIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .map(i -> db.users().insertUser().getId()) .boxed() .collect(MoreCollectors.toSet()); - randomPublicProjectIds = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5))) + randomPublicProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .mapToLong(i -> db.components().insertPublicProject(organization).getId()) .boxed() .collect(MoreCollectors.toSet()); - randomPrivateProjectIds = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5))) + randomPrivateProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .mapToLong(i -> db.components().insertPrivateProject(organization).getId()) .boxed() .collect(MoreCollectors.toSet()); @@ -239,7 +241,7 @@ public class AuthorizationDaoTest { @Test public void keepAuthorizedProjectIds_returns_empty_for_group_AnyOne_for_non_existent_projects() { - Set randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5))) + Set randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .mapToLong(i -> 3_562 + i) .boxed() .collect(MoreCollectors.toSet()); @@ -250,7 +252,7 @@ public class AuthorizationDaoTest { @Test public void keepAuthorizedProjectIds_returns_empty_for_user_for_non_existent_projects() { - Set randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5))) + Set randomNonProjectsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .mapToLong(i -> 9_666 + i) .boxed() .collect(MoreCollectors.toSet()); @@ -513,8 +515,8 @@ public class AuthorizationDaoTest { @Test public void keepAuthorizedUsersForRoleAndProject_returns_empty_for_non_existent_users() { - ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject(organization) : db.components().insertPrivateProject(organization); - Set randomNonExistingUserIdsSet = IntStream.range(0, 1 + Math.abs(new Random().nextInt(5))) + ComponentDto project = random.nextBoolean() ? db.components().insertPublicProject(organization) : db.components().insertPrivateProject(organization); + Set randomNonExistingUserIdsSet = IntStream.range(0, 1 + Math.abs(random.nextInt(5))) .map(i -> i + 1_990) .boxed() .collect(MoreCollectors.toSet()); @@ -1044,11 +1046,11 @@ public class AuthorizationDaoTest { db.users().insertMember(adminGroup, admin2); db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project); - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.uuid(), UserRole.USER)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.getKey(), UserRole.USER)) .containsOnly(user1.getLogin()); - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.uuid(), UserRole.USER)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.getKey(), UserRole.USER)) .containsOnly(user1.getLogin(), admin1.getLogin(), admin2.getLogin()); - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.uuid(), UserRole.ADMIN)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin(), admin1.getLogin(), admin2.getLogin()), project.getKey(), UserRole.ADMIN)) .containsOnly(admin1.getLogin(), admin2.getLogin()); } @@ -1080,17 +1082,60 @@ public class AuthorizationDaoTest { // user without role UserDto userWithNoRole = db.users().insertUser(); - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), project.uuid(), UserRole.USER)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), project.getKey(), UserRole.USER)) .isEmpty(); - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.uuid(), UserRole.USER)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), project.getKey(), UserRole.USER)) .containsOnly(user1.getLogin()); Set allLogins = newHashSet(admin1.getLogin(), admin2.getLogin(), user1.getLogin(), user2.getLogin(), userWithNoRole.getLogin()); // Admin does not have the USER permission set - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.uuid(), UserRole.USER)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.getKey(), UserRole.USER)) .containsOnly(user1.getLogin(), user2.getLogin()); - assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.uuid(), UserRole.ADMIN)) + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, project.getKey(), UserRole.ADMIN)) + .containsOnly(admin1.getLogin(), admin2.getLogin()); + } + + @Test + public void keepAuthorizedLoginsOnProject_return_correct_users_on_branch() { + ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto branch = db.components().insertProjectBranch(project, c -> c.setBranchType(random.nextBoolean() ? BranchType.SHORT : BranchType.LONG)); + + GroupDto userGroup = db.users().insertGroup(organization, "USERS"); + GroupDto adminGroup = db.users().insertGroup(organization, "ADMIN"); + db.users().insertProjectPermissionOnGroup(userGroup, UserRole.USER, project); + db.users().insertProjectPermissionOnGroup(adminGroup, UserRole.ADMIN, project); + + // admin with "direct" ADMIN role + UserDto admin1 = db.users().insertUser(); + db.users().insertProjectPermissionOnUser(admin1, UserRole.ADMIN, project); + + // admin2 with ADMIN role through group + UserDto admin2 = db.users().insertUser(); + db.users().insertMember(adminGroup, admin2); + + // user1 with "direct" USER role + UserDto user1 = db.users().insertUser(); + db.users().insertProjectPermissionOnUser(user1, UserRole.USER, project); + + // user2 with USER role through group + UserDto user2 = db.users().insertUser(); + db.users().insertMember(userGroup, user2); + + // user without role + UserDto userWithNoRole = db.users().insertUser(); + + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(userWithNoRole.getLogin()), branch.getKey(), UserRole.USER)) + .isEmpty(); + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, newHashSet(user1.getLogin()), branch.getKey(), UserRole.USER)) + .containsOnly(user1.getLogin()); + + Set allLogins = newHashSet(admin1.getLogin(), admin2.getLogin(), user1.getLogin(), user2.getLogin(), userWithNoRole.getLogin()); + + // Admin does not have the USER permission set + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, branch.getKey(), UserRole.USER)) + .containsOnly(user1.getLogin(), user2.getLogin()); + assertThat(underTest.keepAuthorizedLoginsOnProject(dbSession, allLogins, branch.getKey(), UserRole.ADMIN)) .containsOnly(admin1.getLogin(), admin2.getLogin()); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index 1379ac1caf9..c066f2caa83 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -101,10 +101,10 @@ public class PropertiesDaoTest { assertThat(underTest.findUsersForNotification("NewViolations", "Email", "uuid_78")) .isEmpty(); - assertThat(underTest.findUsersForNotification("NewViolations", "Email", project1.uuid())) + assertThat(underTest.findUsersForNotification("NewViolations", "Email", project1.getKey())) .containsOnly(new Subscriber("user2", false)); - assertThat(underTest.findUsersForNotification("NewViolations", "Email", project2.uuid())) + assertThat(underTest.findUsersForNotification("NewViolations", "Email", project2.getKey())) .isEmpty(); assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", null)) @@ -113,10 +113,10 @@ public class PropertiesDaoTest { assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", "uuid_78")) .containsOnly(new Subscriber("user3", true)); - assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project1.uuid())) + assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project1.getKey())) .containsOnly(new Subscriber("user2", false), new Subscriber("user3", true)); - assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project2.uuid())) + assertThat(underTest.findUsersForNotification("NewViolations", "Twitter", project2.getKey())) .containsOnly(new Subscriber("user1", false), new Subscriber("user3", true), new Subscriber("user3", false)); } diff --git a/server/sonar-server/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcher.java index ff3ad8346c2..80ad8c05625 100644 --- a/server/sonar-server/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcher.java @@ -55,9 +55,9 @@ public class ReportAnalysisFailureNotificationDispatcher extends NotificationDis @Override public void dispatch(Notification notification, Context context) { - String projectUuid = notification.getFieldValue("project.uuid"); - Multimap subscribedRecipients = manager.findSubscribedRecipientsForDispatcher( - this, projectUuid, REQUIRED_SUBSCRIBER_PERMISSIONS); + String projectKey = notification.getFieldValue("project.key"); + Multimap subscribedRecipients = manager + .findSubscribedRecipientsForDispatcher(this, projectKey, REQUIRED_SUBSCRIBER_PERMISSIONS); for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { String userLogin = channelsByRecipients.getKey(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java index 0718f982640..47476580719 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java @@ -127,7 +127,6 @@ public class QualityGateEventsStep implements ComputationStep { .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label)) .setFieldValue("projectName", project.getName()) .setFieldValue("projectKey", project.getPublicKey()) - .setFieldValue("projectUuid", project.getUuid()) .setFieldValue("projectVersion", project.getReportAttributes().getVersion()) .setFieldValue("alertName", label) .setFieldValue("alertText", rawStatus.getText()) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java index c145b30d61b..b54344cc019 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java @@ -127,7 +127,7 @@ public class SendIssueNotificationsStep implements ComputationStep { IssueChangeNotification changeNotification = new IssueChangeNotification(); changeNotification.setRuleName(rules.getByKey(issue.ruleKey()).getName()); changeNotification.setIssue(issue); - changeNotification.setProject(project.getPublicKey(), project.getName(), getBranchName(), project.getUuid()); + changeNotification.setProject(project.getPublicKey(), project.getName(), getBranchName()); getComponentKey(issue).ifPresent(c -> changeNotification.setComponent(c.getPublicKey(), c.getName())); service.deliver(changeNotification); } @@ -136,7 +136,7 @@ public class SendIssueNotificationsStep implements ComputationStep { NewIssuesStatistics.Stats globalStatistics = statistics.globalStatistics(); NewIssuesNotification notification = newIssuesNotificationFactory .newNewIssuesNotication() - .setProject(project.getPublicKey(), project.getUuid(), project.getName(), getBranchName()) + .setProject(project.getPublicKey(), project.getName(), getBranchName()) .setProjectVersion(project.getReportAttributes().getVersion()) .setAnalysisDate(new Date(analysisDate)) .setStatistics(project.getName(), globalStatistics) @@ -155,7 +155,7 @@ public class SendIssueNotificationsStep implements ComputationStep { .newMyNewIssuesNotification() .setAssignee(assignee); myNewIssuesNotification - .setProject(project.getPublicKey(), project.getUuid(), project.getName(), getBranchName()) + .setProject(project.getPublicKey(), project.getName(), getBranchName()) .setProjectVersion(project.getReportAttributes().getVersion()) .setAnalysisDate(new Date(analysisDate)) .setStatistics(project.getName(), assigneeStatistics) diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java b/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java index 87804f12be2..f298a824a51 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java +++ b/server/sonar-server/src/main/java/org/sonar/server/event/NewAlerts.java @@ -58,10 +58,10 @@ public class NewAlerts extends NotificationDispatcher { @Override public void dispatch(Notification notification, Context context) { - String projectUuid = notification.getFieldValue("projectUuid"); - if (projectUuid != null) { - Multimap subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher( - this, projectUuid, ALL_MUST_HAVE_ROLE_USER); + String projectKey = notification.getFieldValue("projectKey"); + if (projectKey != null) { + Multimap subscribedRecipients = notifications + .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { String userLogin = channelsByRecipients.getKey(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java index 7a5eb221ac5..48673c575d4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java @@ -51,7 +51,6 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { static final String FIELD_PROJECT_NAME = "projectName"; static final String FIELD_PROJECT_KEY = "projectKey"; static final String FIELD_PROJECT_DATE = "projectDate"; - static final String FIELD_PROJECT_UUID = "projectUuid"; static final String FIELD_PROJECT_VERSION = "projectVersion"; static final String FIELD_ASSIGNEE = "assignee"; static final String FIELD_BRANCH = "branch"; diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java index 9f0031d9d81..26375d52a09 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcher.java @@ -59,9 +59,9 @@ public class ChangesOnMyIssueNotificationDispatcher extends NotificationDispatch @Override public void dispatch(Notification notification, Context context) { - String projectUuid = notification.getFieldValue("projectUuid"); - Multimap subscribedRecipients = notificationManager.findSubscribedRecipientsForDispatcher( - this, projectUuid, ALL_MUST_HAVE_ROLE_USER); + String projectKey = notification.getFieldValue("projectKey"); + Multimap subscribedRecipients = notificationManager + .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); // See available fields in the class IssueNotifications. diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java index 5c86e435af0..14bf4f2cc79 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcher.java @@ -62,9 +62,9 @@ public class DoNotFixNotificationDispatcher extends NotificationDispatcher { String newResolution = notification.getFieldValue("new.resolution"); if (Objects.equals(newResolution, Issue.RESOLUTION_FALSE_POSITIVE) || Objects.equals(newResolution, Issue.RESOLUTION_WONT_FIX)) { String author = notification.getFieldValue("changeAuthor"); - String projectUuid = notification.getFieldValue("projectUuid"); - Multimap subscribedRecipients = notifications.findSubscribedRecipientsForDispatcher( - this, projectUuid, ALL_MUST_HAVE_ROLE_USER); + String projectKey = notification.getFieldValue("projectKey"); + Multimap subscribedRecipients = notifications + .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); notify(author, context, subscribedRecipients); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java index 58d6b7296c3..f5504611692 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/IssueChangeNotification.java @@ -54,12 +54,11 @@ public class IssueChangeNotification extends Notification { } public IssueChangeNotification setProject(ComponentDto project) { - return setProject(project.getKey(), project.name(), project.getBranch(), project.uuid()); + return setProject(project.getKey(), project.name(), project.getBranch()); } - public IssueChangeNotification setProject(String projectKey, String projectName, @Nullable String branch, String projectUuid) { + public IssueChangeNotification setProject(String projectKey, String projectName, @Nullable String branch) { setFieldValue("projectName", projectName); - setFieldValue("projectUuid", projectUuid); setFieldValue("projectKey", projectKey); if (branch != null) { setFieldValue("branch", branch); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java index 3b50d87b305..46ed30b1db8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcher.java @@ -55,10 +55,10 @@ public class MyNewIssuesNotificationDispatcher extends NotificationDispatcher { @Override public void dispatch(Notification notification, Context context) { - String projectUuid = notification.getFieldValue("projectUuid"); + String projectKey = notification.getFieldValue("projectKey"); String assignee = notification.getFieldValue("assignee"); - Multimap subscribedRecipients = manager.findSubscribedRecipientsForDispatcher( - this, projectUuid, ALL_MUST_HAVE_ROLE_USER); + Multimap subscribedRecipients = manager + .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); Collection channels = subscribedRecipients.get(assignee); for (NotificationChannel channel : channels) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java index 3f5df507eb3..bc630d529a3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java @@ -49,7 +49,6 @@ import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_DATE; import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY; import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_NAME; -import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_UUID; import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE_TYPE; public class NewIssuesNotification extends Notification { @@ -80,10 +79,9 @@ public class NewIssuesNotification extends Notification { return this; } - public NewIssuesNotification setProject(String projectKey, String projectUuid, String projectName, @Nullable String branchName) { + public NewIssuesNotification setProject(String projectKey, String projectName, @Nullable String branchName) { setFieldValue(FIELD_PROJECT_NAME, projectName); setFieldValue(FIELD_PROJECT_KEY, projectKey); - setFieldValue(FIELD_PROJECT_UUID, projectUuid); if (branchName != null) { setFieldValue(FIELD_BRANCH, branchName); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java index cd404a4af6c..feccf3d73e3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcher.java @@ -56,9 +56,9 @@ public class NewIssuesNotificationDispatcher extends NotificationDispatcher { @Override public void dispatch(Notification notification, Context context) { - String projectUuid = notification.getFieldValue("projectUuid"); - Multimap subscribedRecipients = manager.findSubscribedRecipientsForDispatcher( - this, projectUuid, ALL_MUST_HAVE_ROLE_USER); + String projectKey = notification.getFieldValue("projectKey"); + Multimap subscribedRecipients = manager + .findSubscribedRecipientsForDispatcher(this, projectKey, ALL_MUST_HAVE_ROLE_USER); for (Map.Entry> channelsByRecipients : subscribedRecipients.asMap().entrySet()) { String userLogin = channelsByRecipients.getKey(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java b/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java index d7fd1c0b7f5..96406bbacfb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notification/DefaultNotificationManager.java @@ -118,13 +118,13 @@ public class DefaultNotificationManager implements NotificationManager { * {@inheritDoc} */ @Override - public Multimap findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, String projectUuid, - SubscriberPermissionsOnProject subscriberPermissionsOnProject) { - requireNonNull(projectUuid, "ProjectUUID is mandatory"); + public Multimap findSubscribedRecipientsForDispatcher(NotificationDispatcher dispatcher, + String projectKey, SubscriberPermissionsOnProject subscriberPermissionsOnProject) { + requireNonNull(projectKey, "projectKey is mandatory"); String dispatcherKey = dispatcher.getKey(); Set subscriberAndChannels = Arrays.stream(notificationChannels) - .flatMap(notificationChannel -> toSubscriberAndChannels(dispatcherKey, projectUuid, notificationChannel)) + .flatMap(notificationChannel -> toSubscriberAndChannels(dispatcherKey, projectKey, notificationChannel)) .collect(Collectors.toSet()); if (subscriberAndChannels.isEmpty()) { @@ -133,7 +133,7 @@ public class DefaultNotificationManager implements NotificationManager { ImmutableSetMultimap.Builder builder = ImmutableSetMultimap.builder(); try (DbSession dbSession = dbClient.openSession(false)) { - Set authorizedLogins = keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, subscriberPermissionsOnProject); + Set authorizedLogins = keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, subscriberPermissionsOnProject); subscriberAndChannels.stream() .filter(subscriberAndChannel -> authorizedLogins.contains(subscriberAndChannel.getSubscriber().getLogin())) .forEach(subscriberAndChannel -> builder.put(subscriberAndChannel.getSubscriber().getLogin(), subscriberAndChannel.getChannel())); @@ -141,27 +141,27 @@ public class DefaultNotificationManager implements NotificationManager { return builder.build(); } - private Stream toSubscriberAndChannels(String dispatcherKey, String projectUuid, NotificationChannel notificationChannel) { - Set usersForNotification = dbClient.propertiesDao().findUsersForNotification(dispatcherKey, notificationChannel.getKey(), projectUuid); + private Stream toSubscriberAndChannels(String dispatcherKey, String projectKey, NotificationChannel notificationChannel) { + Set usersForNotification = dbClient.propertiesDao().findUsersForNotification(dispatcherKey, notificationChannel.getKey(), projectKey); return usersForNotification .stream() .map(login -> new SubscriberAndChannel(login, notificationChannel)); } - private Set keepAuthorizedLogins(DbSession dbSession, String projectUuid, Set subscriberAndChannels, + private Set keepAuthorizedLogins(DbSession dbSession, String projectKey, Set subscriberAndChannels, SubscriberPermissionsOnProject requiredPermissions) { if (requiredPermissions.getGlobalSubscribers().equals(requiredPermissions.getProjectSubscribers())) { - return keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, null, requiredPermissions.getGlobalSubscribers()); + return keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, null, requiredPermissions.getGlobalSubscribers()); } else { return Stream .concat( - keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, true, requiredPermissions.getGlobalSubscribers()).stream(), - keepAuthorizedLogins(dbSession, projectUuid, subscriberAndChannels, false, requiredPermissions.getProjectSubscribers()).stream()) + keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, true, requiredPermissions.getGlobalSubscribers()).stream(), + keepAuthorizedLogins(dbSession, projectKey, subscriberAndChannels, false, requiredPermissions.getProjectSubscribers()).stream()) .collect(Collectors.toSet()); } } - private Set keepAuthorizedLogins(DbSession dbSession, String projectUuid, Set subscriberAndChannels, + private Set keepAuthorizedLogins(DbSession dbSession, String projectKey, Set subscriberAndChannels, @Nullable Boolean global, String permission) { Set logins = subscriberAndChannels.stream() .filter(s -> global == null || s.getSubscriber().isGlobal() == global) @@ -170,7 +170,7 @@ public class DefaultNotificationManager implements NotificationManager { if (logins.isEmpty()) { return Collections.emptySet(); } - return dbClient.authorizationDao().keepAuthorizedLoginsOnProject(dbSession, logins, projectUuid, permission); + return dbClient.authorizationDao().keepAuthorizedLoginsOnProject(dbSession, logins, projectKey, permission); } private static final class SubscriberAndChannel { diff --git a/server/sonar-server/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcherTest.java index 82cad44378c..6b59aa6f512 100644 --- a/server/sonar-server/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/ce/notification/ReportAnalysisFailureNotificationDispatcherTest.java @@ -78,8 +78,8 @@ public class ReportAnalysisFailureNotificationDispatcherTest { @Test public void performDispatch_adds_user_for_each_recipient_and_channel_for_the_component_uuid_in_the_notification() { when(notificationMock.getType()).thenReturn(ReportAnalysisFailureNotification.TYPE); - String projectUuid = randomAlphanumeric(9); - when(notificationMock.getFieldValue("project.uuid")).thenReturn(projectUuid); + String projectKey = randomAlphanumeric(9); + when(notificationMock.getFieldValue("project.key")).thenReturn(projectKey); HashMultimap multimap = HashMultimap.create(); String login1 = randomAlphanumeric(3); String login2 = randomAlphanumeric(3); @@ -90,7 +90,7 @@ public class ReportAnalysisFailureNotificationDispatcherTest { multimap.put(login1, channel2); multimap.put(login2, channel2); multimap.put(login2, channel3); - when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectUuid, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER))) + when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectKey, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER))) .thenReturn(multimap); underTest.performDispatch(notificationMock, contextMock); @@ -105,10 +105,10 @@ public class ReportAnalysisFailureNotificationDispatcherTest { @Test public void performDispatch_adds_no_user_if_notification_manager_returns_none() { when(notificationMock.getType()).thenReturn(ReportAnalysisFailureNotification.TYPE); - String projectUuid = randomAlphanumeric(9); - when(notificationMock.getFieldValue("project.uuid")).thenReturn(projectUuid); + String projectKey = randomAlphanumeric(9); + when(notificationMock.getFieldValue("project.key")).thenReturn(projectKey); HashMultimap multimap = HashMultimap.create(); - when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectUuid, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER))) + when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, projectKey, new SubscriberPermissionsOnProject(UserRole.ADMIN, UserRole.USER))) .thenReturn(multimap); underTest.performDispatch(notificationMock, contextMock); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java index f0d821eb93b..ef8923c092a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java @@ -188,7 +188,6 @@ public class QualityGateEventsStepTest { Notification notification = notificationArgumentCaptor.getValue(); assertThat(notification.getType()).isEqualTo("alerts"); assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey()); - assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid()); assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion()); assertThat(notification.getFieldValue("branch")).isNull(); @@ -241,7 +240,6 @@ public class QualityGateEventsStepTest { Notification notification = notificationArgumentCaptor.getValue(); assertThat(notification.getType()).isEqualTo("alerts"); assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey()); - assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid()); assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion()); assertThat(notification.getFieldValue("branch")).isNull(); @@ -271,7 +269,6 @@ public class QualityGateEventsStepTest { Notification notification = notificationArgumentCaptor.getValue(); assertThat(notification.getType()).isEqualTo("alerts"); assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey()); - assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid()); assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion()); assertThat(notification.getFieldValue("branch")).isEqualTo(branchName); @@ -293,7 +290,6 @@ public class QualityGateEventsStepTest { Notification notification = notificationArgumentCaptor.getValue(); assertThat(notification.getType()).isEqualTo("alerts"); assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey()); - assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid()); assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName()); assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion()); assertThat(notification.getFieldValue("branch")).isEqualTo(null); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java index 8646a7bb46c..0516536628c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStepTest.java @@ -144,7 +144,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { underTest.execute(); verify(notificationService).deliver(newIssuesNotificationMock); - verify(newIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getUuid(), PROJECT.getName(), null); + verify(newIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null); verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE)); verify(newIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any(NewIssuesStatistics.Stats.class)); verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION); @@ -207,7 +207,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { underTest.execute(); verify(notificationService).deliver(newIssuesNotificationMock); - verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.uuid(), branch.longName(), BRANCH_NAME); + verify(newIssuesNotificationMock).setProject(branch.getKey(), branch.longName(), BRANCH_NAME); verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE)); verify(newIssuesNotificationMock).setStatistics(eq(branch.longName()), any(NewIssuesStatistics.Stats.class)); verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION); @@ -239,7 +239,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { verify(notificationService).deliver(newIssuesNotificationMock); verify(notificationService).deliver(myNewIssuesNotificationMock); verify(myNewIssuesNotificationMock).setAssignee(ISSUE_ASSIGNEE); - verify(myNewIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getUuid(), PROJECT.getName(), null); + verify(myNewIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null); verify(myNewIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE)); verify(myNewIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any(NewIssuesStatistics.Stats.class)); verify(myNewIssuesNotificationMock).setDebt(ISSUE_DURATION); @@ -425,7 +425,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { private NewIssuesNotification createNewIssuesNotificationMock() { NewIssuesNotification notification = mock(NewIssuesNotification.class); - when(notification.setProject(anyString(), anyString(), anyString(), anyString())).thenReturn(notification); + when(notification.setProject(anyString(), anyString(), anyString())).thenReturn(notification); when(notification.setProjectVersion(anyString())).thenReturn(notification); when(notification.setAnalysisDate(any(Date.class))).thenReturn(notification); when(notification.setStatistics(anyString(), any(NewIssuesStatistics.Stats.class))).thenReturn(notification); @@ -436,7 +436,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { private MyNewIssuesNotification createMyNewIssuesNotificationMock() { MyNewIssuesNotification notification = mock(MyNewIssuesNotification.class); when(notification.setAssignee(anyString())).thenReturn(notification); - when(notification.setProject(anyString(), anyString(), anyString(), anyString())).thenReturn(notification); + when(notification.setProject(anyString(), anyString(), anyString())).thenReturn(notification); when(notification.setProjectVersion(anyString())).thenReturn(notification); when(notification.setAnalysisDate(any(Date.class))).thenReturn(notification); when(notification.setStatistics(anyString(), any(NewIssuesStatistics.Stats.class))).thenReturn(notification); diff --git a/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java b/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java index bb20ef863d9..62b3327fabc 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/event/NewAlertsTest.java @@ -28,15 +28,20 @@ import org.sonar.api.web.UserRole; import org.sonar.server.notification.NotificationDispatcher; import org.sonar.server.notification.NotificationManager; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; public class NewAlertsTest { - NotificationManager notificationManager = mock(NotificationManager.class); - NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class); - NotificationChannel emailChannel = mock(NotificationChannel.class); - NotificationChannel twitterChannel = mock(NotificationChannel.class); - NewAlerts dispatcher = new NewAlerts(notificationManager); + private NotificationManager notificationManager = mock(NotificationManager.class); + private NotificationDispatcher.Context context = mock(NotificationDispatcher.Context.class); + private NotificationChannel emailChannel = mock(NotificationChannel.class); + private NotificationChannel twitterChannel = mock(NotificationChannel.class); + private NewAlerts dispatcher = new NewAlerts(notificationManager); @Test public void should_not_dispatch_if_not_alerts_notification() { @@ -51,9 +56,11 @@ public class NewAlertsTest { Multimap recipients = HashMultimap.create(); recipients.put("user1", emailChannel); recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "uuid_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); + when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "key_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))) + .thenReturn(recipients); - Notification notification = new Notification("alerts").setFieldValue("projectUuid", "uuid_34"); + Notification notification = new Notification("alerts") + .setFieldValue("projectKey", "key_34"); dispatcher.performDispatch(notification, context); verify(context).addUser("user1", emailChannel); @@ -62,11 +69,12 @@ public class NewAlertsTest { } @Test - public void should_not_dispatch_if_missing_project_id() { + public void should_not_dispatch_if_missing_project_key() { Multimap recipients = HashMultimap.create(); recipients.put("user1", emailChannel); recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "uuid_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); + when(notificationManager.findSubscribedRecipientsForDispatcher(dispatcher, "key_34", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))) + .thenReturn(recipients); Notification notification = new Notification("alerts"); dispatcher.performDispatch(notification, context); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java index bf2b55409d6..8e33f079c96 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueUpdaterTest.java @@ -117,7 +117,6 @@ public class IssueUpdaterTest { assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.getDbKey()); assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(project.getDbKey()); - assertThat(issueChangeNotification.getFieldValue("projectUuid")).isEqualTo(project.uuid()); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(project.name()); assertThat(issueChangeNotification.getFieldValue("ruleName")).isEqualTo(rule.getName()); assertThat(issueChangeNotification.getFieldValue("changeAuthor")).isEqualTo("john"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java index e58a9a71a60..cad2fdc1ec2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationDispatcherTest.java @@ -84,12 +84,11 @@ public class ChangesOnMyIssueNotificationDispatcherTest { recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); - when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "uuid1", - new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); + when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "struts", + new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); Notification notification = new IssueChangeNotification() .setFieldValue("projectKey", "struts") - .setFieldValue("projectUuid", "uuid1") .setFieldValue("changeAuthor", "olivier") .setFieldValue("assignee", "freddy"); dispatcher.performDispatch(notification, context); @@ -113,7 +112,8 @@ public class ChangesOnMyIssueNotificationDispatcherTest { .setFieldValue("projectKey", "struts") .setFieldValue("projectUuid", "uuid1") .setFieldValue("changeAuthor", "simon") - .setFieldValue("assignee", "simon"), context); + .setFieldValue("assignee", "simon"), + context); // no change author dispatcher.performDispatch(new IssueChangeNotification().setFieldValue("projectKey", "struts") diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java index c1467623791..7248080bd18 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/DoNotFixNotificationDispatcherTest.java @@ -31,7 +31,13 @@ import org.sonar.server.notification.NotificationDispatcherMetadata; import org.sonar.server.notification.NotificationManager; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; public class DoNotFixNotificationDispatcherTest { NotificationManager notifications = mock(NotificationManager.class); @@ -62,10 +68,10 @@ public class DoNotFixNotificationDispatcherTest { recipients.put("simon", emailChannel); recipients.put("freddy", twitterChannel); recipients.put("godin", twitterChannel); - when(notifications.findSubscribedRecipientsForDispatcher(underTest, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); + when(notifications.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); - Notification fpNotif = new IssueChangeNotification().setFieldValue("projectKey", "struts") - .setFieldValue("projectUuid", "uuid1") + Notification fpNotif = new IssueChangeNotification() + .setFieldValue("projectKey", "struts") .setFieldValue("changeAuthor", "godin") .setFieldValue("new.resolution", Issue.RESOLUTION_FALSE_POSITIVE) .setFieldValue("assignee", "freddy"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java index 94ff9af63e8..18a513ca9ff 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangeNotificationTest.java @@ -84,18 +84,16 @@ public class IssueChangeNotificationTest { @Test public void set_project_without_branch() { - IssueChangeNotification result = notification.setProject("MyService", "My Service", null, "uuid1"); + IssueChangeNotification result = notification.setProject("MyService", "My Service", null); assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService"); - assertThat(result.getFieldValue("projectUuid")).isEqualTo("uuid1"); assertThat(result.getFieldValue("projectName")).isEqualTo("My Service"); assertThat(result.getFieldValue("branch")).isNull(); } @Test public void set_project_with_branch() { - IssueChangeNotification result = notification.setProject("MyService", "My Service", "feature1", "uuid2"); + IssueChangeNotification result = notification.setProject("MyService", "My Service", "feature1"); assertThat(result.getFieldValue("projectKey")).isEqualTo("MyService"); - assertThat(result.getFieldValue("projectUuid")).isEqualTo("uuid2"); assertThat(result.getFieldValue("projectName")).isEqualTo("My Service"); assertThat(result.getFieldValue("branch")).isEqualTo("feature1"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java index 90ac0f3d1a4..3e858e61915 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java @@ -170,7 +170,7 @@ public class IssueChangesEmailTemplateTest { Notification notification = new IssueChangeNotification() .setChangeAuthorLogin("simon") - .setProject("Struts", "org.apache:struts", null, ""); + .setProject("Struts", "org.apache:struts", null); EmailMessage message = underTest.format(notification); assertThat(message.getFrom()).isEqualTo("Simon"); @@ -182,7 +182,7 @@ public class IssueChangesEmailTemplateTest { Notification notification = new IssueChangeNotification() .setChangeAuthorLogin("simon") - .setProject("Struts", "org.apache:struts", null, ""); + .setProject("Struts", "org.apache:struts", null); EmailMessage message = underTest.format(notification); assertThat(message.getFrom()).isEqualTo("simon"); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index 13092a3ba2f..f6ebece6a68 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -224,7 +224,6 @@ public class MyNewIssuesEmailTemplateTest { return new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE) .setFieldValue("projectName", "Struts") .setFieldValue("projectKey", "org.apache:struts") - .setFieldValue("projectUuid", "ABCDE") .setFieldValue("projectDate", "2010-05-18T14:50:45+0000") .setFieldValue("assignee", "lo.gin") .setFieldValue(EFFORT + ".count", "1d3h") diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java index cb5f38c7f7a..6e54f8dbcce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesNotificationDispatcherTest.java @@ -59,11 +59,10 @@ public class MyNewIssuesNotificationDispatcherTest { Multimap recipients = HashMultimap.create(); recipients.put("user1", emailChannel); recipients.put("user2", twitterChannel); - when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); + when(notificationManager.findSubscribedRecipientsForDispatcher(underTest, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); Notification notification = new Notification(MyNewIssuesNotification.MY_NEW_ISSUES_NOTIF_TYPE) .setFieldValue("projectKey", "struts") - .setFieldValue("projectUuid", "uuid1") .setFieldValue("assignee", "user1"); underTest.performDispatch(notification, context); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index 02872c4f408..e429096b273 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -228,7 +228,6 @@ public class NewIssuesEmailTemplateTest { return new Notification(NewIssuesNotification.TYPE) .setFieldValue("projectName", "Struts") .setFieldValue("projectKey", "org.apache:struts") - .setFieldValue("projectUuid", "ABCDE") .setFieldValue("projectDate", "2010-05-18T14:50:45+0000") .setFieldValue(EFFORT + ".count", "1d3h") .setFieldValue(RULE_TYPE + ".count", String.valueOf(count)) diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java index c59fc50191b..153b16774ab 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationDispatcherTest.java @@ -57,11 +57,10 @@ public class NewIssuesNotificationDispatcherTest { Multimap recipients = HashMultimap.create(); recipients.put("user1", emailChannel); recipients.put("user2", twitterChannel); - when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "uuid1", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); + when(notifications.findSubscribedRecipientsForDispatcher(dispatcher, "struts", new NotificationManager.SubscriberPermissionsOnProject(UserRole.USER))).thenReturn(recipients); Notification notification = new Notification(NewIssuesNotification.TYPE) - .setFieldValue("projectKey", "struts") - .setFieldValue("projectUuid", "uuid1"); + .setFieldValue("projectKey", "struts"); dispatcher.performDispatch(notification, context); verify(context).addUser("user1", emailChannel); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java index edcefd30ed2..647a6e73532 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java @@ -83,20 +83,18 @@ public class NewIssuesNotificationTest { @Test public void set_project_without_branch() { - underTest.setProject("project-key", "project-uuid", "project-long-name", null); + underTest.setProject("project-key", "project-long-name", null); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_NAME)).isEqualTo("project-long-name"); - assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_UUID)).isEqualTo("project-uuid"); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_KEY)).isEqualTo("project-key"); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_BRANCH)).isNull(); } @Test public void set_project_with_branch() { - underTest.setProject("project-key", "project-uuid", "project-long-name", "feature"); + underTest.setProject("project-key", "project-long-name", "feature"); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_NAME)).isEqualTo("project-long-name"); - assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_UUID)).isEqualTo("project-uuid"); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_KEY)).isEqualTo("project-key"); assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_BRANCH)).isEqualTo("feature"); }