]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10338 do not fetch "my" organization when not logged in
authorStas Vilchik <stas.vilchik@sonarsource.com>
Fri, 2 Feb 2018 08:54:27 +0000 (09:54 +0100)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Wed, 14 Mar 2018 08:20:28 +0000 (09:20 +0100)
server/sonar-web/src/main/js/app/components/App.tsx
server/sonar-web/src/main/js/app/components/Landing.tsx
server/sonar-web/src/main/js/store/users/actions.ts

index 845d6b880c0b1ae95f4eaef35668225267cc7e5b..4c5a266afde707e82bb36ba5feacaa71ffd14f46 100644 (file)
@@ -21,6 +21,7 @@ import * as React from 'react';
 import { connect } from 'react-redux';
 import * as PropTypes from 'prop-types';
 import GlobalLoading from './GlobalLoading';
+import { CurrentUser } from '../types';
 import { fetchCurrentUser } from '../../store/users/actions';
 import { fetchLanguages, fetchAppState } from '../../store/rootActions';
 import { fetchMyOrganizations } from '../../apps/account/organizations/actions';
@@ -28,7 +29,7 @@ import { fetchMyOrganizations } from '../../apps/account/organizations/actions';
 interface Props {
   children: JSX.Element;
   fetchAppState: () => Promise<any>;
-  fetchCurrentUser: () => Promise<void>;
+  fetchCurrentUser: () => Promise<CurrentUser>;
   fetchLanguages: () => Promise<void>;
   fetchMyOrganizations: () => Promise<void>;
 }
@@ -74,20 +75,22 @@ class App extends React.PureComponent<Props, State> {
   componentDidMount() {
     this.mounted = true;
 
-    this.props
-      .fetchCurrentUser()
-      .then(() => Promise.all([this.fetchAppState(), this.props.fetchLanguages()]))
-      .then(
-        ([appState]) => {
-          if (this.mounted) {
-            if (appState.organizationsEnabled) {
-              this.props.fetchMyOrganizations();
+    this.props.fetchCurrentUser().then(
+      currentUser => {
+        Promise.all([this.fetchAppState(), this.props.fetchLanguages()]).then(
+          ([appState]) => {
+            if (this.mounted) {
+              if (appState.organizationsEnabled && currentUser.isLoggedIn) {
+                this.props.fetchMyOrganizations();
+              }
+              this.setState({ loading: false });
             }
-            this.setState({ loading: false });
-          }
-        },
-        () => {}
-      );
+          },
+          () => {}
+        );
+      },
+      () => {}
+    );
   }
 
   componentWillUnmount() {
index bf257783c72eb8fcbaffc7972219342989340137..d9f522035faec48d52134b19f1f8f8e329de2b57 100644 (file)
@@ -25,7 +25,7 @@ import { getCurrentUser, getGlobalSettingValue } from '../../store/rootReducer';
 import { getHomePageUrl } from '../../helpers/urls';
 
 interface Props {
-  currentUser: CurrentUser;
+  currentUser: CurrentUser | undefined;
   onSonarCloud: boolean;
 }
 
@@ -36,7 +36,7 @@ class Landing extends React.PureComponent<Props> {
 
   componentDidMount() {
     const { currentUser, onSonarCloud } = this.props;
-    if (isLoggedIn(currentUser)) {
+    if (currentUser && isLoggedIn(currentUser)) {
       if (currentUser.homepage) {
         const homepage = getHomePageUrl(currentUser.homepage);
         this.context.router.replace(homepage);
index dd9d84ffe81bc0e62d8804b42c690e9f593809b8..46c31b7c472da829bf972f1996ab6956485aaf60 100644 (file)
@@ -39,7 +39,10 @@ export const receiveUser = (user: any) => ({
 export const skipOnboarding = () => ({ type: SKIP_ONBOARDING });
 
 export const fetchCurrentUser = () => (dispatch: Dispatch<any>) => {
-  return api.getCurrentUser().then(user => dispatch(receiveCurrentUser(user)));
+  return api.getCurrentUser().then(user => {
+    dispatch(receiveCurrentUser(user));
+    return user;
+  });
 };
 
 export const setHomePage = (homepage: HomePage) => (dispatch: Dispatch<any>) => {