diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-05-12 16:16:19 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-05-12 20:43:29 +0200 |
commit | 9fc2898d4b3c0467968ba3ed3932c16d6e6cde7a (patch) | |
tree | 56abd3fdf285e3e5b084486b532160c70b11ae46 | |
parent | 44bb86905beb8652719b777ec45befc9d325af01 (diff) | |
download | sonarqube-9fc2898d4b3c0467968ba3ed3932c16d6e6cde7a.tar.gz sonarqube-9fc2898d4b3c0467968ba3ed3932c16d6e6cde7a.zip |
SONAR-9044 Do not load user's organizations when organizations are disabled
3 files changed, 103 insertions, 4 deletions
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.js index ac0f288819b..707e372a8ea 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavUser.js @@ -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 })} diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.js b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.js index 0a9f7fb9fa3..54f0f55ab25 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavUser-test.js @@ -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} diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavUser-test.js.snap b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavUser-test.js.snap index 50f52bb687c..f3800e5f3ec 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavUser-test.js.snap +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavUser-test.js.snap @@ -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 |