When user removed from private org, log them out

Signed-off-by: Jared Scheib <jared.scheib@gmail.com>
pull/2399/head
Luke Morris 2017-12-06 17:53:30 -08:00 committed by Jared Scheib
parent 236a62f911
commit 64962bb1db
1 changed files with 98 additions and 102 deletions

View File

@ -1,4 +1,4 @@
import React, {PropTypes} from 'react' import React, {PropTypes, Component} from 'react'
import {connect} from 'react-redux' import {connect} from 'react-redux'
import {bindActionCreators} from 'redux' import {bindActionCreators} from 'redux'
import {withRouter} from 'react-router' import {withRouter} from 'react-router'
@ -22,19 +22,32 @@ const handleClickLogin = props => organization => async e => {
router.push('') router.push('')
} }
const Purgatory = ({ class Purgatory extends Component {
componentWillUpdate() {
const {router, me} = this.props
if (me === null) {
router.push('/login')
}
}
render() {
const {me, meChangeOrganization, logoutLink, router, links} = this.props
if (me === null) {
return null
}
const {
name, name,
provider, provider,
scheme, scheme,
currentOrganization, currentOrganization,
meChangeOrganization,
roles, roles,
organizations, organizations,
logoutLink,
router,
links,
superAdmin, superAdmin,
}) => { } = me
const rolesAndOrgs = organizations.map(organization => ({ const rolesAndOrgs = organizations.map(organization => ({
organization, organization,
role: getRoleNameByOrgID(organization.id, roles), role: getRoleNameByOrgID(organization.id, roles),
@ -84,6 +97,7 @@ const Purgatory = ({
</div> </div>
) )
} }
}
const {arrayOf, bool, func, shape, string} = PropTypes const {arrayOf, bool, func, shape, string} = PropTypes
@ -94,6 +108,7 @@ Purgatory.propTypes = {
links: shape({ links: shape({
me: string, me: string,
}), }),
me: shape({
name: string.isRequired, name: string.isRequired,
provider: string.isRequired, provider: string.isRequired,
scheme: string.isRequired, scheme: string.isRequired,
@ -113,35 +128,16 @@ Purgatory.propTypes = {
name: string, name: string,
}) })
).isRequired, ).isRequired,
logoutLink: string.isRequired,
meChangeOrganization: func.isRequired,
superAdmin: bool, superAdmin: bool,
}),
logoutLink: string,
meChangeOrganization: func.isRequired,
} }
const mapStateToProps = ({ const mapStateToProps = ({links, auth: {me, logoutLink}}) => ({
links, links,
auth: {
me: {
name,
provider,
scheme,
currentOrganization,
roles,
organizations,
superAdmin,
},
logoutLink, logoutLink,
}, me,
}) => ({
links,
name,
provider,
scheme,
currentOrganization,
roles,
organizations,
logoutLink,
superAdmin,
}) })
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({