From 0f36fac2f8ab63502cc77f5105386d68052dcc11 Mon Sep 17 00:00:00 2001 From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Thu, 17 Nov 2022 11:46:12 +0100 Subject: [PATCH] SONAR-14829 Allow bulk adding tags on resolved issue. --- .../issue/AbstractChangeTagsAction.java | 2 -- .../java/org/sonar/server/issue/Action.java | 2 +- .../server/issue/ws/BulkChangeAction.java | 6 ++--- .../server/issue/ws/BulkChangeActionTest.java | 25 +++++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java index c9167ea94a6..688f94de451 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/AbstractChangeTagsAction.java @@ -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 diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java index dcddc12f6eb..facbc5df39b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/Action.java @@ -43,7 +43,7 @@ public abstract class Action { private final String key; private final List 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(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java index cbed2d2a575..15dda208337 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/BulkChangeAction.java @@ -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() diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java index f4ff321ce5b..7fbbb1ec1fc 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/BulkChangeActionTest.java @@ -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(); -- 2.39.5