aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-04-11 09:00:21 +0200
committerGrégoire Aubert <gregaubert@users.noreply.github.com>2017-04-12 16:36:29 +0200
commit7723a97ffcffd6ba32d86b2d169a65a86e165772 (patch)
tree7a1a02fcd0a23f5913ebf9cea7565d7b02052ab3 /server
parentd2e84d6611de4066cfddc69b6d29d9c09993b6b2 (diff)
downloadsonarqube-7723a97ffcffd6ba32d86b2d169a65a86e165772.tar.gz
sonarqube-7723a97ffcffd6ba32d86b2d169a65a86e165772.zip
SONAR-9054 PageDefinition has ORGANIZATION scope
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ui/PageRepository.java13
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ui/PageRepositoryTest.java31
2 files changed, 40 insertions, 4 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/PageRepository.java b/server/sonar-server/src/main/java/org/sonar/server/ui/PageRepository.java
index 516849eb8aa..1adf918d83a 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ui/PageRepository.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ui/PageRepository.java
@@ -34,7 +34,6 @@ import org.sonar.api.web.page.Page.Qualifier;
import org.sonar.api.web.page.Page.Scope;
import org.sonar.api.web.page.PageDefinition;
import org.sonar.core.platform.PluginRepository;
-import org.sonar.core.util.stream.MoreCollectors;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Collections.emptyList;
@@ -42,6 +41,8 @@ import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import static org.sonar.api.web.page.Page.Scope.COMPONENT;
import static org.sonar.api.web.page.Page.Scope.GLOBAL;
+import static org.sonar.api.web.page.Page.Scope.ORGANIZATION;
+import static org.sonar.core.util.stream.MoreCollectors.toList;
@ServerSide
public class PageRepository implements Startable {
@@ -78,7 +79,7 @@ public class PageRepository implements Startable {
.peek(checkWellFormed())
.peek(checkPluginExists())
.sorted(comparing(Page::getKey))
- .collect(MoreCollectors.toList());
+ .collect(toList());
}
@Override
@@ -90,6 +91,10 @@ public class PageRepository implements Startable {
return getPages(GLOBAL, isAdmin, null);
}
+ public List<Page> getOrganizationPages(boolean isAdmin) {
+ return getPages(ORGANIZATION, isAdmin, null);
+ }
+
public List<Page> getComponentPages(boolean isAdmin, String qualifierKey) {
Qualifier qualifier = Qualifier.fromKey(qualifierKey);
return qualifier == null ? emptyList() : getPages(COMPONENT, isAdmin, qualifier);
@@ -99,8 +104,8 @@ public class PageRepository implements Startable {
return getAllPages().stream()
.filter(p -> p.getScope().equals(scope))
.filter(p -> p.isAdmin() == isAdmin)
- .filter(p -> GLOBAL.equals(p.getScope()) || p.getComponentQualifiers().contains(qualifier))
- .collect(MoreCollectors.toList());
+ .filter(p -> !COMPONENT.equals(p.getScope()) || p.getComponentQualifiers().contains(qualifier))
+ .collect(toList());
}
@VisibleForTesting
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/PageRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/PageRepositoryTest.java
index 1060bb1d0ea..cde31b07f52 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ui/PageRepositoryTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ui/PageRepositoryTest.java
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.api.web.page.Page.Scope.COMPONENT;
import static org.sonar.api.web.page.Page.Scope.GLOBAL;
+import static org.sonar.api.web.page.Page.Scope.ORGANIZATION;
public class PageRepositoryTest {
@@ -114,6 +115,36 @@ public class PageRepositoryTest {
}
@Test
+ public void get_organization_pages() {
+ PageDefinition plugin = context -> context
+ .addPage(Page.builder("my_plugin/G1").setName("G1").setScope(GLOBAL).build())
+ .addPage(Page.builder("my_plugin/C1").setName("C1").setScope(COMPONENT).build())
+ .addPage(Page.builder("my_plugin/O1").setName("O1").setScope(ORGANIZATION).build())
+ .addPage(Page.builder("my_plugin/O2").setName("O2").setScope(ORGANIZATION).build())
+ .addPage(Page.builder("my_plugin/O3").setName("O3").setScope(ORGANIZATION).build())
+ .addPage(Page.builder("my_plugin/OA1").setName("OA1").setScope(ORGANIZATION).setAdmin(true).build());
+ underTest = new PageRepository(pluginRepository, new PageDefinition[] {plugin});
+ underTest.start();
+
+ List<Page> result = underTest.getOrganizationPages(false);
+
+ assertThat(result).extracting(Page::getKey).containsExactly("my_plugin/O1", "my_plugin/O2", "my_plugin/O3");
+ }
+
+ @Test
+ public void get_organization_admin_pages() {
+ PageDefinition plugin = context -> context
+ .addPage(Page.builder("my_plugin/O1").setName("O1").setScope(ORGANIZATION).build())
+ .addPage(Page.builder("my_plugin/O2").setName("O2").setScope(ORGANIZATION).setAdmin(true).build());
+ underTest = new PageRepository(pluginRepository, new PageDefinition[] {plugin});
+ underTest.start();
+
+ List<Page> result = underTest.getOrganizationPages(true);
+
+ assertThat(result).extracting(Page::getKey).containsExactly("my_plugin/O2");
+ }
+
+ @Test
public void fail_if_pages_called_before_server_startup() {
expectedException.expect(NullPointerException.class);
expectedException.expectMessage("Pages haven't been initialized yet");