Init RBAC read only: composer
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
diff --git a/skyquake/framework/core/modules/routes/navigation.js b/skyquake/framework/core/modules/routes/navigation.js
index bf9c47b..16ff25a 100644
--- a/skyquake/framework/core/modules/routes/navigation.js
+++ b/skyquake/framework/core/modules/routes/navigation.js
@@ -1,6 +1,6 @@
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/skyquake/framework/utils/utils.js b/skyquake/framework/utils/utils.js
index be3278d..16037d7 100644
--- a/skyquake/framework/utils/utils.js
+++ b/skyquake/framework/utils/utils.js
@@ -26,6 +26,7 @@
var Utils = {};
Utils.DescriptorModelMeta = null;
+// Utils.DescriptorModelMeta = require('./../../plugins/composer/src/src/libraries/model/DescriptorModelMeta.json');
var INACTIVITY_TIMEOUT = 600000;
diff --git a/skyquake/framework/widgets/skyquake_nav/skyquakeNav.jsx b/skyquake/framework/widgets/skyquake_nav/skyquakeNav.jsx
index 1aaaf4d..c4df1e2 100644
--- a/skyquake/framework/widgets/skyquake_nav/skyquakeNav.jsx
+++ b/skyquake/framework/widgets/skyquake_nav/skyquakeNav.jsx
@@ -25,7 +25,7 @@
import './skyquakeNav.scss';
import SelectOption from '../form_controls/selectOption.jsx';
import {FormSection} from '../form_controls/formControls.jsx';
-import SkyquakeRBAC from 'widgets/skyquake_rbac/skyquakeRBAC.jsx';
+import {isRBACValid, SkyquakeRBAC} from 'widgets/skyquake_rbac/skyquakeRBAC.jsx';
//Temporary, until api server is on same port as webserver
var rw = require('utils/rw.js');
@@ -190,6 +190,9 @@
skyquakeNav.defaultProps = {
nav: {}
}
+skyquakeNav.contextTypes = {
+ userProfile: React.PropTypes.object
+};
/**
* Returns a React Component
* @param {object} link Information about the nav link
@@ -259,6 +262,7 @@
let secondaryNav = [];
let adminNav = [];
let self = this;
+ const User = this.context.userProfile;
self.hasSubNav = {};
let secondaryNavHTML = (
<div className="secondaryNav" key="secondaryNav">
@@ -318,16 +322,19 @@
</li>
))
} else {
- navItem.html = (
- <SkyquakeRBAC allow={nav[k].allow || ['*']} key={k} className={navClass}>
- <h2>{dashboardLink} {self.hasSubNav[k] ? <span className="oi" data-glyph="caret-bottom"></span> : ''}</h2>
- <ul className="menu">
- {
- NavList
- }
- </ul>
- </SkyquakeRBAC>
- );
+ let shouldAllow = nav[k].allow || ['*'];
+ if (isRBACValid(User, shouldAllow) ){
+ navItem.html = (
+ <div key={k} className={navClass}>
+ <h2>{dashboardLink} {self.hasSubNav[k] ? <span className="oi" data-glyph="caret-bottom"></span> : ''}</h2>
+ <ul className="menu">
+ {
+ NavList
+ }
+ </ul>
+ </div>
+ );
+ }
navList.push(navItem)
}
diff --git a/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx b/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx
index cbb6a56..0245e23 100644
--- a/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx
+++ b/skyquake/framework/widgets/skyquake_rbac/skyquakeRBAC.jsx
@@ -21,6 +21,25 @@
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 @@
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 (<div className={this.props.className} style={this.props.style}>{HTML}</div>)
}