From: Julien HENRY Date: Mon, 13 May 2019 12:23:23 +0000 (+0200) Subject: SONAR-11989 Send notification when doing manual operations on Security Hotspots X-Git-Tag: 7.8~199 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3775e29dbe727665644e7f0f4312cacb80518b38;p=sonarqube.git SONAR-11989 Send notification when doing manual operations on Security Hotspots --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java index 5f88b73eab8..5423d2b7ddd 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java @@ -24,7 +24,6 @@ import java.util.Optional; import javax.annotation.Nullable; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; -import org.sonar.api.rules.RuleType; import org.sonar.core.issue.DefaultIssue; import org.sonar.core.issue.IssueChangeContext; import org.sonar.core.util.stream.MoreCollectors; @@ -93,9 +92,9 @@ public class IssueUpdater { private IssueDto doSaveIssue(DbSession session, DefaultIssue issue, IssueChangeContext context, Optional rule, ComponentDto project, BranchDto branchDto) { IssueDto issueDto = issueStorage.save(session, singletonList(issue)).iterator().next(); - if (issue.type() == RuleType.SECURITY_HOTSPOT + if ( // since this method is called after an update of the issue, date should never be null - || issue.updateDate() == null + issue.updateDate() == null // name of rule is displayed in notification, rule must therefor be present || !rule.isPresent() // notification are not supported on PRs and short lived branches 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 1a86962ef86..d48efd5e36c 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 @@ -54,9 +54,7 @@ import org.sonar.server.rule.DefaultRuleFinder; import static org.apache.commons.lang.math.RandomUtils.nextInt; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; @@ -172,26 +170,6 @@ public class IssueUpdaterTest { assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor))); } - @Test - public void verify_no_notification_on_hotspot() { - UserDto assignee = db.users().insertUser(); - RuleDto rule = db.rules().insertRule(); - ComponentDto project = db.components().insertMainBranch(); - ComponentDto file = db.components().insertComponent(newFileDto(project)); - DefaultIssue issue = db.issues().insertIssue(IssueTesting.newIssue(rule.getDefinition(), project, file) - .setType(RuleType.SECURITY_HOTSPOT)) - .setSeverity(MAJOR) - .setAssigneeUuid(assignee.getUuid()) - .toDefaultIssue(); - UserDto changeAuthor = db.users().insertUser(); - IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid()); - issueFieldsSetter.setSeverity(issue, BLOCKER, context); - - underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false); - - verify(notificationManager, never()).scheduleForSending(any()); - } - @Test public void verify_notification_on_long_branch() { RuleDto rule = db.rules().insertRule(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java index b0b867ae0eb..412b3311037 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/AssignActionTest.java @@ -56,9 +56,7 @@ import static org.junit.rules.ExpectedException.none; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; import static org.sonar.api.rules.RuleType.CODE_SMELL; -import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; import static org.sonar.api.web.UserRole.CODEVIEWER; import static org.sonar.api.web.UserRole.USER; import static org.sonar.server.tester.UserSessionRule.standalone; @@ -192,23 +190,6 @@ public class AssignActionTest { verify(notificationManager).scheduleForSending(any(IssuesChangesNotification.class)); } - @Test - public void do_not_send_notification_on_security_hotspot() { - IssueDto issue = db.issues().insertIssue( - issueDto -> issueDto - .setAssigneeUuid(null) - .setType(SECURITY_HOTSPOT)); - setUserWithBrowsePermission(issue); - UserDto arthur = insertUser("arthur"); - - ws.newRequest() - .setParam("issue", issue.getKey()) - .setParam("assignee", arthur.getLogin()) - .execute(); - - verifyZeroInteractions(notificationManager); - } - @Test public void fail_when_assignee_does_not_exist() { IssueDto issue = newIssueWithBrowsePermission();