]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9925 Display a different login page title for SonarCloud
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 9 Oct 2017 09:47:44 +0000 (11:47 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 10 Oct 2017 13:39:29 +0000 (06:39 -0700)
server/sonar-web/src/main/js/api/nav.ts
server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx
server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx
server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx
server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap
server/sonar-web/src/main/less/pages/login.less
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 0e1983d052785e91573a39f0655c9900dc8105e2..e74221c03091406b4c7cdc84ef08cdf56c8e6589 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { getJSON } from '../helpers/request';
+import { getJSON, parseJSON, request } from '../helpers/request';
 import throwGlobalError from '../app/utils/throwGlobalError';
 
 export function getGlobalNavigation(): Promise<any> {
@@ -31,3 +31,18 @@ export function getComponentNavigation(componentKey: string, branch?: string): P
 export function getSettingsNavigation(): Promise<any> {
   return getJSON('/api/navigation/settings').catch(throwGlobalError);
 }
+
+export function tryGetGlobalNavigation(): Promise<any> {
+  return request('/api/navigation/global')
+    .submit()
+    .then(response => {
+      if (response.status >= 200 && response.status < 300) {
+        return parseJSON(response);
+      } else if (response.status === 401) {
+        return {};
+      } else {
+        return Promise.reject(response);
+      }
+    })
+    .catch(response => throwGlobalError({ response }).catch(() => Promise.resolve({})));
+}
index 362e7f86dba23f22099e901d0c6e2b8ed291279c..aafa8e68ea55a517bd8468d3172a4808458d3e7f 100644 (file)
@@ -25,6 +25,7 @@ import { translate } from '../../../helpers/l10n';
 import { IdentityProvider } from '../../../api/users';
 
 interface Props {
+  onSonarCloud: boolean;
   identityProviders: IdentityProvider[];
   onSubmit: (login: string, password: string) => void;
 }
@@ -62,9 +63,13 @@ export default class LoginForm extends React.PureComponent<Props, State> {
     this.setState({ password: event.currentTarget.value });
 
   render() {
+    const loginTitle = this.props.onSonarCloud
+      ? translate('login.login_to_sonarcloud')
+      : translate('login.login_to_sonarqube');
+
     return (
       <div id="login_form">
-        <h1 className="maintenance-title text-center">{translate('login.login_to_sonarqube')}</h1>
+        <h1 className="login-title text-center">{loginTitle}</h1>
 
         {this.props.identityProviders.length > 0 && (
           <OAuthProviders identityProviders={this.props.identityProviders} />
index 2c2152bb61b10c206f1acf696b226a91b33aff3a..1fce14f6e00d8e1147b8d4943a28527a0f5ba27a 100644 (file)
@@ -21,7 +21,7 @@ import * as React from 'react';
 import { connect } from 'react-redux';
 import LoginForm from './LoginForm';
 import { doLogin } from '../../../store/rootActions';
-import { getAppState } from '../../../store/rootReducer';
+import { tryGetGlobalNavigation } from '../../../api/nav';
 import { IdentityProvider, getIdentityProviders } from '../../../api/users';
 import { getBaseUrl } from '../../../helpers/urls';
 
@@ -32,17 +32,25 @@ interface Props {
 
 interface State {
   identityProviders?: IdentityProvider[];
+  onSonarCloud: boolean;
 }
 
 class LoginFormContainer extends React.PureComponent<Props, State> {
   mounted: boolean;
-  state: State = {};
+  state: State = { onSonarCloud: false };
 
   componentDidMount() {
     this.mounted = true;
-    getIdentityProviders().then(r => {
+    Promise.all([
+      getIdentityProviders(),
+      tryGetGlobalNavigation()
+    ]).then(([identityProvidersResponse, appState]) => {
       if (this.mounted) {
-        this.setState({ identityProviders: r.identityProviders });
+        this.setState({
+          onSonarCloud:
+            appState.settings && appState.settings['sonar.sonarcloud.enabled'] === 'true',
+          identityProviders: identityProvidersResponse.identityProviders
+        });
       }
     });
   }
@@ -63,20 +71,22 @@ class LoginFormContainer extends React.PureComponent<Props, State> {
   };
 
   render() {
-    if (!this.state.identityProviders) {
+    const { identityProviders, onSonarCloud } = this.state;
+    if (!identityProviders) {
       return null;
     }
 
     return (
-      <LoginForm identityProviders={this.state.identityProviders} onSubmit={this.handleSubmit} />
+      <LoginForm
+        identityProviders={identityProviders}
+        onSonarCloud={onSonarCloud}
+        onSubmit={this.handleSubmit}
+      />
     );
   }
 }
 
-const mapStateToProps = (state: any) => ({
-  appState: getAppState(state)
-});
-
+const mapStateToProps = null;
 const mapDispatchToProps = { doLogin };
 
 export default connect(mapStateToProps, mapDispatchToProps)(LoginFormContainer as any);
index 47f1add3ed32007aa9d43d9c1b76c1a019f1c566..6f1d1ce19270a64ecdcec75619e4eb542c8dfcc6 100644 (file)
@@ -31,7 +31,9 @@ const identityProvider = {
 
 it('logs in with simple credentials', () => {
   const onSubmit = jest.fn();
-  const wrapper = shallow(<LoginForm identityProviders={[]} onSubmit={onSubmit} />);
+  const wrapper = shallow(
+    <LoginForm onSonarCloud={false} identityProviders={[]} onSubmit={onSubmit} />
+  );
   expect(wrapper).toMatchSnapshot();
 
   change(wrapper.find('#login'), 'admin');
@@ -43,14 +45,14 @@ it('logs in with simple credentials', () => {
 
 it('logs in with identity provider', () => {
   const wrapper = shallow(
-    <LoginForm identityProviders={[identityProvider]} onSubmit={jest.fn()} />
+    <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} />
   );
   expect(wrapper).toMatchSnapshot();
 });
 
 it('expands more options', () => {
   const wrapper = shallow(
-    <LoginForm identityProviders={[identityProvider]} onSubmit={jest.fn()} />
+    <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} />
   );
   expect(wrapper).toMatchSnapshot();
 
index 295059922eef470b0476242e69d6c327285a9bf8..eb68c53aa8ced7db6eb7b72614d51dd39da966fe 100644 (file)
@@ -5,7 +5,7 @@ exports[`expands more options 1`] = `
   id="login_form"
 >
   <h1
-    className="maintenance-title text-center"
+    className="login-title text-center"
   >
     login.login_to_sonarqube
   </h1>
@@ -40,7 +40,7 @@ exports[`expands more options 2`] = `
   id="login_form"
 >
   <h1
-    className="maintenance-title text-center"
+    className="login-title text-center"
   >
     login.login_to_sonarqube
   </h1>
@@ -131,7 +131,7 @@ exports[`logs in with identity provider 1`] = `
   id="login_form"
 >
   <h1
-    className="maintenance-title text-center"
+    className="login-title text-center"
   >
     login.login_to_sonarqube
   </h1>
@@ -166,7 +166,7 @@ exports[`logs in with simple credentials 1`] = `
   id="login_form"
 >
   <h1
-    className="maintenance-title text-center"
+    className="login-title text-center"
   >
     login.login_to_sonarqube
   </h1>
index 9d7e4a6f0b327eb8e457ded14e7dd0643aaff66b..d91bb7d7572e1fda8ed39c171b272d14bb06f03b 100644 (file)
 @import (reference) "../variables";
 @import (reference) "../mixins";
 
+.login-title {
+  margin-bottom: 40px;
+  line-height: 1.5;
+  font-size: 24px;
+  font-weight: 300;
+  text-align: center;
+}
+
 .login-input {
   width: 100% !important;
   height: auto !important;
index 60cec37405f8b9592ae4bd419ea8933fbd434bbd..5642477be120bf0dd13f1d60a513465a5471994c 100644 (file)
@@ -1347,6 +1347,7 @@ user.password_doesnt_match_confirmation=Password doesn't match confirmation.
 user.login_or_email_used_as_scm_account=Login and email are automatically considered as SCM accounts
 
 login.login_to_sonarqube=Log In to SonarQube
+login.login_to_sonarcloud=Log In to SonarCloud
 login.more_options=More options
 login.login_with_x=Log in with {0}