update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / launchpad / src / instantiate / instantiateDashboard.jsx
index 607576b..ef93bb0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,22 +24,26 @@ import InstantiateSelectDescriptorPanel from './instantiateSelectDescriptorPanel
 import CatalogDescriptorRaw from './catalogDescriptorRaw.jsx'
 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
 import {Panel, PanelWrapper} from 'widgets/panel/panel';
-import Button from 'widgets/button/rw.button.js'
+import Button from 'widgets/button/rw.button.js';
+import {SkyquakeRBAC, isRBACValid} from 'widgets/skyquake_rbac/skyquakeRBAC.jsx';
+import ROLES from 'utils/roleConstants.js';
 import 'style/layout.scss';
 import './instantiateDashboard.scss';
 
+const PROJECT_ROLES = ROLES.PROJECT;
+const PLATFORM = ROLES.PLATFORM;
+
 class InstantiateDashboard extends React.Component {
     constructor(props) {
         super(props);
-        this.Store = this.props.flux.stores.hasOwnProperty('InstantiateStore') ? this.props.flux.stores.InstantiateStore : this.props.flux.createStore(InstantiateStore                );
+        this.Store = this.props.flux.stores.hasOwnProperty('InstantiateStore') ? this.props.flux.stores.InstantiateStore : this.props.flux.createStore(InstantiateStore, 'InstantiateStore');
         this.state = this.Store.getState();
     }
     componentDidMount() {
         let self = this;
         let asyncOperations = []
         asyncOperations.push(this.Store.getCatalog());
-        asyncOperations.push(this.Store.getCloudAccount(function() {
-          asyncOperations.push(self.Store.getDataCenters());
+        asyncOperations.push(this.Store.getResourceOrchestratorAccounts(function() {
           asyncOperations.push(self.Store.getSshKey());
           asyncOperations.push(self.Store.getConfigAgent());
         }));
@@ -48,7 +52,6 @@ class InstantiateDashboard extends React.Component {
                 self.Store.descriptorSelected(self.state.nsdDict[self.props.params.nsd]);
             }
         })
-
     }
     componentWillMount() {
         this.Store.listen(this.updateState);
@@ -75,7 +78,7 @@ class InstantiateDashboard extends React.Component {
           self.props.actions.showNotification('Spaces and special characters except underscores are not supported in the network service name at this time');
           return;
         }
-        if (this.isOpenMano() && (this.state.dataCenterID == "" || !this.state.dataCenterID)) {
+        if (this.state.isOpenMano && (this.state.dataCenterID == "" || !this.state.dataCenterID)) {
              self.props.actions.showNotification("Please enter the Data Center ID");
           return;
         }
@@ -87,7 +90,7 @@ class InstantiateDashboard extends React.Component {
         return !this.props.location.pathname.split('/')[2];
     }
     isOpenMano = () => {
-        return this.state.selectedCloudAccount['account-type'] == 'openmano';
+        return this.state.ro['account-type'] == 'openmano';
     }
     openDescriptor = (descriptor) => {
         let NSD = descriptor;
@@ -105,6 +108,7 @@ class InstantiateDashboard extends React.Component {
         let html;
         let selectedNSDid = self.state.selectedNSDid;
         let isPreviewing = self.state.isPreviewing;
+        const hasAccess = isRBACValid(this.context.userProfile, [PROJECT_ROLES.LCM_ADMIN, PROJECT_ROLES.PROJECT_ADMIN]);
         let descriptorPreview = (
             <Panel title={(self.state.selectedNSD['short-name'] || self.state.selectedNSD.name ) + ' Descriptor Preview'} className="CatalogDescriptorPreview">
             <span className="oi CatalogDescriptorPreview-button" data-glyph={"circle-x"} onClick={self.Store.deselectDescriptor}></span>
@@ -134,10 +138,11 @@ class InstantiateDashboard extends React.Component {
 
                     <Button label="Cancel" onClick={this.handleCancel}/>
                     {this.isSelectPage() ?
-                        <Button label="Next" isLoading={this.state.isSaving} onClick={this.state.selectedNSD && self.openDescriptor} className="dark"  type="submit"/>
+                        <Button label="Next" isLoading={this.state.isSaving} onClick={this.state.selectedNSD && self.openDescriptor} className="dark" type="submit"/>
                         : <div>
                             <Button label="Back" onClick={this.handleBack}/>
-                            <Button label="Launch" isLoading={this.state.isSaving} onClick={self.handleSave.bind(self, true)} className="dark"  type="submit"/>
+                            { hasAccess ? <Button label="Launch" isLoading={this.state.isSaving} onClick={self.handleSave.bind(self, true)} className="dark"  type="submit"
+                            /> : null}
                         </div>
                     }
                 </div>
@@ -146,6 +151,7 @@ class InstantiateDashboard extends React.Component {
     }
 }
 InstantiateDashboard.contextTypes = {
-    router: React.PropTypes.object
+    router: React.PropTypes.object,
+    userProfile: React.PropTypes.object
 };
 export default SkyquakeComponent(InstantiateDashboard);