From 9fc2898d4b3c0467968ba3ed3932c16d6e6cde7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Fri, 12 May 2017 16:16:19 +0200 Subject: [PATCH] SONAR-9044 Do not load user's organizations when organizations are disabled --- .../components/nav/global/GlobalNavUser.js | 14 ++++- .../global/__tests__/GlobalNavUser-test.js | 32 +++++++++- .../__snapshots__/GlobalNavUser-test.js.snap | 61 +++++++++++++++++++ 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 (
  • { const currentUser = { isLoggedIn: false }; const wrapper = shallow( - {}} organizations={[]} /> + {}} + organizations={[]} + /> ); expect(wrapper).toMatchSnapshot(); }); it('should render the right interface for logged in user', () => { const wrapper = shallow( - {}} organizations={[]} /> + {}} + 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( {}} + organizations={organizations} + /> + ); + wrapper.setState({ open: true }); + expect(wrapper).toMatchSnapshot(); +}); + +it('should not render the users organizations when they are not activated', () => { + const wrapper = shallow( + {}} 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( { const fetchMyOrganizations = jest.fn(() => Promise.resolve()); const wrapper = shallow( { const fetchMyOrganizations = jest.fn(() => Promise.resolve()); const wrapper = shallow( + + + + +
  • +`; + exports[`should render the right interface for anonymous user 1`] = `