Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1957. Role filter for create new map #1958

Merged
merged 3 commits into from
Jun 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions web/client/plugins/CreateNewMap.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const PropTypes = require('prop-types');
/**
/*
* Copyright 2016, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const React = require('react');
const PropTypes = require('prop-types');
const {connect} = require('react-redux');

const {Button, Grid, Col} = require('react-bootstrap');
Expand All @@ -18,7 +18,9 @@ class CreateNewMap extends React.Component {
mapType: PropTypes.string,
onGoToMap: PropTypes.func,
colProps: PropTypes.object,
isLoggedIn: PropTypes.bool
isLoggedIn: PropTypes.bool,
allowedRoles: PropTypes.array,
user: PropTypes.object
};

static contextTypes = {
Expand All @@ -28,6 +30,7 @@ class CreateNewMap extends React.Component {
static defaultProps = {
mapType: "leaflet",
isLoggedIn: false,
allowedRoles: ["ADMIN", "USER"],
onGoToMap: () => {},
colProps: {
xs: 12,
Expand All @@ -36,9 +39,8 @@ class CreateNewMap extends React.Component {
md: 12
}
};

render() {
const display = this.props.isLoggedIn ? null : "none";
const display = this.isAllowed() ? null : "none";
return (<Grid fluid style={{marginBottom: "30px", padding: 0, display}}>
<Col {...this.props.colProps} >
<Button bsStyle="primary" onClick={() => { this.context.router.history.push("/viewer/" + this.props.mapType + "/new"); }}>
Expand All @@ -47,11 +49,13 @@ class CreateNewMap extends React.Component {
</Col>
</Grid>);
}
isAllowed = () => this.props.isLoggedIn && this.props.allowedRoles.indexOf(this.props.user && this.props.user.role) >= 0;
}

module.exports = {
CreateNewMapPlugin: connect((state) => ({
mapType: state.maps && state.maps.mapType || state.home && state.home.mapType,
isLoggedIn: state && state.security && state.security.user && state.security.user.enabled && true || false
isLoggedIn: state && state.security && state.security.user && state.security.user.enabled && true || false,
user: state && state.security && state.security.user
}))(CreateNewMap)
};