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 default class SkyquakeRBAC extends React.Component {
25 constructor(props, context) {
29 const User = this.context.userProfile;
30 const UserData = User.data;
32 // If user object has platform property then it has been populated by the back end.
34 const PlatformRole = UserData.platform.role;
35 const isPlatformSuper = PlatformRole[PLATFORM.SUPER];
36 const isPlatformAdmin = PlatformRole[PLATFORM.ADMIN];
37 const isPlatformOper = PlatformRole[PLATFORM.OPER];
38 const hasRoleAccess = checkForRoleAccess(UserData.project[User.projectId], PlatformRole, this.props.allow)//false//(this.props.roles.indexOf(userProfile.projectRole) > -1)
39 if (isPlatformSuper) {
40 HTML = this.props.children;
43 HTML = this.props.children;
47 return (<div className={this.props.className} style={this.props.style}>{HTML}</div>)
50 SkyquakeRBAC.defaultProps = {
53 SkyquakeRBAC.contextTypes = {
54 userProfile: React.PropTypes.object
57 function checkForRoleAccess(project, PlatformRole, allow) {
58 if (allow.indexOf('*') > -1) return true;
59 for (let i = 0; i<allow.length; i++) {
60 if((project && project.role[allow[i]] )|| PlatformRole[allow[i]]) {
69 // export default function(Component) {
70 // class SkyquakeRBAC extends React.Component {
71 // constructor(props, context) {
75 // console.log(this.context.userProfile)
76 // const User = this.context.userProfile.data;
77 // // If user object has platform property then it has been populated by the back end.
79 // const PlatformRole = User.platform.role;
80 // const HTML = <Component {...this.props} router={this.router} actions={this.actions} flux={this.context.flux}/>;
81 // const isPlatformSuper = PlatformRole[PLATFORM.SUPER];
82 // const isPlatformAdmin = PlatformRole[PLATFORM.ADMIN];
83 // const isPlatformOper = PlatformRole[PLATFORM.OPER];
84 // const hasRoleAccess = false//(this.props.roles.indexOf(userProfile.projectRole) > -1)
85 // if (isPlatformSuper || isPlatformOper || isPlatformAdmin) {
88 // if (hasRoleAccess) {
101 // SkyquakeRBAC.defaultProps = {
104 // SkyquakeRBAC.contextTypes = {
105 // userProfile: React.PropTypes.object,
108 // return SkyquakeRBAC;