Launchpad RBAC
[osm/UI.git] / skyquake / plugins / launchpad / src / recordViewer / recordCard.jsx
index 41f7007..7b3cb21 100644 (file)
@@ -36,6 +36,10 @@ import LaunchpadFleetStore from '../launchpadFleetStore.js';
 import Prism from 'prismjs';
 import 'prismjs/themes/prism.css';
 
+import {SkyquakeRBAC, isRBACValid} from 'widgets/skyquake_rbac/skyquakeRBAC.jsx';
+import ROLES from 'utils/roleConstants.js';
+
+const PROJECT_ROLES = ROLES.PROJECT;
 
 export default class RecordCard extends React.Component {
   constructor(props) {
@@ -77,6 +81,8 @@ export default class RecordCard extends React.Component {
 
     let notice = null;
 
+    let hasAccess = isRBACValid(this.context.userProfile, [PROJECT_ROLES.LCM_ADMIN]);
+
     switch(this.props.type) {
       case 'vnfr' :
         cardData = this.props.data[0];
@@ -86,7 +92,7 @@ export default class RecordCard extends React.Component {
         if (displayConfigPrimitives) {
           configPrimitiveComponent = (
             <div className="flex vnfrConfigPrimitiveContainer">
-              <VnfrConfigPrimitives data={configPrimitivesProps} />
+              <VnfrConfigPrimitives data={configPrimitivesProps} hasAccess={hasAccess} />
             {/* <NsrPrimitiveJobList jobs={cardData['config-agent-job']}/> */}
             <div style={{display:'flex', flexDirection: 'column',     flex: '1 1 40%'}}>
                 <div className="launchpadCard_title">
@@ -106,7 +112,7 @@ export default class RecordCard extends React.Component {
                         //That match the currently selected job id
                         if(v.id == cardData.id) {
                           return v.primitive.map(function(p, i) {
-                            return <JobListCard type="vnfr" job-id={job['job-id']} cardData={cardData} key={ob['job-id'] + '-' + i} {...p} />
+                            return <JobListCard type="vnfr" job-id={job['job-id']} cardData={cardData} key={job['job-id'] + '-' + i} {...p} />
                           })
                         }
                       })
@@ -132,14 +138,38 @@ export default class RecordCard extends React.Component {
               </li>
             )
             notice = <li className='notice'>* If a separate browser window does not open, please check if the popup was blocked and allow it.</li>
-            if(vdur.hasOwnProperty('volumer') && (vdur.volumer.length > 0)) {
+            if(vdur.hasOwnProperty('volumes') && (vdur.volumes.length > 0)) {
               displayVolumesTab = true;
-              vdur.volumer.map((volume, vi) => {
-                let html = Prism.highlight(JSON.stringify(volume), Prism.languages.javascript, 'javascript');
+              vdur.volumes.map((volume, vi) => {
+                // let html = Prism.highlight(JSON.stringify(volume), Prism.languages.javascript, 'javascript');
+                // volumesHTML.push(
+                //     <pre className="language-js" key={index + '-' + vi}>
+                //       <code dangerouslySetInnerHTML={{__html: html}} />
+                //     </pre>
+                function buildProperties(obj) {
+                  let p = [];
+                    _.forEach(obj, function(v, k) {
+                    p.push(
+                      <div style={{margin: '0.5rem 0.5rem'}} key={k + vi}>
+                        <div style={{margin: '0 0.5rem',
+    fontWeight: 'bold', textTransform: 'uppercase', color: '#5b5b5b'}}>{k}</div>
+                        <div style={{margin: '0 0.5rem'}}>{v.constructor.name != 'Object' ? v : buildProperties(v)}</div>
+                      </div>
+                    )
+                  });
+                    return p;
+                 }
                 volumesHTML.push(
-                    <pre className="language-js" key={index + '-' + vi}>
-                      <code dangerouslySetInnerHTML={{__html: html}} />
-                    </pre>
+                    <div key={vi}>
+                      <div className="launchpadCard_title">
+                        VOLUME
+                      </div>
+                      <div style={{display: 'flex', flexDirection: 'column'}}>
+                      {
+                        buildProperties(volume)
+                      }
+                      </div>
+                    </div>
                 )
               })
             }
@@ -184,7 +214,7 @@ export default class RecordCard extends React.Component {
                         //That match the currently selected job id
                         if(v.id == cardData.id) {
                           return v.primitive.map(function(p, i) {
-                            return <JobListCard type="vnfr" job-id={job['job-id']} cardData={cardData} key={ob['job-id'] + '-' + 'vnfr' + '-' + h} {...p} />
+                            return <JobListCard type="vnfr" job-id={job['job-id']} cardData={cardData} key={job['job-id'] + '-' + 'vnfr' + '-' + h} {...p} />
                           })
                         }
                       })
@@ -395,3 +425,7 @@ RecordCard.defaultProps = {
   isLoading: true,
   jobData: []
 }
+RecordCard.contextTypes = {
+    router: React.PropTypes.object,
+    userProfile: React.PropTypes.object
+};