From: Stas Vilchik Date: Tue, 9 Jan 2018 10:01:22 +0000 (+0100) Subject: SONAR-10073 Impossible to set QP of a project from an organization that is not default X-Git-Tag: 7.0-RC1~40 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1904c96a996c1cba54e2fe7540447fcb031e00d3;p=sonarqube.git SONAR-10073 Impossible to set QP of a project from an organization that is not default --- diff --git a/server/sonar-web/src/main/js/api/quality-profiles.ts b/server/sonar-web/src/main/js/api/quality-profiles.ts index 9daa0c5051a..5e2715d7b81 100644 --- a/server/sonar-web/src/main/js/api/quality-profiles.ts +++ b/server/sonar-web/src/main/js/api/quality-profiles.ts @@ -97,7 +97,7 @@ export interface SearchQualityProfilesResponse { export function searchQualityProfiles( parameters: SearchQualityProfilesParameters ): Promise { - return getJSON('/api/qualityprofiles/search', parameters); + return getJSON('/api/qualityprofiles/search', parameters).catch(throwGlobalError); } export function getQualityProfile(data: { diff --git a/server/sonar-web/src/main/js/apps/projectQualityProfiles/App.tsx b/server/sonar-web/src/main/js/apps/projectQualityProfiles/App.tsx index 45bdae0cb28..8038913342d 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityProfiles/App.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityProfiles/App.tsx @@ -34,7 +34,6 @@ import { translate, translateWithParameters } from '../../helpers/l10n'; interface Props { component: Component; - customOrganizations: boolean; } interface State { @@ -67,11 +66,10 @@ export default class QualityProfiles extends React.PureComponent { } fetchProfiles() { - const { component } = this.props; - const organization = this.props.customOrganizations ? component.organization : undefined; + const { key, organization } = this.props.component; Promise.all([ searchQualityProfiles({ organization }).then(r => r.profiles), - searchQualityProfiles({ organization, project: component.key }).then(r => r.profiles) + searchQualityProfiles({ organization, project: key }).then(r => r.profiles) ]).then( ([allProfiles, profiles]) => { if (this.mounted) { diff --git a/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/App-test.tsx index 9e873f1187f..35a49ed3bd6 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/App-test.tsx @@ -66,21 +66,13 @@ const component = { it('checks permissions', () => { handleRequiredAuthorization.mockClear(); - mount(); + mount(); expect(handleRequiredAuthorization).toBeCalled(); }); it('fetches profiles', () => { searchQualityProfiles.mockClear(); - mount(); - expect(searchQualityProfiles.mock.calls).toHaveLength(2); - expect(searchQualityProfiles).toBeCalledWith({ organization: undefined }); - expect(searchQualityProfiles).toBeCalledWith({ organization: undefined, project: 'foo' }); -}); - -it('fetches profiles with organization', () => { - searchQualityProfiles.mockClear(); - mount(); + mount(); expect(searchQualityProfiles.mock.calls).toHaveLength(2); expect(searchQualityProfiles).toBeCalledWith({ organization: 'org' }); expect(searchQualityProfiles).toBeCalledWith({ organization: 'org', project: 'foo' }); @@ -90,7 +82,7 @@ it('changes profile', () => { associateProject.mockClear(); dissociateProject.mockClear(); addGlobalSuccessMessage.mockClear(); - const wrapper = mount(); + const wrapper = mount(); const fooJava = randomProfile('foo-java', 'java'); const fooJs = randomProfile('foo-js', 'js'); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx index fda9bb7ed26..661d0b4b3e7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx @@ -60,17 +60,24 @@ export default class App extends React.PureComponent { loadData() { this.setState({ loading: true }); - Promise.all([getExporters(), this.fetchProfiles()]).then(responses => { - if (this.mounted) { - const [exporters, profilesResponse] = responses; - this.setState({ - actions: profilesResponse.actions, - exporters, - profiles: sortProfiles(profilesResponse.profiles), - loading: false - }); + Promise.all([getExporters(), this.fetchProfiles()]).then( + responses => { + if (this.mounted) { + const [exporters, profilesResponse] = responses; + this.setState({ + actions: profilesResponse.actions, + exporters, + profiles: sortProfiles(profilesResponse.profiles), + loading: false + }); + } + }, + () => { + if (this.mounted) { + this.setState({ loading: false }); + } } - }); + ); } updateProfiles = () => {