Skip to content

Commit

Permalink
Fix #1957. Role filter for create new map
Browse files Browse the repository at this point in the history
Fix #1957. Now you can confiure the plugin to display only for the allowedRoles in configuration
  • Loading branch information
offtherailz committed Jun 23, 2017
1 parent a790299 commit eb5305c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions web/client/plugins/CreateNewMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ const CreateNewMap = React.createClass({
mapType: React.PropTypes.string,
onGoToMap: React.PropTypes.func,
colProps: React.PropTypes.object,
isLoggedIn: React.PropTypes.bool
isLoggedIn: React.PropTypes.bool,
allowedRoles: React.PropTypes.array,
user: React.PropTypes.object
},
contextTypes: {
router: React.PropTypes.object
},
getDefaultProps() {
return {
mapType: "leaflet",
allowedRoles: ["ADMIN", "USER"],
isLoggedIn: false,
onGoToMap: () => {},
colProps: {
Expand All @@ -35,22 +38,27 @@ const CreateNewMap = React.createClass({
}
};
},

render() {
const display = this.props.isLoggedIn ? null : "none";
const display = this.isAllowed() ? null : "none";

return (<Grid fluid={true} style={{marginBottom: "30px", padding: 0, display}}>
<Col {...this.props.colProps} >
<Button bsStyle="primary" onClick={() => { this.context.router.push("/viewer/" + this.props.mapType + "/new"); }}>
<Message msgId="newMap" />
</Button>
</Col>
</Grid>);
},
isAllowed() {
return 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)
};

0 comments on commit eb5305c

Please sign in to comment.