diff options
6 files changed, 44 insertions, 8 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 1e2a84d57c0..a5a9bc5a71b 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 @@ -32,6 +32,7 @@ import org.sonar.api.utils.text.JsonWriter; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.dialect.H2; +import org.sonar.server.organization.DefaultOrganizationProvider; import org.sonar.server.organization.OrganizationFlags; import org.sonar.server.ui.PageRepository; import org.sonar.server.ui.VersionFormatter; @@ -61,15 +62,17 @@ public class GlobalAction implements NavigationWsAction { private final Server server; private final DbClient dbClient; private final OrganizationFlags organizationFlags; + private final DefaultOrganizationProvider defaultOrganizationProvider; public GlobalAction(PageRepository pageRepository, Settings settings, ResourceTypes resourceTypes, Server server, - DbClient dbClient, OrganizationFlags organizationFlags) { + DbClient dbClient, OrganizationFlags organizationFlags, DefaultOrganizationProvider defaultOrganizationProvider) { this.pageRepository = pageRepository; this.settings = settings; this.resourceTypes = resourceTypes; this.server = server; this.dbClient = dbClient; this.organizationFlags = organizationFlags; + this.defaultOrganizationProvider = defaultOrganizationProvider; } @Override @@ -139,6 +142,7 @@ public class GlobalAction implements NavigationWsAction { private void writeOrganizationSupport(JsonWriter json) { try (DbSession dbSession = dbClient.openSession(false)) { json.prop("organizationsEnabled", organizationFlags.isEnabled(dbSession)); + json.prop("defaultOrganization", defaultOrganizationProvider.get().getKey()); } } } 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 d339df3d19f..6af08ab2f98 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 @@ -25,5 +25,6 @@ ], "version": "6.2", "productionDatabase": true, - "organizationsEnabled": false + "organizationsEnabled": false, + "defaultOrganization": "key_foo" } 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 179ff4b1ce1..1a651fec00c 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 @@ -33,6 +33,8 @@ import org.sonar.core.platform.PluginRepository; import org.sonar.db.DbClient; import org.sonar.db.dialect.H2; import org.sonar.db.dialect.MySql; +import org.sonar.server.organization.DefaultOrganizationProvider; +import org.sonar.server.organization.TestDefaultOrganizationProvider; import org.sonar.server.organization.TestOrganizationFlags; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ui.PageRepository; @@ -57,6 +59,7 @@ public class GlobalActionTest { private WsActionTester ws; private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone(); + private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.fromUuid("foo"); @Test public void empty_call() throws Exception { @@ -152,7 +155,7 @@ public class GlobalActionTest { } @Test - public void organization_support_is_enabled() throws Exception { + public void organization_support() throws Exception { init(); organizationFlags.setEnabled(true); @@ -201,7 +204,8 @@ public class GlobalActionTest { } }}); pageRepository.start(); - ws = new WsActionTester(new GlobalAction(pageRepository, settings, new ResourceTypes(resourceTypeTrees), server, dbClient, organizationFlags)); + ws = new WsActionTester(new GlobalAction(pageRepository, settings, new ResourceTypes(resourceTypeTrees), server, + dbClient, organizationFlags, defaultOrganizationProvider)); } private void executeAndVerify(String json) { diff --git a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalActionTest/organization_support.json b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalActionTest/organization_support.json index 58c7c3350a2..b2778b221da 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalActionTest/organization_support.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/ui/ws/GlobalActionTest/organization_support.json @@ -1,3 +1,4 @@ { - "organizationsEnabled": true + "organizationsEnabled": true, + "defaultOrganization": "key_foo" } diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js index 90249a0e7e2..1c7f395f741 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js @@ -150,7 +150,7 @@ export default class GlobalNavMenu extends React.Component { {this.renderProjects()} {governanceInstalled && this.renderPortfolios()} {this.renderIssuesLink()} - {this.renderRulesLink()} + {!organizationsEnabled && this.renderRulesLink()} {!organizationsEnabled && this.renderProfilesLink()} {this.renderQualityGatesLink()} {this.renderAdministrationLink()} diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/CodingRulesAppContainer.js b/server/sonar-web/src/main/js/apps/coding-rules/components/CodingRulesAppContainer.js index c7bb6c70ed3..de34c58dd33 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/CodingRulesAppContainer.js +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/CodingRulesAppContainer.js @@ -19,18 +19,38 @@ */ // @flow import React from 'react'; +import { connect } from 'react-redux'; +import { withRouter } from 'react-router'; +import { getAppState } from '../../../store/rootReducer'; import init from '../init'; -export default class CodingRulesAppContainer extends React.PureComponent { +class CodingRulesAppContainer extends React.PureComponent { stop: ?() => void; props: { + appState: { + defaultOrganization: string, + organizationsEnabled: boolean + }, params: { organizationKey?: string + }, + router: { + replace: (string) => void } }; componentDidMount() { - this.stop = init(this.refs.container, this.props.params.organizationKey); + if (this.props.appState.organizationsEnabled && !this.props.params.organizationKey) { + // redirect to organization-level rules page + this.props.router.replace( + '/organizations/' + + this.props.appState.defaultOrganization + + '/rules' + + window.location.hash + ); + } else { + this.stop = init(this.refs.container, this.props.params.organizationKey); + } } componentWillUnmount() { @@ -51,3 +71,9 @@ export default class CodingRulesAppContainer extends React.PureComponent { ); } } + +const mapStateToProps = state => ({ + appState: getAppState(state) +}); + +export default connect(mapStateToProps)(withRouter(CodingRulesAppContainer)); |