]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16398 Make tags editable on resolved issues
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 7 Jun 2022 06:37:17 +0000 (08:37 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Jun 2022 20:03:14 +0000 (20:03 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java

index 53648c30a0f84278a91f59d7f7425a5a1375273e..cfaf240fce1edd1705dd04fcc9d4e6fc17b461e8 100644 (file)
@@ -228,11 +228,11 @@ public class SearchResponseLoader {
     }
     RuleType ruleType = RuleType.valueOf(issue.getType());
     availableActions.add(COMMENT_KEY);
+    availableActions.add("set_tags");
     if (issue.getResolution() != null) {
       return availableActions;
     }
     availableActions.add(ASSIGN_KEY);
-    availableActions.add("set_tags");
     if (ruleType != RuleType.SECURITY_HOTSPOT && userSession.hasComponentPermission(ISSUE_ADMIN, project)) {
       availableActions.add(SET_TYPE_KEY);
       availableActions.add(SET_SEVERITY_KEY);
index 0da9576c31f338754c42b1dfb66acbc63a8fbb63..1f3bdad7a8da3b46da95cccd32f38db908e2f6e6 100644 (file)
@@ -88,6 +88,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.groups.Tuple.tuple;
 import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
+import static org.sonar.api.issue.Issue.STATUS_OPEN;
 import static org.sonar.api.issue.Issue.STATUS_RESOLVED;
 import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
 import static org.sonar.api.rules.RuleType.CODE_SMELL;
@@ -100,11 +101,14 @@ import static org.sonar.db.component.ComponentDto.PULL_REQUEST_SEPARATOR;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.issue.IssueTesting.newDto;
 import static org.sonar.db.rule.RuleDescriptionSectionDto.createDefaultRuleDescriptionSection;
+import static org.sonar.server.issue.CommentAction.COMMENT_KEY;
 import static org.sonar.server.tester.UserSessionRule.standalone;
 import static org.sonarqube.ws.Common.RuleType.BUG;
 import static org.sonarqube.ws.Common.RuleType.SECURITY_HOTSPOT_VALUE;
 import static org.sonarqube.ws.Common.RuleType.VULNERABILITY;
 import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_BRANCH;
+import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_ASSIGN;
+import static org.sonarqube.ws.client.issue.IssuesWsParameters.ACTION_SET_TAGS;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ADDITIONAL_FIELDS;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_ASSIGNEES;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_COMPONENT_KEYS;
@@ -114,6 +118,7 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_IN_NEW_CODE
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_PULL_REQUEST;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_RULES;
 import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_PERIOD;
+import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_STATUSES;
 
 public class SearchActionTest {
 
@@ -184,6 +189,44 @@ public class SearchActionTest {
           formatDateTime(issue.getIssueUpdateDate()), false));
   }
 
+  @Test
+  public void response_contains_correct_actions() {
+    UserDto user = db.users().insertUser();
+    userSession.logIn(user);
+    ComponentDto project = db.components().insertPublicProject();
+    ComponentDto file = db.components().insertComponent(newFileDto(project));
+    RuleDto rule = newIssueRule();
+    db.issues().insertIssue(rule, project, file, i -> i.setStatus(STATUS_OPEN));
+    db.issues().insertIssue(rule, project, file, i -> i.setStatus(STATUS_RESOLVED).setResolution(RESOLUTION_FIXED));
+    indexPermissionsAndIssues();
+
+    SearchWsResponse response = ws.newRequest()
+      .setParam(PARAM_ADDITIONAL_FIELDS, "actions")
+      .setParam(PARAM_STATUSES, STATUS_OPEN)
+      .executeProtobuf(SearchWsResponse.class);
+
+    assertThat(
+      response
+        .getIssuesList()
+        .get(0)
+        .getActions()
+        .getActionsList()
+    ).isEqualTo(asList(ACTION_SET_TAGS, COMMENT_KEY, ACTION_ASSIGN));
+
+    response = ws.newRequest()
+      .setParam(PARAM_ADDITIONAL_FIELDS, "actions")
+      .setParam(PARAM_STATUSES, STATUS_RESOLVED)
+      .executeProtobuf(SearchWsResponse.class);
+
+    assertThat(
+      response
+        .getIssuesList()
+        .get(0)
+        .getActions()
+        .getActionsList()
+    ).isEqualTo(asList(ACTION_SET_TAGS, COMMENT_KEY));
+  }
+
   @Test
   public void issue_on_external_rule() {
     ComponentDto project = db.components().insertPublicProject();