X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=skyquake%2Fframework%2Fwidgets%2Fskyquake_rbac%2FskyquakeRBAC.jsx;h=c1d3b0123954812ba97d5124b7ae15e0821c5796;hb=9be8b4847b580cea9e28d2f2a02166753c29b58e;hp=e00e67254f136de54f077e3a45a30b59dbd5e57d;hpb=bb11c05914869028a39a685cf5bf2ec347f299a1;p=osm%2FUI.git diff --git a/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx b/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx index e00e67254..c1d3b0123 100644 --- a/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx +++ b/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx @@ -21,27 +21,36 @@ import React from 'react'; import ROLES from 'utils/roleConstants.js'; const PLATFORM = ROLES.PLATFORM; +export function isRBACValid(User, allow){ + const UserData = User.data; + if(UserData) { + const PlatformRole = UserData.platform.role; + const isPlatformSuper = PlatformRole[PLATFORM.SUPER]; + const isPlatformAdmin = PlatformRole[PLATFORM.ADMIN]; + const isPlatformOper = PlatformRole[PLATFORM.OPER]; + const hasRoleAccess = checkForRoleAccess(UserData.project[User.projectId], PlatformRole, allow)//false//(this.props.roles.indexOf(userProfile.projectRole) > -1) + if (isPlatformSuper) { + return true; + } else { + if (hasRoleAccess) { + return true; + } + } + } + return false; +} + export default class SkyquakeRBAC extends React.Component { constructor(props, context) { super(props); } render() { - const User = this.context.userProfile.data; + const User = this.context.userProfile; + const UserData = User.data; let HTML = null; // If user object has platform property then it has been populated by the back end. - if(User) { - const PlatformRole = User.platform.role; - const isPlatformSuper = PlatformRole[PLATFORM.SUPER]; - const isPlatformAdmin = PlatformRole[PLATFORM.ADMIN]; - const isPlatformOper = PlatformRole[PLATFORM.OPER]; - const hasRoleAccess = checkForRoleAccess(User.project[this.props.project], PlatformRole, this.props.allow)//false//(this.props.roles.indexOf(userProfile.projectRole) > -1) - if (isPlatformSuper) { - HTML = this.props.children; - } else { - if (hasRoleAccess) { - HTML = this.props.children; - } - } + if(isRBACValid(User, this.props.allow)) { + HTML = this.props.children; } return (
{HTML}
) } @@ -56,7 +65,7 @@ SkyquakeRBAC.contextTypes = { function checkForRoleAccess(project, PlatformRole, allow) { if (allow.indexOf('*') > -1) return true; for (let i = 0; i