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;
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;
this.dbClient = dbClient;
this.organizationFlags = organizationFlags;
this.defaultOrganizationProvider = defaultOrganizationProvider;
+ this.userSession = userSession;
}
@Override
@Override
public void handle(Request request, Response response) throws Exception {
JsonWriter json = response.newJsonWriter().beginObject();
+ writeActions(json);
writePages(json);
writeSettings(json);
writeDeprecatedLogoProperties(json);
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)) {
public class GlobalActionTest {
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone();
+ public UserSessionRule userSession = UserSessionRule.standalone();
private Settings settings = new MapSettings();
executeAndVerify("organization_support.json");
}
+ @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[] {
}});
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) {