X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fframework%2Fwidgets%2Fskyquake_rbac%2FskyquakeRBAC.jsx;h=c1d3b0123954812ba97d5124b7ae15e0821c5796;hb=04997f0db765e39bd3a1fa76d40043eda9cdd326;hp=cbb6a567ff2ac48293245ac6f8abc98efb9a0793;hpb=96b7649b2db9ab306a20b43db5f77b6111d746ed;p=osm%2FUI.git diff --git a/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx b/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx index cbb6a567f..c1d3b0123 100644 --- a/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx +++ b/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx @@ -21,6 +21,25 @@ 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); @@ -30,19 +49,8 @@ export default class SkyquakeRBAC extends React.Component { const UserData = User.data; let HTML = null; // If user object has platform property then it has been populated by the back end. - 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, 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}
) } @@ -57,7 +65,7 @@ SkyquakeRBAC.contextTypes = { function checkForRoleAccess(project, PlatformRole, allow) { if (allow.indexOf('*') > -1) return true; for (let i = 0; i