diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-02-02 09:54:27 +0100 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-03-14 09:20:28 +0100 |
commit | 47d50b8a9c17d595a07b6a7e157849ccf1ffc302 (patch) | |
tree | 1723a9347c7f9f0c8b5d0efc2afecf01b7dea4fd /server/sonar-web/src | |
parent | ad9dd01e97b800714e76baa9a31e80db7ecc1c90 (diff) | |
download | sonarqube-47d50b8a9c17d595a07b6a7e157849ccf1ffc302.tar.gz sonarqube-47d50b8a9c17d595a07b6a7e157849ccf1ffc302.zip |
SONAR-10338 do not fetch "my" organization when not logged in
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r-- | server/sonar-web/src/main/js/app/components/App.tsx | 31 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/app/components/Landing.tsx | 4 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/store/users/actions.ts | 5 |
3 files changed, 23 insertions, 17 deletions
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<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() { 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<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); 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<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>) => { |