From f5764b41dffa181327a098dccbf56773a76411f2 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 6 Feb 2017 10:55:12 +0100 Subject: [PATCH] display 404 when accessing on-prem admin pages being in cloud mode --- .../src/main/js/app/utils/startReactApp.js | 1 + .../src/main/js/apps/groups/routes.js | 3 +- .../organizations/forSingleOrganization.js | 49 +++++++++++++++++++ .../js/apps/permission-templates/routes.js | 3 +- .../src/main/js/apps/permissions/routes.js | 3 +- .../src/main/js/apps/projects-admin/routes.js | 5 +- 6 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/organizations/forSingleOrganization.js diff --git a/server/sonar-web/src/main/js/app/utils/startReactApp.js b/server/sonar-web/src/main/js/app/utils/startReactApp.js index e28587b9184..32c8cb9a0fb 100644 --- a/server/sonar-web/src/main/js/app/utils/startReactApp.js +++ b/server/sonar-web/src/main/js/app/utils/startReactApp.js @@ -160,6 +160,7 @@ const startReactApp = () => { + diff --git a/server/sonar-web/src/main/js/apps/groups/routes.js b/server/sonar-web/src/main/js/apps/groups/routes.js index 08981267c79..f221791c856 100644 --- a/server/sonar-web/src/main/js/apps/groups/routes.js +++ b/server/sonar-web/src/main/js/apps/groups/routes.js @@ -20,7 +20,8 @@ import React from 'react'; import { IndexRoute } from 'react-router'; import GroupsAppContainer from './components/GroupsAppContainer'; +import forSingleOrganization from '../organizations/forSingleOrganization'; export default ( - + ); diff --git a/server/sonar-web/src/main/js/apps/organizations/forSingleOrganization.js b/server/sonar-web/src/main/js/apps/organizations/forSingleOrganization.js new file mode 100644 index 00000000000..2a2474219b1 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/forSingleOrganization.js @@ -0,0 +1,49 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +// @flow +import React from 'react'; +import { connect } from 'react-redux'; +import { withRouter } from 'react-router'; +import { areThereCustomOrganizations } from '../../store/rootReducer'; + +const forSingleOrganization = (ComposedComponent: Object) => { + class X extends React.Component { + static displayName = `forSingleOrganization(${ComposedComponent.displayName})}`; + + render () { + const { customOrganizations, router, ...other } = this.props; + + if (customOrganizations) { + router.replace('/not_found'); + return null; + } + + return ; + } + } + + const mapStateToProps = state => ({ + customOrganizations: areThereCustomOrganizations(state) + }); + + return connect(mapStateToProps)(withRouter(X)); +}; + +export default forSingleOrganization; diff --git a/server/sonar-web/src/main/js/apps/permission-templates/routes.js b/server/sonar-web/src/main/js/apps/permission-templates/routes.js index 799d82546f9..3060d3331f0 100644 --- a/server/sonar-web/src/main/js/apps/permission-templates/routes.js +++ b/server/sonar-web/src/main/js/apps/permission-templates/routes.js @@ -20,7 +20,8 @@ import React from 'react'; import { IndexRoute } from 'react-router'; import AppContainer from './components/AppContainer'; +import forSingleOrganization from '../organizations/forSingleOrganization'; export default ( - + ); diff --git a/server/sonar-web/src/main/js/apps/permissions/routes.js b/server/sonar-web/src/main/js/apps/permissions/routes.js index a273a2914b6..ee80d1143a0 100644 --- a/server/sonar-web/src/main/js/apps/permissions/routes.js +++ b/server/sonar-web/src/main/js/apps/permissions/routes.js @@ -21,9 +21,10 @@ import React from 'react'; import { IndexRoute } from 'react-router'; import GlobalPermissionsApp from './global/components/App'; import ProjectPermissionsApp from './project/components/App'; +import forSingleOrganization from '../organizations/forSingleOrganization'; export const globalPermissionsRoutes = ( - + ); export const projectPermissionsRoutes = ( diff --git a/server/sonar-web/src/main/js/apps/projects-admin/routes.js b/server/sonar-web/src/main/js/apps/projects-admin/routes.js index 5b25254fb7f..f8442f2c572 100644 --- a/server/sonar-web/src/main/js/apps/projects-admin/routes.js +++ b/server/sonar-web/src/main/js/apps/projects-admin/routes.js @@ -20,7 +20,8 @@ import React from 'react'; import { IndexRoute } from 'react-router'; import AppContainer from './AppContainer'; +import forSingleOrganization from '../organizations/forSingleOrganization'; -export default( - +export default ( + ); -- 2.39.5