Set me role in redux based on current organization
parent
7252260792
commit
71bd6e390b
|
@ -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,
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue