From: Grégoire Aubert Date: Thu, 30 Nov 2017 10:25:53 +0000 (+0100) Subject: Rewrite usage of Organization containers X-Git-Tag: 7.0-RC1~153 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=42b5ea685c8ee46cf05625879300aa3eb3529897;p=sonarqube.git Rewrite usage of Organization containers --- diff --git a/server/sonar-web/src/main/js/api/users.ts b/server/sonar-web/src/main/js/api/users.ts index d04b71bcd55..fa1b73f80fa 100644 --- a/server/sonar-web/src/main/js/api/users.ts +++ b/server/sonar-web/src/main/js/api/users.ts @@ -19,7 +19,7 @@ */ import { getJSON, post, postJSON, RequestData } from '../helpers/request'; import throwGlobalError from '../app/utils/throwGlobalError'; -import { Paging } from '../app/types'; +import { CurrentUser, Paging } from '../app/types'; export interface IdentityProvider { backgroundColor: string; @@ -42,7 +42,7 @@ export interface User { avatar?: string; } -export function getCurrentUser(): Promise { +export function getCurrentUser(): Promise { return getJSON('/api/users/current'); } diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.tsx b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.tsx index 1ffec34be8f..90cf0393293 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.tsx @@ -20,12 +20,13 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import GlobalNavUser from '../GlobalNavUser'; +import { Visibility } from '../../../../types'; const currentUser = { avatar: 'abcd1234', isLoggedIn: true, name: 'foo', email: 'foo@bar.baz' }; const organizations = [ - { key: 'myorg', name: 'MyOrg', projectVisibility: 'public' }, - { key: 'foo', name: 'Foo', projectVisibility: 'public' }, - { key: 'bar', name: 'bar', projectVisibility: 'public' } + { key: 'myorg', name: 'MyOrg', projectVisibility: Visibility.Public }, + { key: 'foo', name: 'Foo', projectVisibility: Visibility.Public }, + { key: 'bar', name: 'bar', projectVisibility: Visibility.Public } ]; const appState = { organizationsEnabled: true }; diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdmin.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdmin.js deleted file mode 100644 index d11ba3c3d5b..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdmin.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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 { getOrganizationByKey } from '../../../store/rootReducer'; -import handleRequiredAuthorization from '../../../app/utils/handleRequiredAuthorization'; - -export class OrganizationAdmin extends React.PureComponent { - /*:: props: { - children?: React.Element<*>, - organization: { canAdmin: boolean } - }; - */ - - componentDidMount() { - this.checkPermissions(); - } - - componentDidUpdate() { - this.checkPermissions(); - } - - isOrganizationAdmin() { - return this.props.organization.canAdmin; - } - - checkPermissions() { - if (!this.isOrganizationAdmin()) { - handleRequiredAuthorization(); - } - } - - render() { - if (!this.isOrganizationAdmin()) { - return null; - } - - return this.props.children; - } -} - -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -export default connect(mapStateToProps)(OrganizationAdmin); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdminContainer.tsx b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdminContainer.tsx new file mode 100644 index 00000000000..393c1768dc1 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdminContainer.tsx @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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. + */ +import * as React from 'react'; +import { connect } from 'react-redux'; +import { RouterState } from 'react-router'; +import { getOrganizationByKey } from '../../../store/rootReducer'; +import handleRequiredAuthorization from '../../../app/utils/handleRequiredAuthorization'; +import { Organization } from '../../../app/types'; + +interface StateToProps { + organization?: Organization; +} + +interface OwnProps extends RouterState { + children: JSX.Element; +} + +interface Props extends StateToProps, Pick {} + +export class OrganizationAdmin extends React.PureComponent { + componentDidMount() { + this.checkPermissions(); + } + + componentDidUpdate() { + this.checkPermissions(); + } + + isOrganizationAdmin = () => this.props.organization && this.props.organization.canAdmin; + + checkPermissions = () => { + if (!this.isOrganizationAdmin()) { + handleRequiredAuthorization(); + } + }; + + render() { + if (!this.isOrganizationAdmin()) { + return null; + } + return React.cloneElement(this.props.children, { + location: this.props.location, + organization: this.props.organization + }); + } +} + +const mapStateToProps = (state: any, ownProps: OwnProps) => ({ + organization: getOrganizationByKey(state, ownProps.params.organizationKey) +}); + +export default connect(mapStateToProps)(OrganizationAdmin); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.js deleted file mode 100644 index a48cf7f5cd6..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.js +++ /dev/null @@ -1,39 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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 { getCurrentUser, getOrganizationByKey } from '../../../store/rootReducer'; - -class OrganizationContainer extends React.PureComponent { - render() { - return React.cloneElement(this.props.children, { - currentUser: this.props.currentUser, - organization: this.props.organization - }); - } -} - -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey), - currentUser: getCurrentUser(state) -}); - -export default connect(mapStateToProps)(OrganizationContainer); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.tsx b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.tsx new file mode 100644 index 00000000000..01b44ca1feb --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.tsx @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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. + */ +import * as React from 'react'; +import { connect } from 'react-redux'; +import { RouterState } from 'react-router'; +import { getCurrentUser, getOrganizationByKey } from '../../../store/rootReducer'; +import { Organization, CurrentUser } from '../../../app/types'; + +interface StateToProps { + organization?: Organization; + currentUser: CurrentUser; +} + +interface OwnProps extends RouterState { + children: JSX.Element; +} + +interface Props extends StateToProps, Pick {} + +class OrganizationContainer extends React.PureComponent { + render() { + return React.cloneElement(this.props.children, { + location: this.props.location, + currentUser: this.props.currentUser, + organization: this.props.organization + }); + } +} + +const mapStateToProps = (state: any, ownProps: OwnProps) => ({ + organization: getOrganizationByKey(state, ownProps.params.organizationKey), + currentUser: getCurrentUser(state) +}); + +export default connect(mapStateToProps)(OrganizationContainer); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.js index d1b270dd0d4..cf91c1e61b9 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.js @@ -115,12 +115,8 @@ class OrganizationDelete extends React.PureComponent { } } -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - const mapDispatchToProps = { deleteOrganization }; -export default connect(mapStateToProps, mapDispatchToProps)(withRouter(OrganizationDelete)); +export default connect(null, mapDispatchToProps)(withRouter(OrganizationDelete)); export const UnconnectedOrganizationDelete = OrganizationDelete; diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationEdit.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationEdit.js index 22ea72f7c6a..5f7a3c867ef 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationEdit.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationEdit.js @@ -193,12 +193,8 @@ class OrganizationEdit extends React.PureComponent { } } -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - const mapDispatchToProps = { updateOrganization }; -export default connect(mapStateToProps, mapDispatchToProps)(OrganizationEdit); +export default connect(null, mapDispatchToProps)(OrganizationEdit); export const UnconnectedOrganizationEdit = OrganizationEdit; diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroups.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroups.js index 4d46eedb5b1..984c4c8d6ca 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroups.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroups.js @@ -20,13 +20,11 @@ // @flow import React from 'react'; import Helmet from 'react-helmet'; -import { connect } from 'react-redux'; import init from '../../groups/init'; -import { getOrganizationByKey } from '../../../store/rootReducer'; import { translate } from '../../../helpers/l10n'; /*:: import type { Organization } from '../../../store/organizations/duck'; */ -class OrganizationGroups extends React.PureComponent { +export default class OrganizationGroups extends React.PureComponent { /*:: props: { organization: Organization }; @@ -45,9 +43,3 @@ class OrganizationGroups extends React.PureComponent { ); } } - -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -export default connect(mapStateToProps)(OrganizationGroups); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js deleted file mode 100644 index 201c72151be..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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 AppContainer from '../../permission-templates/components/AppContainer'; -import { getOrganizationByKey } from '../../../store/rootReducer'; -/*:: import type { Organization } from '../../../store/organizations/duck'; */ - -/*:: -type Props = { - location: {}, - organization: Organization -}; -*/ - -function OrganizationPermissionTemplates(props /*: Props */) { - return ; -} - -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -export default connect(mapStateToProps)(OrganizationPermissionTemplates); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissions.tsx b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissions.tsx deleted file mode 100644 index b2136ea2f35..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissions.tsx +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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. - */ -import * as React from 'react'; -import { connect } from 'react-redux'; -import GlobalPermissionsApp from '../../permissions/global/components/App'; -import { getOrganizationByKey } from '../../../store/rootReducer'; -import { Organization } from '../../../app/types'; - -interface Props { - organization: Organization; -} - -function OrganizationPermissions({ organization }: Props) { - return ; -} - -const mapStateToProps = (state: any, ownProps: any) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -export default connect(mapStateToProps)(OrganizationPermissions); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsManagement.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsManagement.js deleted file mode 100644 index a8ae5dd4b09..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsManagement.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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 AppContainer from '../../projectsManagement/AppContainer'; -import { getOrganizationByKey } from '../../../store/rootReducer'; -/*:: import type { Organization } from '../../../store/organizations/duck'; */ - -/*:: -type Props = { - organization: Organization -}; -*/ - -function OrganizationProjectsManagement(props /*: Props */) { - return ; -} - -const mapStateToProps = (state, ownProps) => ({ - organization: getOrganizationByKey(state, ownProps.params.organizationKey) -}); - -export default connect(mapStateToProps)(OrganizationProjectsManagement); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdmin-test.js b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdmin-test.js deleted file mode 100644 index 77c7e788dcf..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdmin-test.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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. - */ -import React from 'react'; -import { shallow } from 'enzyme'; -import { OrganizationAdmin } from '../OrganizationAdmin'; - -jest.mock('../../../../app/utils/handleRequiredAuthorization', () => jest.fn()); - -it('should render children', () => { - const organization = { canAdmin: true }; - expect( - shallow( - -
hello
-
- ) - ).toMatchSnapshot(); -}); - -it('should not render anything', () => { - const organization = { canAdmin: false }; - expect( - shallow( - -
hello
-
- ).type() - ).toBeNull(); -}); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdminContainer-test.tsx b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdminContainer-test.tsx new file mode 100644 index 00000000000..dc4eab48ac5 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdminContainer-test.tsx @@ -0,0 +1,60 @@ +/* +* SonarQube +* Copyright (C) 2009-2017 SonarSource SA +* mailto:info 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. +*/ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import { Location } from 'history'; +import { OrganizationAdmin } from '../OrganizationAdminContainer'; +import { Visibility } from '../../../../app/types'; + +jest.mock('../../../../app/utils/handleRequiredAuthorization', () => ({ default: jest.fn() })); + +const locationMock = {} as Location; + +it('should render children', () => { + const organization = { + canAdmin: true, + key: 'foo', + name: 'Foo', + projectVisibility: Visibility.Public + }; + expect( + shallow( + +
hello
+
+ ) + ).toMatchSnapshot(); +}); + +it('should not render anything', () => { + const organization = { + canAdmin: false, + key: 'foo', + name: 'Foo', + projectVisibility: Visibility.Public + }; + expect( + shallow( + +
hello
+
+ ).type() + ).toBeNull(); +}); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdmin-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdmin-test.js.snap deleted file mode 100644 index 331cb8d84f7..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdmin-test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render children 1`] = ` -
- hello -
-`; diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdminContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdminContainer-test.tsx.snap new file mode 100644 index 00000000000..349db2dd14c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdminContainer-test.tsx.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render children 1`] = ` +
+ hello +
+`; diff --git a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.tsx.snap b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.tsx.snap index 66184bbc5d4..b9efc8fe2e3 100644 --- a/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.tsx.snap @@ -18,6 +18,7 @@ exports[`admin 1`] = ` "canDelete": true, "key": "foo", "name": "Foo", + "projectVisibility": "public", } } /> @@ -221,6 +222,7 @@ exports[`regular user 1`] = ` "canDelete": false, "key": "foo", "name": "Foo", + "projectVisibility": "public", } } /> @@ -344,6 +346,7 @@ exports[`undeletable org 1`] = ` "canDelete": false, "key": "foo", "name": "Foo", + "projectVisibility": "public", } } /> diff --git a/server/sonar-web/src/main/js/apps/organizations/routes.js b/server/sonar-web/src/main/js/apps/organizations/routes.js deleted file mode 100644 index d4cbdaa8a9c..00000000000 --- a/server/sonar-web/src/main/js/apps/organizations/routes.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info 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. - */ -import OrganizationPageContainer from './components/OrganizationPage'; -import OrganizationPageExtension from '../../app/components/extensions/OrganizationPageExtension'; -import OrganizationContainer from './components/OrganizationContainer'; -import OrganizationProjects from './components/OrganizationProjects'; -import OrganizationRules from './components/OrganizationRules'; -import OrganizationAdminContainer from './components/OrganizationAdmin'; -import OrganizationEdit from './components/OrganizationEdit'; -import OrganizationGroups from './components/OrganizationGroups'; -import OrganizationMembersContainer from './components/OrganizationMembersContainer'; -import OrganizationPermissions from './components/OrganizationPermissions'; -import OrganizationPermissionTemplates from './components/OrganizationPermissionTemplates'; -import OrganizationProjectsManagement from './components/OrganizationProjectsManagement'; -import OrganizationDelete from './components/OrganizationDelete'; -import qualityGatesRoutes from '../quality-gates/routes'; -import qualityProfilesRoutes from '../quality-profiles/routes'; -import Issues from '../issues/components/AppContainer'; - -const routes = [ - { - path: ':organizationKey', - component: OrganizationPageContainer, - childRoutes: [ - { - indexRoute: { - onEnter(nextState, replace) { - const { params } = nextState; - replace(`/organizations/${params.organizationKey}/projects`); - } - } - }, - { - path: 'projects', - component: OrganizationContainer, - childRoutes: [{ indexRoute: { component: OrganizationProjects } }] - }, - { - path: 'issues', - component: OrganizationContainer, - childRoutes: [{ indexRoute: { component: Issues } }] - }, - { - path: 'members', - component: OrganizationMembersContainer - }, - { - path: 'rules', - component: OrganizationRules - }, - { - path: 'quality_profiles', - childRoutes: qualityProfilesRoutes - }, - { - path: 'quality_gates', - component: OrganizationContainer, - childRoutes: qualityGatesRoutes - }, - { - path: 'extension/:pluginKey/:extensionKey', - component: OrganizationPageExtension - }, - { - component: OrganizationAdminContainer, - childRoutes: [ - { path: 'delete', component: OrganizationDelete }, - { path: 'edit', component: OrganizationEdit }, - { path: 'groups', component: OrganizationGroups }, - { path: 'permissions', component: OrganizationPermissions }, - { path: 'permission_templates', component: OrganizationPermissionTemplates }, - { path: 'projects_management', component: OrganizationProjectsManagement } - ] - } - ] - } -]; - -export default routes; diff --git a/server/sonar-web/src/main/js/apps/organizations/routes.ts b/server/sonar-web/src/main/js/apps/organizations/routes.ts new file mode 100644 index 00000000000..fff5e339798 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/organizations/routes.ts @@ -0,0 +1,97 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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. + */ +import { RouterState, RedirectFunction } from 'react-router'; +import GlobalPermissionsApp from '../permissions/global/components/App'; +import OrganizationPageContainer from './components/OrganizationPage'; +import OrganizationPageExtension from '../../app/components/extensions/OrganizationPageExtension'; +import OrganizationContainer from './components/OrganizationContainer'; +import OrganizationProjects from './components/OrganizationProjects'; +import OrganizationRules from './components/OrganizationRules'; +import OrganizationAdminContainer from './components/OrganizationAdminContainer'; +import OrganizationEdit from './components/OrganizationEdit'; +import OrganizationGroups from './components/OrganizationGroups'; +import OrganizationMembersContainer from './components/OrganizationMembersContainer'; +import OrganizationDelete from './components/OrganizationDelete'; +import PermissionTemplateApp from '../permission-templates/components/AppContainer'; +import ProjectManagementApp from '../projectsManagement/AppContainer'; +import qualityGatesRoutes from '../quality-gates/routes'; +import qualityProfilesRoutes from '../quality-profiles/routes'; +import Issues from '../issues/components/AppContainer'; + +const routes = [ + { + path: ':organizationKey', + component: OrganizationPageContainer, + childRoutes: [ + { + indexRoute: { + onEnter(nextState: RouterState, replace: RedirectFunction) { + const { params } = nextState; + replace(`/organizations/${params.organizationKey}/projects`); + } + } + }, + { + path: 'projects', + component: OrganizationContainer, + childRoutes: [{ indexRoute: { component: OrganizationProjects } }] + }, + { + path: 'issues', + component: OrganizationContainer, + childRoutes: [{ indexRoute: { component: Issues } }] + }, + { + path: 'members', + component: OrganizationMembersContainer + }, + { + path: 'rules', + component: OrganizationRules + }, + { + path: 'quality_profiles', + childRoutes: qualityProfilesRoutes + }, + { + path: 'quality_gates', + component: OrganizationContainer, + childRoutes: qualityGatesRoutes + }, + { + path: 'extension/:pluginKey/:extensionKey', + component: OrganizationPageExtension + }, + { + component: OrganizationAdminContainer, + childRoutes: [ + { path: 'delete', component: OrganizationDelete }, + { path: 'edit', component: OrganizationEdit }, + { path: 'groups', component: OrganizationGroups }, + { path: 'permissions', component: GlobalPermissionsApp }, + { path: 'permission_templates', component: PermissionTemplateApp }, + { path: 'projects_management', component: ProjectManagementApp } + ] + } + ] + } +]; + +export default routes; diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx b/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx index 913058f2e88..05730e8252e 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx @@ -69,9 +69,8 @@ export default class AllHoldersList extends React.PureComponent { }; render() { - const order = PERMISSIONS_ORDER; const l10nPrefix = this.props.organization ? 'organizations_permissions' : 'global_permissions'; - const permissions = order.map(p => ({ + const permissions = PERMISSIONS_ORDER.map(p => ({ key: p, name: translate(l10nPrefix, p), description: translate(l10nPrefix, p, 'desc') diff --git a/server/sonar-web/src/main/js/apps/permissions/shared/components/PermissionHeader.tsx b/server/sonar-web/src/main/js/apps/permissions/shared/components/PermissionHeader.tsx index 96d9e40d1c2..390fa00a8d8 100644 --- a/server/sonar-web/src/main/js/apps/permissions/shared/components/PermissionHeader.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/shared/components/PermissionHeader.tsx @@ -35,10 +35,6 @@ interface Props { } export default class PermissionHeader extends React.PureComponent { - static defaultProps = { - showPublicProjectsWarning: false - }; - handlePermissionClick = (event: React.SyntheticEvent) => { event.preventDefault(); event.currentTarget.blur();