From: Grégoire Aubert Date: Wed, 4 Oct 2017 16:14:49 +0000 (+0200) Subject: SONAR-9925 Rewrite session to typescript X-Git-Tag: 6.7-RC1~329 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb8126d2d05acc3605fb233c68b935de4dc74214;p=sonarqube.git SONAR-9925 Rewrite session to typescript --- diff --git a/server/sonar-web/src/main/js/api/users.ts b/server/sonar-web/src/main/js/api/users.ts index 07a5d7996d3..f42c362fc74 100644 --- a/server/sonar-web/src/main/js/api/users.ts +++ b/server/sonar-web/src/main/js/api/users.ts @@ -19,6 +19,13 @@ */ import { getJSON, post, RequestData } from '../helpers/request'; +export interface IdentityProvider { + backgroundColor: string; + iconPath: string; + key: string; + name: string; +} + export function getCurrentUser(): Promise { return getJSON('/api/users/current'); } @@ -43,7 +50,7 @@ export function getUserGroups(login: string, organization?: string): Promise { +export function getIdentityProviders(): Promise<{ identityProviders: IdentityProvider[] }> { return getJSON('/api/users/identity_providers'); } diff --git a/server/sonar-web/src/main/js/app/components/SimpleContainer.js b/server/sonar-web/src/main/js/app/components/SimpleContainer.js deleted file mode 100644 index 02596356d31..00000000000 --- a/server/sonar-web/src/main/js/app/components/SimpleContainer.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import GlobalFooterContainer from './GlobalFooterContainer'; -import NavBar from '../../components/nav/NavBar'; - -/*:: -type Props = { - children?: React.Element<*> | Array>, - hideLoggedInInfo?: boolean -}; -*/ - -export default class SimpleContainer extends React.PureComponent { - /*:: props: Props; */ - - componentDidMount() { - const html = document.querySelector('html'); - if (html) { - html.classList.add('dashboard-page'); - } - } - - componentWillUnmount() { - const html = document.querySelector('html'); - if (html) { - html.classList.remove('dashboard-page'); - } - } - - render() { - return ( -
-
- - -
-
- {this.props.children} -
-
-
- -
- ); - } -} diff --git a/server/sonar-web/src/main/js/app/components/SimpleContainer.tsx b/server/sonar-web/src/main/js/app/components/SimpleContainer.tsx new file mode 100644 index 00000000000..51c4336afde --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/SimpleContainer.tsx @@ -0,0 +1,60 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import GlobalFooterContainer from './GlobalFooterContainer'; +import NavBar from '../../components/nav/NavBar'; + +interface Props { + children?: React.ReactNode; + hideLoggedInInfo?: boolean; +} + +export default class SimpleContainer extends React.PureComponent { + componentDidMount() { + const html = document.querySelector('html'); + if (html) { + html.classList.add('dashboard-page'); + } + } + + componentWillUnmount() { + const html = document.querySelector('html'); + if (html) { + html.classList.remove('dashboard-page'); + } + } + + render() { + return ( +
+
+ + +
+
+ {this.props.children} +
+
+
+ +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.js b/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.js deleted file mode 100644 index 4ae970f2481..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.js +++ /dev/null @@ -1,140 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import OAuthProviders from './OAuthProviders'; -import GlobalMessagesContainer from '../../../app/components/GlobalMessagesContainer'; -import { translate } from '../../../helpers/l10n'; - -/*:: -type Props = { - identityProviders: Array<{ - backgroundColor: string, - iconPath: string, - key: string, - name: string - }>, - onSubmit: (string, string) => void -}; -*/ - -/*:: -type State = { - collapsed: boolean, - login: string, - password: string -}; -*/ - -export default class LoginForm extends React.PureComponent { - /*:: props: Props; */ - /*:: state: State; */ - - constructor(props /*: Props */) { - super(props); - this.state = { - collapsed: props.identityProviders.length > 0, - login: '', - password: '' - }; - } - - handleSubmit = (event /*: Event */) => { - event.preventDefault(); - this.props.onSubmit(this.state.login, this.state.password); - }; - - handleMoreOptionsClick = (event /*: Event */) => { - event.preventDefault(); - this.setState({ collapsed: false }); - }; - - render() { - return ( -
-

{translate('login.login_to_sonarqube')}

- - {this.props.identityProviders.length > 0 && ( - - )} - - {this.state.collapsed ? ( - - ) : ( -
- - -
- - this.setState({ login: e.target.value })} - /> -
- -
- - this.setState({ password: e.target.value })} - /> -
- -
-
- - - {translate('cancel')} - -
-
- - )} -
- ); - } -} 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 new file mode 100644 index 00000000000..362e7f86dba --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx @@ -0,0 +1,135 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { Link } from 'react-router'; +import OAuthProviders from './OAuthProviders'; +import GlobalMessagesContainer from '../../../app/components/GlobalMessagesContainer'; +import { translate } from '../../../helpers/l10n'; +import { IdentityProvider } from '../../../api/users'; + +interface Props { + identityProviders: IdentityProvider[]; + onSubmit: (login: string, password: string) => void; +} + +interface State { + collapsed: boolean; + login: string; + password: string; +} + +export default class LoginForm extends React.PureComponent { + constructor(props: Props) { + super(props); + this.state = { + collapsed: props.identityProviders.length > 0, + login: '', + password: '' + }; + } + + handleSubmit = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.props.onSubmit(this.state.login, this.state.password); + }; + + handleMoreOptionsClick = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.setState({ collapsed: false }); + }; + + handleLoginChange = (event: React.SyntheticEvent) => + this.setState({ login: event.currentTarget.value }); + + handlePwdChange = (event: React.SyntheticEvent) => + this.setState({ password: event.currentTarget.value }); + + render() { + return ( +
+

{translate('login.login_to_sonarqube')}

+ + {this.props.identityProviders.length > 0 && ( + + )} + + {this.state.collapsed ? ( + + ) : ( +
+ + +
+ + +
+ +
+ + +
+ +
+
+ + + {translate('cancel')} + +
+
+ + )} +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.js b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.js deleted file mode 100644 index fe2197fdf6f..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.js +++ /dev/null @@ -1,81 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import PropTypes from 'prop-types'; -import { connect } from 'react-redux'; -import LoginForm from './LoginForm'; -import { doLogin } from '../../../store/rootActions'; -import { getAppState } from '../../../store/rootReducer'; -import { getIdentityProviders } from '../../../api/users'; - -class LoginFormContainer extends React.PureComponent { - /*:: mounted: boolean; */ - - static propTypes = { - location: PropTypes.object.isRequired - }; - - state = {}; - - componentDidMount() { - this.mounted = true; - getIdentityProviders().then(r => { - if (this.mounted) { - this.setState({ identityProviders: r.identityProviders }); - } - }); - } - - componentWillUnmount() { - this.mounted = false; - } - - handleSuccessfulLogin = () => { - const { location } = this.props; - const queryReturnTo = location.query['return_to']; - const returnTo = queryReturnTo ? `${queryReturnTo}${location.hash}` : `${window.baseUrl}/`; - window.location = returnTo; - }; - - handleSubmit = (login /*: string */, password /*: string */) => { - this.props.doLogin(login, password).then(this.handleSuccessfulLogin, () => { - /* do nothing */ - }); - }; - - render() { - if (!this.state.identityProviders) { - return null; - } - - return ( - - ); - } -} - -const mapStateToProps = state => ({ - appState: getAppState(state) -}); - -const mapDispatchToProps = { doLogin }; - -export default connect(mapStateToProps, mapDispatchToProps)(LoginFormContainer); 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 new file mode 100644 index 00000000000..2c2152bb61b --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx @@ -0,0 +1,82 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +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 { IdentityProvider, getIdentityProviders } from '../../../api/users'; +import { getBaseUrl } from '../../../helpers/urls'; + +interface Props { + doLogin: (login: string, password: string) => Promise; + location: { hash?: string; pathName: string; query: { return_to?: string } }; +} + +interface State { + identityProviders?: IdentityProvider[]; +} + +class LoginFormContainer extends React.PureComponent { + mounted: boolean; + state: State = {}; + + componentDidMount() { + this.mounted = true; + getIdentityProviders().then(r => { + if (this.mounted) { + this.setState({ identityProviders: r.identityProviders }); + } + }); + } + + componentWillUnmount() { + this.mounted = false; + } + + handleSuccessfulLogin = () => { + const { location } = this.props; + const queryReturnTo = location.query['return_to']; + const returnTo = queryReturnTo ? `${queryReturnTo}${location.hash}` : `${getBaseUrl()}/`; + window.location.href = returnTo; + }; + + handleSubmit = (login: string, password: string) => { + this.props.doLogin(login, password).then(this.handleSuccessfulLogin, () => {}); + }; + + render() { + if (!this.state.identityProviders) { + return null; + } + + return ( + + ); + } +} + +const mapStateToProps = (state: any) => ({ + appState: getAppState(state) +}); + +const mapDispatchToProps = { doLogin }; + +export default connect(mapStateToProps, mapDispatchToProps)(LoginFormContainer as any); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/Logout.js b/server/sonar-web/src/main/js/apps/sessions/components/Logout.js deleted file mode 100644 index 736c4cc6372..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/Logout.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import { connect } from 'react-redux'; -import GlobalMessagesContainer from '../../../app/components/GlobalMessagesContainer'; -import { doLogout } from '../../../store/rootActions'; -import { translate } from '../../../helpers/l10n'; -import RecentHistory from '../../../app/components/RecentHistory'; - -class Logout extends React.PureComponent { - componentDidMount() { - this.props - .doLogout() - .then(() => { - RecentHistory.clear(); - window.location = window.baseUrl + '/'; - }) - .catch(() => { - /* do nothing */ - }); - } - - render() { - return ( -
- - {translate('logging_out')} -
- ); - } -} - -const mapStateToProps = () => ({}); - -const mapDispatchToProps = { doLogout }; - -export default connect(mapStateToProps, mapDispatchToProps)(Logout); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/Logout.tsx b/server/sonar-web/src/main/js/apps/sessions/components/Logout.tsx new file mode 100644 index 00000000000..b90ff4c42ae --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/Logout.tsx @@ -0,0 +1,57 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { connect } from 'react-redux'; +import GlobalMessagesContainer from '../../../app/components/GlobalMessagesContainer'; +import RecentHistory from '../../../app/components/RecentHistory'; +import { doLogout } from '../../../store/rootActions'; +import { translate } from '../../../helpers/l10n'; +import { getBaseUrl } from '../../../helpers/urls'; + +interface Props { + doLogout: () => Promise; +} + +class Logout extends React.PureComponent { + componentDidMount() { + this.props.doLogout().then( + () => { + RecentHistory.clear(); + window.location.href = getBaseUrl() + '/'; + }, + () => {} + ); + } + + render() { + return ( +
+ + {translate('logging_out')} +
+ ); + } +} + +const mapStateToProps = () => ({}); + +const mapDispatchToProps = { doLogout }; + +export default connect(mapStateToProps, mapDispatchToProps)(Logout as any); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.js b/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.js deleted file mode 100644 index d06a2019558..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import { translateWithParameters } from '../../../helpers/l10n'; - -/*:: -type Props = { - formatLabel?: string => string, - identityProviders: Array<{ - backgroundColor: string, - iconPath: string, - key: string, - name: string - }> -}; -*/ - -export default function OAuthProviders(props /*: Props */) { - return ( -
- -
- ); -} - -OAuthProviders.defaultProps = { - formatLabel: (name /*: string */) => translateWithParameters('login.login_with_x', name) -}; 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 new file mode 100644 index 00000000000..973f8b31021 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx @@ -0,0 +1,58 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { translateWithParameters } from '../../../helpers/l10n'; +import { IdentityProvider } from '../../../api/users'; +import { getBaseUrl } from '../../../helpers/urls'; + +interface Props { + formatLabel?: (name: string) => string; + identityProviders: IdentityProvider[]; +} + +export default function OAuthProviders(props: Props) { + const formatLabel = props.formatLabel || defaultFormatLabel; + return ( +
+ +
+ ); +} + +function defaultFormatLabel(name: string) { + return translateWithParameters('login.login_with_x', name); +} diff --git a/server/sonar-web/src/main/js/apps/sessions/components/SimpleSessionsContainer.js b/server/sonar-web/src/main/js/apps/sessions/components/SimpleSessionsContainer.js deleted file mode 100644 index 29efdcd38a9..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/SimpleSessionsContainer.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import SimpleContainer from '../../../app/components/SimpleContainer'; - -/*:: -type Props = { - children?: React.Element<*> | Array> -}; -*/ - -export default function SimpleSessionsContainer({ children } /*: Props */) { - return {children}; -} diff --git a/server/sonar-web/src/main/js/apps/sessions/components/SimpleSessionsContainer.tsx b/server/sonar-web/src/main/js/apps/sessions/components/SimpleSessionsContainer.tsx new file mode 100644 index 00000000000..b29c1e494ee --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/SimpleSessionsContainer.tsx @@ -0,0 +1,29 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import SimpleContainer from '../../../app/components/SimpleContainer'; + +interface Props { + children?: React.ReactElement; +} + +export default function SimpleSessionsContainer({ children }: Props) { + return {children}; +} diff --git a/server/sonar-web/src/main/js/apps/sessions/components/Unauthorized.tsx b/server/sonar-web/src/main/js/apps/sessions/components/Unauthorized.tsx index 12bc8b8724c..cb12caa296e 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/Unauthorized.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/Unauthorized.tsx @@ -19,6 +19,7 @@ */ import * as React from 'react'; import { Link } from 'react-router'; +import { translate } from '../../../helpers/l10n'; interface Props { location: { @@ -33,14 +34,16 @@ export default function Unauthorized(props: Props) { return (
-

- {"You're not authorized to access this page. Please contact the administrator."} -

+

{translate('unauthorized.message')}

- {!!message &&

Reason : {message}

} + {!!message && ( +

+ {translate('unauthorized.reason')} {message} +

+ )}
- Home + {translate('layout.home')}
); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.js b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.js deleted file mode 100644 index 6eea8123a99..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.js +++ /dev/null @@ -1,60 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import React from 'react'; -import { shallow } from 'enzyme'; -import LoginForm from '../LoginForm'; -import { change, click, submit } from '../../../../helpers/testUtils'; - -const identityProvider = { - backgroundColor: '#000', - iconPath: '/some/path', - key: 'foo', - name: 'foo' -}; - -it('logs in with simple credentials', () => { - const onSubmit = jest.fn(); - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - - change(wrapper.find('#login'), 'admin'); - change(wrapper.find('#password'), 'admin'); - submit(wrapper.find('form')); - - expect(onSubmit).toBeCalledWith('admin', 'admin'); -}); - -it('logs in with identity provider', () => { - const wrapper = shallow( - - ); - expect(wrapper).toMatchSnapshot(); -}); - -it('expands more options', () => { - const wrapper = shallow( - - ); - expect(wrapper).toMatchSnapshot(); - - click(wrapper.find('.js-more-options')); - expect(wrapper).toMatchSnapshot(); -}); 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 new file mode 100644 index 00000000000..47f1add3ed3 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import { shallow } from 'enzyme'; +import LoginForm from '../LoginForm'; +import { change, click, submit } from '../../../../helpers/testUtils'; + +const identityProvider = { + backgroundColor: '#000', + iconPath: '/some/path', + key: 'foo', + name: 'foo' +}; + +it('logs in with simple credentials', () => { + const onSubmit = jest.fn(); + const wrapper = shallow(); + expect(wrapper).toMatchSnapshot(); + + change(wrapper.find('#login'), 'admin'); + change(wrapper.find('#password'), 'admin'); + submit(wrapper.find('form')); + + expect(onSubmit).toBeCalledWith('admin', 'admin'); +}); + +it('logs in with identity provider', () => { + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); +}); + +it('expands more options', () => { + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + + click(wrapper.find('.js-more-options')); + expect(wrapper).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.js.snap b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.js.snap deleted file mode 100644 index 42113f43dc0..00000000000 --- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.js.snap +++ /dev/null @@ -1,240 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`expands more options 1`] = ` -
-

- login.login_to_sonarqube -

- - -
-`; - -exports[`expands more options 2`] = ` -
-

- login.login_to_sonarqube -

- -
- -
- - -
-
- - -
-
-
- - - cancel - -
-
- -
-`; - -exports[`logs in with identity provider 1`] = ` -
-

- login.login_to_sonarqube -

- - -
-`; - -exports[`logs in with simple credentials 1`] = ` -
-

- login.login_to_sonarqube -

-
- -
- - -
-
- - -
-
-
- - - cancel - -
-
- -
-`; 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 new file mode 100644 index 00000000000..295059922ee --- /dev/null +++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap @@ -0,0 +1,241 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`expands more options 1`] = ` +
+

+ login.login_to_sonarqube +

+ + +
+`; + +exports[`expands more options 2`] = ` +
+

+ login.login_to_sonarqube +

+ +
+ +
+ + +
+
+ + +
+
+
+ + + cancel + +
+
+ +
+`; + +exports[`logs in with identity provider 1`] = ` +
+

+ login.login_to_sonarqube +

+ + +
+`; + +exports[`logs in with simple credentials 1`] = ` +
+

+ login.login_to_sonarqube +

+
+ +
+ + +
+
+ + +
+
+
+ + + cancel + +
+
+ +
+`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 13443aa12e9..60cec37405f 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1350,6 +1350,9 @@ login.login_to_sonarqube=Log In to SonarQube login.more_options=More options login.login_with_x=Log in with {0} +unauthorized.message=You're not authorized to access this page. Please contact the administrator. +unauthorized.reason=Reason: + #------------------------------------------------------------------------------ # # USERS & GROUPS PAGE diff --git a/tests/src/test/resources/user/BaseIdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html b/tests/src/test/resources/user/BaseIdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html index b62763fb7c9..d202404dfd1 100644 --- a/tests/src/test/resources/user/BaseIdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html +++ b/tests/src/test/resources/user/BaseIdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html @@ -36,7 +36,7 @@ assertText bd - *Reason : A functional error has happened* + *Reason: A functional error has happened* diff --git a/tests/src/test/resources/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html b/tests/src/test/resources/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html index 40c300bd701..ddf1b837078 100644 --- a/tests/src/test/resources/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html +++ b/tests/src/test/resources/user/BaseIdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html @@ -31,7 +31,7 @@ waitForText bd - *You're not authorized to access this page. Please contact the administrator.*Reason : 'fake-base-id-provider' users are not allowed to sign up* + *You're not authorized to access this page. Please contact the administrator.*Reason: 'fake-base-id-provider' users are not allowed to sign up* diff --git a/tests/src/test/resources/user/OAuth2IdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html b/tests/src/test/resources/user/OAuth2IdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html index 6a38ed69063..a78424c7a91 100644 --- a/tests/src/test/resources/user/OAuth2IdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html +++ b/tests/src/test/resources/user/OAuth2IdentityProviderTest/display_message_in_ui_but_not_in_log_when_unauthorized_exception.html @@ -36,7 +36,7 @@ assertText bd - *Reason : A functional error has happened* + *Reason: A functional error has happened* diff --git a/tests/src/test/resources/user/OAuth2IdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html b/tests/src/test/resources/user/OAuth2IdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html index a3da2de8ed0..addc1e7818b 100644 --- a/tests/src/test/resources/user/OAuth2IdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html +++ b/tests/src/test/resources/user/OAuth2IdentityProviderTest/fail_to_authenticate_when_not_allowed_to_sign_up.html @@ -31,7 +31,7 @@ waitForText bd - *You're not authorized to access this page. Please contact the administrator.*Reason : 'fake-oauth2-id-provider' users are not allowed to sign up* + *You're not authorized to access this page. Please contact the administrator.*Reason: 'fake-oauth2-id-provider' users are not allowed to sign up*