3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 import React from 'react';
21 import ROLES from 'utils/roleConstants.js';
22 const PLATFORM = ROLES.PLATFORM;
24 export function isRBACValid(User, allow){
25 const UserData = User.data;
27 const PlatformRole = UserData.platform.role;
28 const isPlatformSuper = PlatformRole[PLATFORM.SUPER];
29 const isPlatformAdmin = PlatformRole[PLATFORM.ADMIN];
30 const isPlatformOper = PlatformRole[PLATFORM.OPER];
31 const hasRoleAccess = checkForRoleAccess(UserData.project[User.projectId], PlatformRole, allow)//false//(this.props.roles.indexOf(userProfile.projectRole) > -1)
32 if (isPlatformSuper) {
43 export default class SkyquakeRBAC extends React.Component {
44 constructor(props, context) {
48 const User = this.context.userProfile;
49 const UserData = User.data;
51 // If user object has platform property then it has been populated by the back end.
52 if(isRBACValid(User, this.props.allow)) {
53 HTML = this.props.children;
55 return (<div className={this.props.className} style={this.props.style}>{HTML}</div>)
58 SkyquakeRBAC.defaultProps = {
61 SkyquakeRBAC.contextTypes = {
62 userProfile: React.PropTypes.object
65 function checkForRoleAccess(project, PlatformRole, allow) {
66 if (allow.indexOf('*') > -1) return true;
67 for (let i = 0; i<allow.length; i++) {
68 if((project && project.role[allow[i]])|| PlatformRole[allow[i]]) {
77 // export default function(Component) {
78 // class SkyquakeRBAC extends React.Component {
79 // constructor(props, context) {
83 // console.log(this.context.userProfile)
84 // const User = this.context.userProfile.data;
85 // // If user object has platform property then it has been populated by the back end.
87 // const PlatformRole = User.platform.role;
88 // const HTML = <Component {...this.props} router={this.router} actions={this.actions} flux={this.context.flux}/>;
89 // const isPlatformSuper = PlatformRole[PLATFORM.SUPER];
90 // const isPlatformAdmin = PlatformRole[PLATFORM.ADMIN];
91 // const isPlatformOper = PlatformRole[PLATFORM.OPER];
92 // const hasRoleAccess = false//(this.props.roles.indexOf(userProfile.projectRole) > -1)
93 // if (isPlatformSuper || isPlatformOper || isPlatformAdmin) {
96 // if (hasRoleAccess) {
109 // SkyquakeRBAC.defaultProps = {
112 // SkyquakeRBAC.contextTypes = {
113 // userProfile: React.PropTypes.object,
116 // return SkyquakeRBAC;