]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14829 Allow bulk adding tags on resolved issue.
authorWojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com>
Thu, 17 Nov 2022 10:46:12 +0000 (11:46 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 18 Nov 2022 20:02:49 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java

index c9167ea94a63860a9d2735dc59ad369a01f31505..688f94de451e43be2d061ad77764d11b7cc2d536 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import org.sonar.server.issue.workflow.IsUnResolved;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.server.rule.RuleTagFormat;
 import org.sonar.core.issue.DefaultIssue;
@@ -43,7 +42,6 @@ public abstract class AbstractChangeTagsAction extends Action {
   protected AbstractChangeTagsAction(String key, IssueFieldsSetter issueUpdater) {
     super(key);
     this.issueUpdater = issueUpdater;
-    super.setConditions(new IsUnResolved());
   }
 
   @Override
index dcddc12f6ebe06d8f43dc02b92e2e3b9f152c0b4..facbc5df39bd6220ece4ac295ecaf4880edd58c4 100644 (file)
@@ -43,7 +43,7 @@ public abstract class Action {
   private final String key;
   private final List<Condition> conditions;
 
-  public Action(String key) {
+  protected Action(String key) {
     Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Action key must be set");
     this.key = key;
     this.conditions = newArrayList();
index cbed2d2a575e2a0eb3c55536b6d4e717727c0365..15dda208337498406b716112df83f183a5d23450 100644 (file)
@@ -76,8 +76,8 @@ import org.sonarqube.ws.Issues;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.ImmutableMap.of;
 import static java.lang.String.format;
+import static java.util.Map.of;
 import static java.util.Objects.requireNonNull;
 import static java.util.function.Function.identity;
 import static java.util.stream.Collectors.toMap;
@@ -393,9 +393,9 @@ public class BulkChangeAction implements IssuesWsAction {
       this.issues = getAuthorizedIssues(allIssues);
       this.componentsByUuid = getComponents(dbSession,
         issues.stream().map(DefaultIssue::componentUuid).collect(MoreCollectors.toSet())).stream()
-        .collect(uniqueIndex(ComponentDto::uuid, identity()));
+          .collect(uniqueIndex(ComponentDto::uuid, identity()));
       this.rulesByKey = dbClient.ruleDao().selectByKeys(dbSession,
-          issues.stream().map(DefaultIssue::ruleKey).collect(MoreCollectors.toSet())).stream()
+        issues.stream().map(DefaultIssue::ruleKey).collect(MoreCollectors.toSet())).stream()
         .collect(uniqueIndex(RuleDto::getKey, identity()));
 
       this.availableActions = actions.stream()
index f4ff321ce5b404c09d2f74f7c715d0e1ac9ff7ff..7fbbb1ec1fcfd4d1e209740afc76d191255041b1 100644 (file)
@@ -81,10 +81,12 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoInteractions;
 import static org.sonar.api.issue.DefaultTransitions.RESOLVE_AS_REVIEWED;
+import static org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE;
 import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
 import static org.sonar.api.issue.Issue.STATUS_CLOSED;
 import static org.sonar.api.issue.Issue.STATUS_CONFIRMED;
 import static org.sonar.api.issue.Issue.STATUS_OPEN;
+import static org.sonar.api.issue.Issue.STATUS_RESOLVED;
 import static org.sonar.api.rule.Severity.MAJOR;
 import static org.sonar.api.rule.Severity.MINOR;
 import static org.sonar.api.rules.RuleType.BUG;
@@ -212,6 +214,29 @@ public class BulkChangeActionTest {
     verifyNoInteractions(issueChangeEventService);
   }
 
+  @Test
+  public void add_tags_when_issue_is_resolved_is_accepted() {
+    UserDto user = db.users().insertUser();
+    userSession.logIn(user);
+    ComponentDto project = db.components().insertPrivateProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    addUserProjectPermissions(user, project, USER, ISSUE_ADMIN);
+    RuleDto rule = db.rules().insertIssueRule();
+    IssueDto issue = db.issues().insertIssue(rule, project, file, i -> i.setTags(asList("tag1", "tag2"))
+      .setStatus(STATUS_RESOLVED).setResolution(RESOLUTION_FALSE_POSITIVE));
+
+    BulkChangeWsResponse response = call(builder()
+      .setIssues(singletonList(issue.getKey()))
+      .setAddTags(singletonList("tag3"))
+      .build());
+
+    checkResponse(response, 1, 1, 0, 0);
+    IssueDto reloaded = getIssueByKeys(issue.getKey()).get(0);
+    assertThat(reloaded.getTags()).containsOnly("tag1", "tag2", "tag3");
+    assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW);
+    assertThat(reloaded.getResolution()).isEqualTo("FALSE-POSITIVE");
+  }
+
   @Test
   public void remove_assignee() {
     UserDto user = db.users().insertUser();