Skip to content

Commit

Permalink
Merge branch 'gsa-8.0' into tooltip_time_format_gsa8
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahd93 authored May 9, 2019
2 parents cbd20b0 + f119368 commit d5847be
Show file tree
Hide file tree
Showing 20 changed files with 691 additions and 225 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add tooltips to deactivated text fields in AlertDialog [#1269](https://github.com/greenbone/gsa/pull/1269)

### Changed
- Don't allow to verify predefined report formats [#1378](https://github.com/greenbone/gsa/pull/1378)
- Avoid storing config.js in browser cache [#1372](https://github.com/greenbone/gsa/pull/1372)
- Display data loading errors at list pages [#1349](https://github.com/greenbone/gsa/pull/1349)
- Improve login page [#1347](https://github.com/greenbone/gsa/pull/1347)
Expand All @@ -40,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Fixed
- Fix scheduled task tooltip time format [#1382](https://github.com/greenbone/gsa/pull/1382)
- Fix updating Titlebar after session timeout [#1377](https://github.com/greenbone/gsa/pull/1377)
- Use German manual for *DE* locale [#1372](https://github.com/greenbone/gsa/pull/1372)
- Load all container tasks for report import dialog from redux store [#1370](https://github.com/greenbone/gsa/pull/1370)
- Don't render *Invalid Date* [#1368](https://github.com/greenbone/gsa/pull/1368)
Expand Down
1 change: 1 addition & 0 deletions gsa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ set (GSA_JS_SRC_FILES
${GSA_SRC_DIR}/src/web/entity/icon/editicon.js
${GSA_SRC_DIR}/src/web/entity/icon/observericon.js
${GSA_SRC_DIR}/src/web/entity/icon/trashicon.js
${GSA_SRC_DIR}/src/web/entity/icon/verifyicon.js
${GSA_SRC_DIR}/src/web/entity/info.js
${GSA_SRC_DIR}/src/web/entity/link.js
${GSA_SRC_DIR}/src/web/entity/note.js
Expand Down
7 changes: 6 additions & 1 deletion gsa/src/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ import LocaleObserver from 'web/components/observer/localeobserver';

import GmpProvider from 'web/components/provider/gmpprovider';

import {setUsername, setTimezone} from 'web/store/usersettings/actions';
import {
setUsername,
setTimezone,
setIsLoggedIn,
} from 'web/store/usersettings/actions';

import globalcss from 'web/utils/globalcss';

Expand Down Expand Up @@ -65,6 +69,7 @@ const initStore = () => {
if (isDefined(username)) {
store.dispatch(setUsername(username));
}
store.dispatch(setIsLoggedIn(gmp.isLoggedIn()));
};

class App extends React.Component {
Expand Down
59 changes: 44 additions & 15 deletions gsa/src/web/authorized.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
*/
import React from 'react';

import {connect} from 'react-redux';

import {withRouter} from 'react-router-dom';

import {isDefined} from 'gmp/utils/identity';

import {setIsLoggedIn} from './store/usersettings/actions';
import {isLoggedIn} from 'web/store/usersettings/selectors';

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import withGmp from 'web/utils/withGmp';
Expand All @@ -39,6 +44,8 @@ class Authorized extends React.Component {
this.responseError = this.responseError.bind(this);

this.unsubscribe = gmp.addHttpErrorHandler(this.responseError);

this.checkIsLoggedIn();
}

componentWillUnmount() {
Expand All @@ -47,48 +54,70 @@ class Authorized extends React.Component {
}
}

componentDidUpdate() {
this.checkIsLoggedIn();
}

responseError(xhr) {
const {location} = this.props;
const {logout} = this.props;

if (xhr.status === 401 && location.pathname !== '/login') {
this.toLoginPage();
if (xhr.status === 401) {
logout();
return Promise.resolve(xhr);
}
return Promise.reject(xhr);
}

checkIsLoggedIn() {
if (!this.props.isLoggedIn) {
this.toLoginPage();
}
}

toLoginPage() {
const {gmp, history} = this.props;
const {history, location} = this.props;

if (location.pathname === '/login') {
// already at login page
return;
}

history.replace('/login', {
next: this.props.location.pathname,
});

gmp.logout();
}

render() {
const {gmp} = this.props;

if (gmp.isLoggedIn()) {
return this.props.children;
}

this.toLoginPage();

return null;
return this.props.isLoggedIn ? this.props.children : null;
}
}

Authorized.propTypes = {
gmp: PropTypes.gmp.isRequired,
history: PropTypes.object.isRequired,
isLoggedIn: PropTypes.bool.isRequired,
location: PropTypes.object.isRequired,
logout: PropTypes.func.isRequired,
};

const mapStateToProps = rootState => ({
isLoggedIn: isLoggedIn(rootState),
});

const mapDispatchToProps = (dispatch, {gmp}) => ({
logout: () => {
gmp.logout();
dispatch(setIsLoggedIn(false));
},
});

export default compose(
withGmp,
withRouter,
connect(
mapStateToProps,
mapDispatchToProps,
),
)(Authorized);

// vim: set ts=2 sw=2 tw=80:
16 changes: 9 additions & 7 deletions gsa/src/web/components/bar/__tests__/titlebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,40 @@ import React from 'react';
import {rendererWith} from 'web/utils/testing';

import Titlebar from '../titlebar';
import {setUsername} from 'web/store/usersettings/actions';
import {setIsLoggedIn, setUsername} from 'web/store/usersettings/actions';

import {setLocale} from 'gmp/locale/lang';

setLocale('en');

describe('Titlebar tests', () => {
test('should render content if user is logged in', () => {
const isLoggedIn = jest.fn().mockReturnValue(true);
const gmp = {isLoggedIn, settings: {vendorVersion: ''}};
const gmp = {settings: {vendorVersion: ''}};

const {render, store} = rendererWith({gmp, router: true, store: true});

store.dispatch(setUsername('username'));
store.dispatch(setIsLoggedIn(true));

const {baseElement} = render(<Titlebar />);

expect(baseElement).toMatchSnapshot();
expect(isLoggedIn).toHaveBeenCalled();
const links = baseElement.querySelectorAll('a');
expect(links[1]).toHaveTextContent('username');
expect(baseElement).not.toHaveTextContent('Vendor Version');
});

test('should not render content if user is logged out', () => {
const isLoggedIn = jest.fn().mockReturnValue(false);
const gmp = {isLoggedIn, settings: {vendorVersion: 'Vendor Version'}};
const gmp = {settings: {vendorVersion: 'Vendor Version'}};

const {render, store} = rendererWith({gmp, router: true, store: true});

store.dispatch(setUsername('username'));
store.dispatch(setIsLoggedIn(false));

const {baseElement} = render(<Titlebar />);

expect(baseElement).toMatchSnapshot();
expect(isLoggedIn).toHaveBeenCalled();
expect(baseElement).not.toHaveTextContent('username');
expect(baseElement).toHaveTextContent('Vendor Version');
});
Expand Down
28 changes: 19 additions & 9 deletions gsa/src/web/components/bar/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@
*/
import React from 'react';

import {connect} from 'react-redux';

import styled from 'styled-components';

import _ from 'gmp/locale';

import {isDefined} from 'gmp/utils/identity';

import PropTypes from 'web/utils/proptypes';
import withGmp from 'web/utils/withGmp';
import withCapabilities from 'web/utils/withCapabilities';
import compose from 'web/utils/compose';

import Theme from 'web/utils/theme';

import Layout from 'web/components/layout/layout';

import Menu from 'web/components/menu/menu';
import MenuEntry from 'web/components/menu/menuentry';
import MenuHelpEntry from 'web/components/menu/menuhelpentry';
import MenuSection from 'web/components/menu/menusection';

import {isLoggedIn} from 'web/store/usersettings/selectors';

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import Theme from 'web/utils/theme';
import withGmp from 'web/utils/withGmp';
import withCapabilities from 'web/utils/withCapabilities';

const MENU_BAR_HEIGHT = '35px';

const Ul = styled.ul`
Expand All @@ -63,8 +66,9 @@ const MenuBarPlaceholder = styled.div`
height: ${MENU_BAR_HEIGHT};
`;

const MenuBar = ({gmp, capabilities}) => {
if (!gmp.isLoggedIn() || !isDefined(capabilities)) {
// eslint-disable-next-line no-shadow
const MenuBar = ({isLoggedIn, capabilities}) => {
if (!isLoggedIn || !isDefined(capabilities)) {
return null;
}

Expand Down Expand Up @@ -276,11 +280,17 @@ const MenuBar = ({gmp, capabilities}) => {
MenuBar.propTypes = {
capabilities: PropTypes.capabilities,
gmp: PropTypes.gmp.isRequired,
isLoggedIn: PropTypes.bool.isRequired,
};

const mapStateToProps = rootState => ({
isLoggedIn: isLoggedIn(rootState),
});

export default compose(
withCapabilities,
withGmp,
connect(mapStateToProps),
)(MenuBar);

// vim: set ts=2 sw=2 tw=80:
12 changes: 11 additions & 1 deletion gsa/src/web/components/bar/titlebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import React from 'react';

import {connect} from 'react-redux';

import {withRouter} from 'react-router-dom';

import styled from 'styled-components';
Expand All @@ -34,6 +36,8 @@ import Layout from 'web/components/layout/layout';
import Link from 'web/components/link/link';
import UserLink from 'web/components/link/userlink';

import {isLoggedIn} from 'web/store/usersettings/selectors';

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import Theme from 'web/utils/theme';
Expand Down Expand Up @@ -114,7 +118,7 @@ class Titlebar extends React.Component {
<React.Fragment>
<TitlebarPlaceholder />
<TitlebarLayout>
{gmp.isLoggedIn() ? (
{this.props.isLoggedIn ? (
<React.Fragment>
<Link to="/" title={_('Dashboard')}>
<Greenbone />
Expand Down Expand Up @@ -143,11 +147,17 @@ class Titlebar extends React.Component {
Titlebar.propTypes = {
gmp: PropTypes.gmp.isRequired,
history: PropTypes.object.isRequired,
isLoggedIn: PropTypes.bool.isRequired,
};

const mapStateToProps = rootState => ({
isLoggedIn: isLoggedIn(rootState),
});

export default compose(
withGmp,
withRouter,
connect(mapStateToProps),
)(Titlebar);

// vim: set ts=2 sw=2 tw=80:
2 changes: 2 additions & 0 deletions gsa/src/web/components/observer/sessionobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Ping extends React.Component {
log.debug('clearing ping timer', this.timer);

global.clearTimeout(this.timer);

this.timer = undefined;
}
}

Expand Down
Loading

0 comments on commit d5847be

Please sign in to comment.