From 94775d6f33ce5a725d0f3f229d80a0d419db2781 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 29 Sep 2017 15:25:20 +0200 Subject: SONAR-7590 pass return_to for oauth providers --- .../src/main/js/apps/sessions/components/LoginForm.tsx | 6 +++++- .../main/js/apps/sessions/components/LoginFormContainer.tsx | 10 +++++++--- .../src/main/js/apps/sessions/components/OAuthProviders.tsx | 6 +++++- .../js/apps/sessions/components/__tests__/LoginForm-test.tsx | 6 +++--- .../components/__tests__/__snapshots__/LoginForm-test.tsx.snap | 3 +++ 5 files changed, 23 insertions(+), 8 deletions(-) (limited to 'server/sonar-web') diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx b/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx index aafa8e68ea5..dbb5afeaa27 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx @@ -28,6 +28,7 @@ interface Props { onSonarCloud: boolean; identityProviders: IdentityProvider[]; onSubmit: (login: string, password: string) => void; + returnTo: string; } interface State { @@ -72,7 +73,10 @@ export default class LoginForm extends React.PureComponent {

{loginTitle}

{this.props.identityProviders.length > 0 && ( - + )} {this.state.collapsed ? ( diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx index 1fce14f6e00..f4096338e9a 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx @@ -59,11 +59,14 @@ class LoginFormContainer extends React.PureComponent { this.mounted = false; } - handleSuccessfulLogin = () => { + getReturnUrl = () => { const { location } = this.props; const queryReturnTo = location.query['return_to']; - const returnTo = queryReturnTo ? `${queryReturnTo}${location.hash}` : `${getBaseUrl()}/`; - window.location.href = returnTo; + return queryReturnTo ? `${queryReturnTo}${location.hash}` : `${getBaseUrl()}/`; + }; + + handleSuccessfulLogin = () => { + window.location.href = this.getReturnUrl(); }; handleSubmit = (login: string, password: string) => { @@ -81,6 +84,7 @@ class LoginFormContainer extends React.PureComponent { identityProviders={identityProviders} onSonarCloud={onSonarCloud} onSubmit={this.handleSubmit} + returnTo={this.getReturnUrl()} /> ); } diff --git a/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx b/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx index 973f8b31021..ec13345fea5 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx @@ -25,6 +25,7 @@ import { getBaseUrl } from '../../../helpers/urls'; interface Props { formatLabel?: (name: string) => string; identityProviders: IdentityProvider[]; + returnTo: string; } export default function OAuthProviders(props: Props) { @@ -35,7 +36,10 @@ export default function OAuthProviders(props: Props) { {props.identityProviders.map(identityProvider => (
  • { const onSubmit = jest.fn(); const wrapper = shallow( - + ); expect(wrapper).toMatchSnapshot(); @@ -45,14 +45,14 @@ it('logs in with simple credentials', () => { it('logs in with identity provider', () => { const wrapper = shallow( - + ); expect(wrapper).toMatchSnapshot(); }); it('expands more options', () => { const wrapper = shallow( - + ); expect(wrapper).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap index eb68c53aa8c..8c6b6308238 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap @@ -20,6 +20,7 @@ exports[`expands more options 1`] = ` }, ] } + returnTo="" />