From: Stas Vilchik Date: Fri, 2 Feb 2018 08:54:27 +0000 (+0100) Subject: SONAR-10338 do not fetch "my" organization when not logged in X-Git-Tag: 7.5~1541 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=47d50b8a9c17d595a07b6a7e157849ccf1ffc302;p=sonarqube.git SONAR-10338 do not fetch "my" organization when not logged in --- diff --git a/server/sonar-web/src/main/js/app/components/App.tsx b/server/sonar-web/src/main/js/app/components/App.tsx index 845d6b880c0..4c5a266afde 100644 --- a/server/sonar-web/src/main/js/app/components/App.tsx +++ b/server/sonar-web/src/main/js/app/components/App.tsx @@ -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; - fetchCurrentUser: () => Promise; + fetchCurrentUser: () => Promise; fetchLanguages: () => Promise; fetchMyOrganizations: () => Promise; } @@ -74,20 +75,22 @@ class App extends React.PureComponent { 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() { diff --git a/server/sonar-web/src/main/js/app/components/Landing.tsx b/server/sonar-web/src/main/js/app/components/Landing.tsx index bf257783c72..d9f522035fa 100644 --- a/server/sonar-web/src/main/js/app/components/Landing.tsx +++ b/server/sonar-web/src/main/js/app/components/Landing.tsx @@ -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 { 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); diff --git a/server/sonar-web/src/main/js/store/users/actions.ts b/server/sonar-web/src/main/js/store/users/actions.ts index dd9d84ffe81..46c31b7c472 100644 --- a/server/sonar-web/src/main/js/store/users/actions.ts +++ b/server/sonar-web/src/main/js/store/users/actions.ts @@ -39,7 +39,10 @@ export const receiveUser = (user: any) => ({ export const skipOnboarding = () => ({ type: SKIP_ONBOARDING }); export const fetchCurrentUser = () => (dispatch: Dispatch) => { - 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) => {