aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx10
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap3
5 files changed, 23 insertions, 8 deletions
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<Props, State> {
<h1 className="login-title text-center">{loginTitle}</h1>
{this.props.identityProviders.length > 0 && (
- <OAuthProviders identityProviders={this.props.identityProviders} />
+ <OAuthProviders
+ identityProviders={this.props.identityProviders}
+ returnTo={this.props.returnTo}
+ />
)}
{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<Props, State> {
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<Props, State> {
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 => (
<li key={identityProvider.key}>
<a
- href={`${getBaseUrl()}/sessions/init/${identityProvider.key}`}
+ href={
+ `${getBaseUrl()}/sessions/init/${identityProvider.key}` +
+ `?return_to=${encodeURIComponent(props.returnTo)}`
+ }
style={{ backgroundColor: identityProvider.backgroundColor }}
title={formatLabel(identityProvider.name)}>
<img
diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx
index 6f1d1ce1927..29a5edfb341 100644
--- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx
+++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx
@@ -32,7 +32,7 @@ const identityProvider = {
it('logs in with simple credentials', () => {
const onSubmit = jest.fn();
const wrapper = shallow(
- <LoginForm onSonarCloud={false} identityProviders={[]} onSubmit={onSubmit} />
+ <LoginForm onSonarCloud={false} identityProviders={[]} onSubmit={onSubmit} returnTo="" />
);
expect(wrapper).toMatchSnapshot();
@@ -45,14 +45,14 @@ it('logs in with simple credentials', () => {
it('logs in with identity provider', () => {
const wrapper = shallow(
- <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} />
+ <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} returnTo="" />
);
expect(wrapper).toMatchSnapshot();
});
it('expands more options', () => {
const wrapper = shallow(
- <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} />
+ <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} returnTo="" />
);
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=""
/>
<div
className="text-center"
@@ -55,6 +56,7 @@ exports[`expands more options 2`] = `
},
]
}
+ returnTo=""
/>
<form
onSubmit={[Function]}
@@ -146,6 +148,7 @@ exports[`logs in with identity provider 1`] = `
},
]
}
+ returnTo=""
/>
<div
className="text-center"