Set me role in redux based on current organization

pull/10616/head
Jared Scheib 2017-11-03 08:17:04 -07:00
parent 7252260792
commit 71bd6e390b
2 changed files with 10 additions and 3 deletions

View File

@ -39,6 +39,10 @@ const {arrayOf, bool, shape, string} = PropTypes
RoleIndicator.propTypes = {
isUsingAuth: bool.isRequired,
me: shape({
currentOrganization: shape({
name: string.isRequired,
id: string.isRequired,
}),
roles: arrayOf(
shape({
name: string.isRequired,

View File

@ -3,9 +3,12 @@ import _ from 'lodash'
import {SUPERADMIN_ROLE, MEMBER_ROLE} from 'src/auth/Authorized'
export const getMeRole = me => {
return me.superAdmin
? SUPERADMIN_ROLE
: _.get(_.first(_.get(me, 'roles', [])), 'name', MEMBER_ROLE)
const currentRoleOrg = me.roles.find(
role => me.currentOrganization.id === role.organization
)
const currentRole = _.get(currentRoleOrg, 'name', MEMBER_ROLE)
return me.superAdmin ? SUPERADMIN_ROLE : currentRole
}
export const isSameUser = (userA, userB) => {