aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-04-27 17:03:32 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-04-28 16:20:03 +0200
commitce8280033755911dad0766d342d36f442789ed26 (patch)
tree7a2f95027d0d9d7c5421821d00d19bbf09ccb7a2 /server/sonar-server
parentc938464d1eedf63277e5dcc96d0a22519911bf1b (diff)
downloadsonarqube-ce8280033755911dad0766d342d36f442789ed26.tar.gz
sonarqube-ce8280033755911dad0766d342d36f442789ed26.zip
SONAR-9099 return visibility field also for views in api/components/show
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java38
2 files changed, 38 insertions, 10 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
index 5c2c0c8d563..22961ca2385 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
@@ -19,8 +19,10 @@
*/
package org.sonar.server.component.ws;
+import com.google.common.collect.ImmutableSet;
import java.util.Objects;
import java.util.Optional;
+import java.util.Set;
import org.sonar.api.resources.Qualifiers;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
@@ -34,6 +36,12 @@ import static org.sonar.api.utils.DateUtils.formatDateTime;
import static org.sonar.core.util.Protobuf.setNullable;
class ComponentDtoToWsComponent {
+
+ /**
+ * The concept of "visibility" will only be configured for these qualifiers.
+ */
+ private static final Set<String> QUALIFIERS_WITH_VISIBILITY = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW);
+
private ComponentDtoToWsComponent() {
// prevent instantiation
}
@@ -58,7 +66,7 @@ class ComponentDtoToWsComponent {
setNullable(emptyToNull(dto.language()), wsComponent::setLanguage);
setTags(dto, wsComponent);
lastAnalysis.ifPresent(analysis -> wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt())));
- if (Qualifiers.PROJECT.equals(dto.qualifier())) {
+ if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) {
wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate()));
}
return wsComponent;
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 4fc68854faf..8a174072af9 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
@@ -202,22 +202,42 @@ public class ShowActionTest {
}
@Test
- public void return_visibility_field() throws Exception {
+ public void should_return_visibility_for_private_project() 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");
+ assertThat(result.getComponent().getVisibility()).isEqualTo("private");
+ }
+
+ @Test
+ public void should_return_visibility_for_public_project() throws Exception {
+ userSession.logIn().setRoot();
+ ComponentDto publicProject = db.components().insertPublicProject();
+
+ ShowWsResponse result = newRequest(null, publicProject.key());
+ assertThat(result.getComponent().hasVisibility()).isTrue();
+ assertThat(result.getComponent().getVisibility()).isEqualTo("public");
+ }
+
+ @Test
+ public void should_return_visibility_for_view() throws Exception {
+ userSession.logIn().setRoot();
+ ComponentDto view = db.components().insertView();
+
+ ShowWsResponse result = newRequest(null, view.key());
+ assertThat(result.getComponent().hasVisibility()).isTrue();
+ }
- ShowWsResponse result2 = newRequest(null, module.key());
- assertThat(result2.getComponent().hasVisibility()).isFalse();
+ @Test
+ public void should_not_return_visibility_for_module() throws Exception {
+ userSession.logIn().setRoot();
+ ComponentDto privateProject = db.components().insertPrivateProject();
+ ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject));
- ShowWsResponse result3 = newRequest(null, publicProject.key());
- assertThat(result3.getComponent().hasVisibility()).isTrue();
- assertThat(result3.getComponent().getVisibility()).isEqualTo(publicProject.isPrivate() ? "private" : "public");
+ ShowWsResponse result = newRequest(null, module.key());
+ assertThat(result.getComponent().hasVisibility()).isFalse();
}
@Test