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 {bindActionCreators} from 'redux'
import {withRouter} from 'react-router'
@ -22,67 +22,81 @@ const handleClickLogin = props => organization => async e => {
router.push('')
}
const Purgatory = ({
name,
provider,
scheme,
currentOrganization,
meChangeOrganization,
roles,
organizations,
logoutLink,
router,
links,
superAdmin,
}) => {
const rolesAndOrgs = organizations.map(organization => ({
organization,
role: getRoleNameByOrgID(organization.id, roles),
currentOrganization: organization.id === currentOrganization.id,
}))
class Purgatory extends Component {
componentWillUpdate() {
const {router, me} = this.props
const subHeading =
rolesAndOrgs.length === 1
? 'Authenticated in 1 Organization'
: `Authenticated in ${rolesAndOrgs.length} Organizations`
if (me === null) {
router.push('/login')
}
}
return (
<div>
<Notifications />
<SplashPage>
<div className="auth--purgatory">
<h3>
{name}
</h3>
<h6>
{subHeading}{' '}
<code>
{scheme}/{provider}
</code>
</h6>
{rolesAndOrgs.length
? <div className="auth--list">
{rolesAndOrgs.map((rag, i) =>
<PurgatoryAuthItem
key={i}
roleAndOrg={rag}
superAdmin={superAdmin}
onClickLogin={handleClickLogin({
router,
links,
meChangeOrganization,
})}
/>
)}
</div>
: <p>You are a Lost Soul</p>}
<a href={logoutLink} className="btn btn-sm btn-link auth--logout">
Logout
</a>
</div>
</SplashPage>
</div>
)
render() {
const {me, meChangeOrganization, logoutLink, router, links} = this.props
if (me === null) {
return null
}
const {
name,
provider,
scheme,
currentOrganization,
roles,
organizations,
superAdmin,
} = me
const rolesAndOrgs = organizations.map(organization => ({
organization,
role: getRoleNameByOrgID(organization.id, roles),
currentOrganization: organization.id === currentOrganization.id,
}))
const subHeading =
rolesAndOrgs.length === 1
? 'Authenticated in 1 Organization'
: `Authenticated in ${rolesAndOrgs.length} Organizations`
return (
<div>
<Notifications />
<SplashPage>
<div className="auth--purgatory">
<h3>
{name}
</h3>
<h6>
{subHeading}{' '}
<code>
{scheme}/{provider}
</code>
</h6>
{rolesAndOrgs.length
? <div className="auth--list">
{rolesAndOrgs.map((rag, i) =>
<PurgatoryAuthItem
key={i}
roleAndOrg={rag}
superAdmin={superAdmin}
onClickLogin={handleClickLogin({
router,
links,
meChangeOrganization,
})}
/>
)}
</div>
: <p>You are a Lost Soul</p>}
<a href={logoutLink} className="btn btn-sm btn-link auth--logout">
Logout
</a>
</div>
</SplashPage>
</div>
)
}
}
const {arrayOf, bool, func, shape, string} = PropTypes
@ -94,54 +108,36 @@ Purgatory.propTypes = {
links: shape({
me: string,
}),
name: string.isRequired,
provider: string.isRequired,
scheme: string.isRequired,
currentOrganization: shape({
id: string.isRequired,
me: shape({
name: string.isRequired,
}).isRequired,
roles: arrayOf(
shape({
name: string,
organization: string,
})
).isRequired,
organizations: arrayOf(
shape({
id: string,
name: string,
})
).isRequired,
logoutLink: string.isRequired,
provider: string.isRequired,
scheme: string.isRequired,
currentOrganization: shape({
id: string.isRequired,
name: string.isRequired,
}).isRequired,
roles: arrayOf(
shape({
name: string,
organization: string,
})
).isRequired,
organizations: arrayOf(
shape({
id: string,
name: string,
})
).isRequired,
superAdmin: bool,
}),
logoutLink: string,
meChangeOrganization: func.isRequired,
superAdmin: bool,
}
const mapStateToProps = ({
const mapStateToProps = ({links, auth: {me, logoutLink}}) => ({
links,
auth: {
me: {
name,
provider,
scheme,
currentOrganization,
roles,
organizations,
superAdmin,
},
logoutLink,
},
}) => ({
links,
name,
provider,
scheme,
currentOrganization,
roles,
organizations,
logoutLink,
superAdmin,
me,
})
const mapDispatchToProps = dispatch => ({