]> source.dussan.org Git - sonarqube.git/commitdiff
Rewrite usage of Organization containers
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 30 Nov 2017 10:25:53 +0000 (11:25 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 14 Dec 2017 16:03:35 +0000 (17:03 +0100)
21 files changed:
server/sonar-web/src/main/js/api/users.ts
server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.tsx
server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdmin.js [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/OrganizationAdminContainer.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.js [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/OrganizationContainer.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/organizations/components/OrganizationDelete.js
server/sonar-web/src/main/js/apps/organizations/components/OrganizationEdit.js
server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroups.js
server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissionTemplates.js [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/OrganizationPermissions.tsx [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/OrganizationProjectsManagement.js [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdmin-test.js [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationAdminContainer-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdmin-test.js.snap [deleted file]
server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationAdminContainer-test.tsx.snap [new file with mode: 0644]
server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/__snapshots__/OrganizationNavigation-test.tsx.snap
server/sonar-web/src/main/js/apps/organizations/routes.js [deleted file]
server/sonar-web/src/main/js/apps/organizations/routes.ts [new file with mode: 0644]
server/sonar-web/src/main/js/apps/permissions/global/components/AllHoldersList.tsx
server/sonar-web/src/main/js/apps/permissions/shared/components/PermissionHeader.tsx

index d04b71bcd55b2c56bcf52509400d4918657da4a1..fa1b73f80fa343b3ed793233192168457bacf3ac 100644 (file)
@@ -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<any> {
+export function getCurrentUser(): Promise<CurrentUser> {
   return getJSON('/api/users/current');
 }
 
index 1ffec34be8fd7de253f6e07f89472676c1c6c51b..90cf03932935879cf142db57d22468eb608843f8 100644 (file)
 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 (file)
index d11ba3c..0000000
+++ /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 (file)
index 0000000..393c176
--- /dev/null
@@ -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<OwnProps, 'children' | 'location'> {}
+
+export class OrganizationAdmin extends React.PureComponent<Props> {
+  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<StateToProps, {}, OwnProps>(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 (file)
index a48cf7f..0000000
+++ /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 (file)
index 0000000..01b44ca
--- /dev/null
@@ -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<OwnProps, 'children' | 'location'> {}
+
+class OrganizationContainer extends React.PureComponent<Props> {
+  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<StateToProps, {}, OwnProps>(mapStateToProps)(OrganizationContainer);
index d1b270dd0d44e2f2581088401084d52c8150d7a5..cf91c1e61b96654265be538f09ed35c3411f805b 100644 (file)
@@ -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;
index 22ea72f7c6a8c5485780733dc072d0afbb7a55b1..5f7a3c867efd4a168507bdb7987edb53b0bdd881 100644 (file)
@@ -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;
index 4d46eedb5b163846b60f88d1e9f6f85e139a5ac6..984c4c8d6caa73ec4a5c0091c539117b27f96393 100644 (file)
 // @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 (file)
index 201c721..0000000
+++ /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 <AppContainer location={props.location} organization={props.organization} />;
-}
-
-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 (file)
index b2136ea..0000000
+++ /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 <GlobalPermissionsApp organization={organization} />;
-}
-
-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 (file)
index a8ae5dd..0000000
+++ /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 <AppContainer organization={props.organization} />;
-}
-
-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 (file)
index 77c7e78..0000000
+++ /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(
-      <OrganizationAdmin organization={organization}>
-        <div>hello</div>
-      </OrganizationAdmin>
-    )
-  ).toMatchSnapshot();
-});
-
-it('should not render anything', () => {
-  const organization = { canAdmin: false };
-  expect(
-    shallow(
-      <OrganizationAdmin organization={organization}>
-        <div>hello</div>
-      </OrganizationAdmin>
-    ).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 (file)
index 0000000..dc4eab4
--- /dev/null
@@ -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(
+      <OrganizationAdmin organization={organization} location={locationMock}>
+        <div>hello</div>
+      </OrganizationAdmin>
+    )
+  ).toMatchSnapshot();
+});
+
+it('should not render anything', () => {
+  const organization = {
+    canAdmin: false,
+    key: 'foo',
+    name: 'Foo',
+    projectVisibility: Visibility.Public
+  };
+  expect(
+    shallow(
+      <OrganizationAdmin organization={organization} location={locationMock}>
+        <div>hello</div>
+      </OrganizationAdmin>
+    ).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 (file)
index 331cb8d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render children 1`] = `
-<div>
-  hello
-</div>
-`;
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 (file)
index 0000000..349db2d
--- /dev/null
@@ -0,0 +1,17 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render children 1`] = `
+<div
+  location={Object {}}
+  organization={
+    Object {
+      "canAdmin": true,
+      "key": "foo",
+      "name": "Foo",
+      "projectVisibility": "public",
+    }
+  }
+>
+  hello
+</div>
+`;
index 66184bbc5d4022a9940329d9dd6d5b4ab10db5d0..b9efc8fe2e30d1dabae7c8fb7e1bab2476efb872 100644 (file)
@@ -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 (file)
index d4cbdaa..0000000
+++ /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 (file)
index 0000000..fff5e33
--- /dev/null
@@ -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;
index 913058f2e88b6f48558a677b666c127c53bf4d7e..05730e8252e920a90b90475c6d7d3d4d88744ed4 100644 (file)
@@ -69,9 +69,8 @@ export default class AllHoldersList extends React.PureComponent<Props> {
   };
 
   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')
index 96d9e40d1c263aa815c355e564571d1e99250142..390fa00a8d8b882b367d458fe4d79ce722c7e36f 100644 (file)
@@ -35,10 +35,6 @@ interface Props {
 }
 
 export default class PermissionHeader extends React.PureComponent<Props> {
-  static defaultProps = {
-    showPublicProjectsWarning: false
-  };
-
   handlePermissionClick = (event: React.SyntheticEvent<HTMLAnchorElement>) => {
     event.preventDefault();
     event.currentTarget.blur();