From: Jeremy Davis Date: Mon, 6 Jul 2020 13:35:47 +0000 (+0200) Subject: SONAR-13589 Restrict query to correct editions X-Git-Tag: 8.5.0.37579~202 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=34a0bc1a4e14e13a7d40a410b268d6ea7b0f3a40;p=sonarqube.git SONAR-13589 Restrict query to correct editions --- diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx index fca27d93214..0b58cdc9491 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavPlus.tsx @@ -33,7 +33,7 @@ import { ComponentQualifier } from '../../../../types/component'; import GlobalNavPlusMenu from './GlobalNavPlusMenu'; interface Props { - appState: Pick; + appState: Pick; currentUser: T.LoggedInUser; router: Router; } @@ -56,9 +56,7 @@ export class GlobalNavPlus extends React.PureComponent { componentDidMount() { this.mounted = true; - if (hasGlobalPermission(this.props.currentUser, 'provisioning')) { - this.fetchAlmBindings(); - } + this.fetchAlmBindings(); if (this.props.appState.qualifiers.includes('VW')) { getExtensionStart('governance/console').then( @@ -81,6 +79,17 @@ export class GlobalNavPlus extends React.PureComponent { }; fetchAlmBindings = async () => { + const { + appState: { branchesEnabled }, + currentUser + } = this.props; + const canCreateProject = hasGlobalPermission(currentUser, 'provisioning'); + + // getAlmSettings requires branchesEnabled + if (!canCreateProject || !branchesEnabled) { + return; + } + const almSettings = await getAlmSettings(); // Import is only available if exactly one binding is configured @@ -134,7 +143,7 @@ export class GlobalNavPlus extends React.PureComponent { return ( <> { }); it('should render correctly when no rights', async () => { - const wrapper = shallowRender(); + const wrapper = shallowRender([], {}); expect(wrapper.type()).toBeNull(); await waitAndUpdate(wrapper); expect(getAlmSettings).not.toBeCalled(); }); +it('should render correctly if branches not enabled', async () => { + const wrapper = shallowRender([PROJECT_CREATION_RIGHT], { branchesEnabled: false }); + await waitAndUpdate(wrapper); + expect(wrapper).toMatchSnapshot(); + expect(getAlmSettings).not.toBeCalled(); +}); + it('should render correctly', () => { expect( - shallowRender([APP_CREATION_RIGHT, PORTFOLIO_CREATION_RIGHT, PROJECT_CREATION_RIGHT]) + shallowRender([APP_CREATION_RIGHT, PORTFOLIO_CREATION_RIGHT, PROJECT_CREATION_RIGHT], {}) ).toMatchSnapshot('no governance'); const wrapper = shallowRender( [APP_CREATION_RIGHT, PORTFOLIO_CREATION_RIGHT, PROJECT_CREATION_RIGHT], - true + { enableGovernance: true } ); wrapper.setState({ boundAlms: ['bitbucket'] }); expect(wrapper).toMatchSnapshot('full rights and alms'); @@ -77,7 +84,7 @@ it('should load correctly', async () => { { alm: AlmKeys.GitHub, key: 'GH1' } ]); - const wrapper = shallowRender([PROJECT_CREATION_RIGHT]); + const wrapper = shallowRender([PROJECT_CREATION_RIGHT], {}); await waitAndUpdate(wrapper); @@ -86,7 +93,7 @@ it('should load correctly', async () => { }); it('should display component creation form', () => { - const wrapper = shallowRender([PORTFOLIO_CREATION_RIGHT], true); + const wrapper = shallowRender([PORTFOLIO_CREATION_RIGHT], { enableGovernance: true }); wrapper.instance().handleComponentCreationClick(ComponentQualifier.Portfolio); wrapper.setState({ governanceReady: true }); @@ -103,7 +110,7 @@ describe('handleComponentCreate', () => { const portfolio = { key: 'portfolio', qualifier: ComponentQualifier.Portfolio }; - const wrapper = shallowRender([], true); + const wrapper = shallowRender([], { enableGovernance: true }); it('should redirect to admin', async () => { wrapper.instance().handleComponentCreate(portfolio); @@ -120,10 +127,16 @@ describe('handleComponentCreate', () => { }); }); -function shallowRender(permissions: string[] = [], enableGovernance = false) { +function shallowRender( + permissions: string[] = [], + { enableGovernance = false, branchesEnabled = true } +) { return shallow( diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavPlus-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavPlus-test.tsx.snap index 658c06d2ab9..1d95d08cb45 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavPlus-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavPlus-test.tsx.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`should render correctly if branches not enabled 1`] = ` + + + } + tagName="li" + > + + + + + +`; + exports[`should render correctly: full rights and alms 1`] = `