diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-04-24 19:31:54 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-04-27 14:25:54 +0200 |
commit | d4eb053812ed5fd74f49face32f094b03a707166 (patch) | |
tree | 736aa3be2684fda62dddfc83fe6c0ff80742d5eb /server/sonar-server/src | |
parent | 0bccca34fd7d3867764ae112f18ad3c3c9f68301 (diff) | |
download | sonarqube-d4eb053812ed5fd74f49face32f094b03a707166.tar.gz sonarqube-d4eb053812ed5fd74f49face32f094b03a707166.zip |
SONAR-9099 add visibility flag to response of api/components/show
Diffstat (limited to 'server/sonar-server/src')
3 files changed, 57 insertions, 2 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java index 4aef9e3f4d0..ef737d714c9 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ShowAction.java @@ -70,7 +70,9 @@ public class ShowAction implements ComponentsWsAction { .setSince("5.4") .setChangelog( new Change("6.4", "Analysis date has been added to the response"), - new Change("6.4", "The field 'id' is deprecated in the response")) + new Change("6.4", "The field 'id' is deprecated in the response"), + new Change("6.4", "The 'visibility' field is added") + ) .setHandler(this); action.createParam(PARAM_COMPONENT_ID) diff --git a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json index 5d21fab0c1a..18030a1004d 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/component/ws/show-example.json @@ -30,7 +30,8 @@ "tags": [ "language", "plugin" - ] + ], + "visibility": "private" } ] } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java index 41294cd3570..4fc68854faf 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java @@ -26,11 +26,14 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.resources.Qualifiers; +import org.sonar.api.server.ws.Change; +import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDbTester; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; import org.sonar.server.component.ComponentFinder; import org.sonar.server.exceptions.ForbiddenException; @@ -42,6 +45,7 @@ import org.sonarqube.ws.WsComponents; import org.sonarqube.ws.WsComponents.ShowWsResponse; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.api.utils.DateUtils.parseDateTime; import static org.sonar.db.component.ComponentTesting.newDirectory; @@ -66,6 +70,35 @@ public class ShowActionTest { private WsActionTester ws = new WsActionTester(new ShowAction(userSession, db.getDbClient(), new ComponentFinder(db.getDbClient()))); @Test + public void verify_definition() throws Exception { + WebService.Action action = ws.getDef(); + + assertThat(action.since()).isEqualTo("5.4"); + assertThat(action.description()).isNotNull(); + assertThat(action.responseExample()).isNotNull(); + assertThat(action.changelog()).extracting(Change::getVersion, Change::getDescription).containsExactlyInAnyOrder( + tuple("6.4", "Analysis date has been added to the response"), + tuple("6.4", "The field 'id' is deprecated in the response"), + tuple("6.4", "The 'visibility' field is added") + ); + + WebService.Param componentId = action.param(PARAM_COMPONENT_ID); + assertThat(componentId.isRequired()).isFalse(); + assertThat(componentId.description()).isNotNull(); + assertThat(componentId.exampleValue()).isNotNull(); + assertThat(componentId.deprecatedSince()).isEqualTo("6.4"); + assertThat(componentId.deprecatedKey()).isEqualTo("id"); + assertThat(componentId.deprecatedKeySince()).isEqualTo("6.4"); + + WebService.Param component = action.param(PARAM_COMPONENT); + assertThat(component.isRequired()).isFalse(); + assertThat(component.description()).isNotNull(); + assertThat(component.exampleValue()).isNotNull(); + assertThat(component.deprecatedKey()).isEqualTo("key"); + assertThat(component.deprecatedKeySince()).isEqualTo("6.4"); + } + + @Test public void json_example() throws IOException { userSession.logIn().setRoot(); insertJsonExampleComponentsAndSnapshots(); @@ -169,6 +202,25 @@ public class ShowActionTest { } @Test + public void return_visibility_field() throws Exception { + userSession.logIn().setRoot(); + ComponentDto privateProject = db.components().insertPrivateProject(); + ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject)); + ComponentDto publicProject = db.components().insertPublicProject(); + + ShowWsResponse result = newRequest(null, privateProject.key()); + assertThat(result.getComponent().hasVisibility()).isTrue(); + assertThat(result.getComponent().getVisibility()).isEqualTo(privateProject.isPrivate() ? "private" : "public"); + + ShowWsResponse result2 = newRequest(null, module.key()); + assertThat(result2.getComponent().hasVisibility()).isFalse(); + + ShowWsResponse result3 = newRequest(null, publicProject.key()); + assertThat(result3.getComponent().hasVisibility()).isTrue(); + assertThat(result3.getComponent().getVisibility()).isEqualTo(publicProject.isPrivate() ? "private" : "public"); + } + + @Test public void throw_ForbiddenException_if_user_doesnt_have_browse_permission_on_project() { userSession.logIn(); |