]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10073 Impossible to set QP of a project from an organization that is not default
authorStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 9 Jan 2018 10:01:22 +0000 (11:01 +0100)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Tue, 9 Jan 2018 19:16:51 +0000 (20:16 +0100)
server/sonar-web/src/main/js/api/quality-profiles.ts
server/sonar-web/src/main/js/apps/projectQualityProfiles/App.tsx
server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/App-test.tsx
server/sonar-web/src/main/js/apps/quality-profiles/components/App.tsx

index 9daa0c5051a0dcb1a6b34862d12f53a6584feb87..5e2715d7b81e4c6fb530b205eb5f53cfff4dded6 100644 (file)
@@ -97,7 +97,7 @@ export interface SearchQualityProfilesResponse {
 export function searchQualityProfiles(
   parameters: SearchQualityProfilesParameters
 ): Promise<SearchQualityProfilesResponse> {
-  return getJSON('/api/qualityprofiles/search', parameters);
+  return getJSON('/api/qualityprofiles/search', parameters).catch(throwGlobalError);
 }
 
 export function getQualityProfile(data: {
index 45bdae0cb28d6f6565c8899a5e046ba2988645cb..8038913342dc7cb73b6c9d360d9d04d58af40151 100644 (file)
@@ -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<Props, State> {
   }
 
   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) {
index 9e873f1187f9ffe436a8992c32c6e7b4c09b2bd6..35a49ed3bd65f694686495f57609b0c8ee1b45fa 100644 (file)
@@ -66,21 +66,13 @@ const component = {
 
 it('checks permissions', () => {
   handleRequiredAuthorization.mockClear();
-  mount(<App component={{ ...component, configuration: undefined }} customOrganizations={false} />);
+  mount(<App component={{ ...component, configuration: undefined }} />);
   expect(handleRequiredAuthorization).toBeCalled();
 });
 
 it('fetches profiles', () => {
   searchQualityProfiles.mockClear();
-  mount(<App component={component} customOrganizations={false} />);
-  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(<App component={component} customOrganizations={true} />);
+  mount(<App component={component} />);
   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(<App component={component} customOrganizations={false} />);
+  const wrapper = mount(<App component={component} />);
 
   const fooJava = randomProfile('foo-java', 'java');
   const fooJs = randomProfile('foo-js', 'js');
index fda9bb7ed26ed3e7db83286aa91e5aa154ec2685..661d0b4b3e7a9161e08e5734b0895bb5d76b89dd 100644 (file)
@@ -60,17 +60,24 @@ export default class App extends React.PureComponent<Props, State> {
 
   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 = () => {