aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-05-11 16:14:09 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-05-12 12:37:19 +0200
commit8b20d9b681313b7b6b9bf0071e9169995d434912 (patch)
tree0cbae8cc026e842ee28b8c12265bc5803f97f60c
parentb451f859c4fc8e0a694c18e175ddc931e1702cd9 (diff)
downloadsonarqube-8b20d9b681313b7b6b9bf0071e9169995d434912.tar.gz
sonarqube-8b20d9b681313b7b6b9bf0071e9169995d434912.zip
SONAR-9194 Add canAdmin flag to WS api/navigation/global
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java10
-rw-r--r--server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json3
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java12
3 files changed, 21 insertions, 4 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
index a5a9bc5a71b..ac787e96528 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/GlobalAction.java
@@ -36,6 +36,7 @@ import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.OrganizationFlags;
import org.sonar.server.ui.PageRepository;
import org.sonar.server.ui.VersionFormatter;
+import org.sonar.server.user.UserSession;
import static org.sonar.api.CoreProperties.RATING_GRID;
import static org.sonar.core.config.WebConstants.SONARQUBE_DOT_COM_ENABLED;
@@ -63,9 +64,10 @@ public class GlobalAction implements NavigationWsAction {
private final DbClient dbClient;
private final OrganizationFlags organizationFlags;
private final DefaultOrganizationProvider defaultOrganizationProvider;
+ private final UserSession userSession;
public GlobalAction(PageRepository pageRepository, Settings settings, ResourceTypes resourceTypes, Server server,
- DbClient dbClient, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider) {
+ DbClient dbClient, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider, UserSession userSession) {
this.pageRepository = pageRepository;
this.settings = settings;
this.resourceTypes = resourceTypes;
@@ -73,6 +75,7 @@ public class GlobalAction implements NavigationWsAction {
this.dbClient = dbClient;
this.organizationFlags = organizationFlags;
this.defaultOrganizationProvider = defaultOrganizationProvider;
+ this.userSession = userSession;
}
@Override
@@ -88,6 +91,7 @@ public class GlobalAction implements NavigationWsAction {
@Override
public void handle(Request request, Response response) throws Exception {
JsonWriter json = response.newJsonWriter().beginObject();
+ writeActions(json);
writePages(json);
writeSettings(json);
writeDeprecatedLogoProperties(json);
@@ -98,6 +102,10 @@ public class GlobalAction implements NavigationWsAction {
json.endObject().close();
}
+ private void writeActions(JsonWriter json) {
+ json.prop("canAdmin", userSession.isSystemAdministrator());
+ }
+
private void writePages(JsonWriter json) {
json.name("globalPages").beginArray();
for (org.sonar.api.web.page.Page page : pageRepository.getGlobalPages(false)) {
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json
index 6af08ab2f98..cddaab6ff31 100644
--- a/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json
+++ b/server/sonar-server/src/main/resources/org/sonar/server/ui/ws/global-example.json
@@ -26,5 +26,6 @@
"version": "6.2",
"productionDatabase": true,
"organizationsEnabled": false,
- "defaultOrganization": "key_foo"
+ "defaultOrganization": "key_foo",
+ "canAdmin": false
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
index 1a651fec00c..85e45dab932 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java
@@ -50,7 +50,7 @@ import static org.sonar.test.JsonAssert.assertJson;
public class GlobalActionTest {
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone();
+ public UserSessionRule userSession = UserSessionRule.standalone();
private Settings settings = new MapSettings();
@@ -163,6 +163,14 @@ public class GlobalActionTest {
}
@Test
+ public void can_admin_on_global_level() {
+ init();
+ userSession.logIn().setRoot();
+
+ assertJson(call()).isSimilarTo("{\"canAdmin\":true}");
+ }
+
+ @Test
public void test_example_response() throws Exception {
init(createPages(), new ResourceTypeTree[] {
ResourceTypeTree.builder()
@@ -205,7 +213,7 @@ public class GlobalActionTest {
}});
pageRepository.start();
ws = new WsActionTester(new GlobalAction(pageRepository, settings, new ResourceTypes(resourceTypeTrees), server,
- dbClient, organizationFlags, defaultOrganizationProvider));
+ dbClient, organizationFlags, defaultOrganizationProvider, userSession));
}
private void executeAndVerify(String json) {