]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9044 Do not load user's organizations when organizations are disabled
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 12 May 2017 14:16:19 +0000 (16:16 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 12 May 2017 18:43:29 +0000 (20:43 +0200)
server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.js
server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.js
server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavUser-test.js.snap

index ac0f288819b3d144bb12d72c81d2f38c7a808743..707e372a8eafb660b25236e06f9159847e65c41e 100644 (file)
@@ -33,6 +33,9 @@ type CurrentUser = {
 };
 
 type Props = {
+  appState: {
+    organizationsEnabled: boolean
+  },
   currentUser: CurrentUser,
   fetchMyOrganizations: () => Promise<*>,
   location: Object,
@@ -87,7 +90,7 @@ export default class GlobalNavUser extends React.PureComponent {
   };
 
   openDropdown = () => {
-    this.props.fetchMyOrganizations().then(() => {
+    this.fetchMyOrganizations().then(() => {
       window.addEventListener('click', this.handleClickOutside, true);
       this.setState({ open: true });
     });
@@ -98,9 +101,16 @@ export default class GlobalNavUser extends React.PureComponent {
     this.setState({ open: false });
   };
 
+  fetchMyOrganizations = () => {
+    if (this.props.appState.organizationsEnabled) {
+      return this.props.fetchMyOrganizations();
+    }
+    return Promise.resolve();
+  };
+
   renderAuthenticated() {
     const { currentUser, organizations } = this.props;
-    const hasOrganizations = organizations.length > 0;
+    const hasOrganizations = this.props.appState.organizationsEnabled && organizations.length > 0;
     return (
       <li
         className={classNames('dropdown js-user-authenticated', { open: this.state.open })}
index 0a9f7fb9fa36641986ae0ba84d570310184361cf..54f0f55ab25ab592d4c061a1b8024ffb235efa5c 100644 (file)
@@ -27,18 +27,29 @@ const organizations = [
   { key: 'foo', name: 'Foo' },
   { key: 'bar', name: 'bar' }
 ];
+const appState = { organizationsEnabled: true };
 
 it('should render the right interface for anonymous user', () => {
   const currentUser = { isLoggedIn: false };
   const wrapper = shallow(
-    <GlobalNavUser currentUser={currentUser} fetchMyOrganizations={() => {}} organizations={[]} />
+    <GlobalNavUser
+      appState={appState}
+      currentUser={currentUser}
+      fetchMyOrganizations={() => {}}
+      organizations={[]}
+    />
   );
   expect(wrapper).toMatchSnapshot();
 });
 
 it('should render the right interface for logged in user', () => {
   const wrapper = shallow(
-    <GlobalNavUser currentUser={currentUser} fetchMyOrganizations={() => {}} organizations={[]} />
+    <GlobalNavUser
+      appState={appState}
+      currentUser={currentUser}
+      fetchMyOrganizations={() => {}}
+      organizations={[]}
+    />
   );
   wrapper.setState({ open: true });
   expect(wrapper).toMatchSnapshot();
@@ -47,6 +58,20 @@ it('should render the right interface for logged in user', () => {
 it('should render the users organizations', () => {
   const wrapper = shallow(
     <GlobalNavUser
+      appState={appState}
+      currentUser={currentUser}
+      fetchMyOrganizations={() => {}}
+      organizations={organizations}
+    />
+  );
+  wrapper.setState({ open: true });
+  expect(wrapper).toMatchSnapshot();
+});
+
+it('should not render the users organizations when they are not activated', () => {
+  const wrapper = shallow(
+    <GlobalNavUser
+      appState={{ organizationsEnabled: false }}
       currentUser={currentUser}
       fetchMyOrganizations={() => {}}
       organizations={organizations}
@@ -60,6 +85,7 @@ it('should update the component correctly when the user changes to anonymous', (
   const fetchMyOrganizations = jest.fn();
   const wrapper = shallow(
     <GlobalNavUser
+      appState={appState}
       currentUser={currentUser}
       fetchMyOrganizations={fetchMyOrganizations}
       organizations={[]}
@@ -76,6 +102,7 @@ it('should lazyload the organizations when opening the dropdown', () => {
   const fetchMyOrganizations = jest.fn(() => Promise.resolve());
   const wrapper = shallow(
     <GlobalNavUser
+      appState={appState}
       currentUser={currentUser}
       fetchMyOrganizations={fetchMyOrganizations}
       organizations={organizations}
@@ -92,6 +119,7 @@ it('should update the organizations when the user changes', () => {
   const fetchMyOrganizations = jest.fn(() => Promise.resolve());
   const wrapper = shallow(
     <GlobalNavUser
+      appState={appState}
       currentUser={currentUser}
       fetchMyOrganizations={fetchMyOrganizations}
       organizations={organizations}
index 50f52bb687cb80eb92435a828ede9e0ab64592dd..f3800e5f3ece72b10e9e3dd61931c335bcc16c22 100644 (file)
@@ -1,5 +1,66 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
+exports[`should not render the users organizations when they are not activated 1`] = `
+<li
+  className="dropdown js-user-authenticated open"
+>
+  <a
+    className="dropdown-toggle navbar-avatar"
+    href="#"
+    onClick={[Function]}
+  >
+    <Connect(Avatar)
+      email="foo@bar.baz"
+      name="foo"
+      size={24}
+    />
+  </a>
+  <ul
+    className="dropdown-menu dropdown-menu-right"
+  >
+    <li
+      className="dropdown-item"
+    >
+      <div
+        className="text-ellipsis text-muted"
+        title="foo"
+      >
+        <strong>
+          foo
+        </strong>
+      </div>
+      <div
+        className="little-spacer-top text-ellipsis text-muted"
+        title="foo@bar.baz"
+      >
+        foo@bar.baz
+      </div>
+    </li>
+    <li
+      className="divider"
+    />
+    <li>
+      <Link
+        onClick={[Function]}
+        onlyActiveOnIndex={false}
+        style={Object {}}
+        to="/account"
+      >
+        my_account.page
+      </Link>
+    </li>
+    <li>
+      <a
+        href="#"
+        onClick={[Function]}
+      >
+        layout.logout
+      </a>
+    </li>
+  </ul>
+</li>
+`;
+
 exports[`should render the right interface for anonymous user 1`] = `
 <li>
   <a