From cb8b5693d2b7c64f6ef69fc50040b9e2f81cdb33 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 7 Jun 2022 08:37:17 +0200 Subject: [PATCH] SONAR-16398 Make tags editable on resolved issues --- .../server/issue/ws/SearchResponseLoader.java | 2 +- .../server/issue/ws/SearchActionTest.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java index 53648c30a0f..cfaf240fce1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java @@ -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); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java index 0da9576c31f..1f3bdad7a8d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java @@ -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(); -- 2.39.5