From 07633662ca4b314f27373775a7eb0ccc1d19e8a0 Mon Sep 17 00:00:00 2001 From: Laurence Maultsby Date: Thu, 13 Apr 2017 16:36:22 -0400 Subject: [PATCH] Account page RBAC Signed-off-by: Laurence Maultsby --- .../plugins/accounts/src/account/account.jsx | 32 +++++++-- .../src/account/accountsDashboard.jsx | 16 ++++- .../src/account_sidebar/accountSidebar.jsx | 72 +++++++++++-------- .../src/dashboard/dashboard.jsx | 4 +- .../src/dashboard/dashboard.jsx | 5 +- 5 files changed, 90 insertions(+), 39 deletions(-) diff --git a/skyquake/plugins/accounts/src/account/account.jsx b/skyquake/plugins/accounts/src/account/account.jsx index 37063ca57..92c368afe 100644 --- a/skyquake/plugins/accounts/src/account/account.jsx +++ b/skyquake/plugins/accounts/src/account/account.jsx @@ -23,6 +23,7 @@ import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx' import Crouton from 'react-crouton'; import TextInput from 'widgets/form_controls/textInput.jsx'; import {AccountConnectivityStatus} from '../account_sidebar/accountSidebar.jsx'; + import 'style/common.scss'; import './account.scss'; class Account extends React.Component { @@ -263,7 +264,16 @@ class Account extends React.Component { value = Account.params[node.ref]; } paramsStack.push( - + ); } @@ -287,7 +297,16 @@ class Account extends React.Component { // // ); nestedParamsStack.push( - + ); } } @@ -330,7 +349,7 @@ class Account extends React.Component { {Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()} - + { (Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()) === 'FAILURE' ? @@ -387,7 +406,7 @@ class Account extends React.Component { {params}
- {buttons} + {!self.props.readonly ? buttons : null}
) @@ -395,6 +414,11 @@ class Account extends React.Component { } } +Account.contextTypes = { + router: React.PropTypes.object, + userProfile: React.PropTypes.object +} + function displayFailureMessage(msg) { return (
diff --git a/skyquake/plugins/accounts/src/account/accountsDashboard.jsx b/skyquake/plugins/accounts/src/account/accountsDashboard.jsx index f139b474b..c95a63f23 100644 --- a/skyquake/plugins/accounts/src/account/accountsDashboard.jsx +++ b/skyquake/plugins/accounts/src/account/accountsDashboard.jsx @@ -21,6 +21,14 @@ import AppHeader from 'widgets/header/header.jsx'; import AccountStore from './accountStore.js'; import AccountSidebar from '../account_sidebar/accountSidebar.jsx'; import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx'; +import {SkyquakeRBAC, isRBACValid} from 'widgets/skyquake_rbac/skyquakeRBAC.jsx'; +import ROLES from 'utils/roleConstants.js'; + +const PROJECT_ROLES = ROLES.PROJECT; +const PLATFORM = ROLES.PLATFORM; + +//Delete this line after testing is done +// PROJECT_ROLES.ACCOUNT_ADMIN = ''; import 'style/layout.scss'; class AccountsDashboard extends React.Component { @@ -44,11 +52,12 @@ class AccountsDashboard extends React.Component { render() { let self = this; let html; + let READONLY = !isRBACValid(this.context.userProfile, [PROJECT_ROLES.ACCOUNT_ADMIN]); html = (
- +
- { this.props.children ? React.cloneElement(this.props.children, {store: self.Store, ...self.state}) : 'Edit or Create New Accounts' + { this.props.children ? React.cloneElement(this.props.children, {readonly: READONLY, store: self.Store, ...self.state}) : 'Edit or Create New Accounts' }
@@ -57,7 +66,8 @@ class AccountsDashboard extends React.Component { } } AccountsDashboard.contextTypes = { - router: React.PropTypes.object + router: React.PropTypes.object, + userProfile: React.PropTypes.object }; export default SkyquakeComponent(AccountsDashboard); diff --git a/skyquake/plugins/accounts/src/account_sidebar/accountSidebar.jsx b/skyquake/plugins/accounts/src/account_sidebar/accountSidebar.jsx index 723d89361..3a10ce988 100644 --- a/skyquake/plugins/accounts/src/account_sidebar/accountSidebar.jsx +++ b/skyquake/plugins/accounts/src/account_sidebar/accountSidebar.jsx @@ -42,6 +42,7 @@ class AccountSidebar extends React.Component{ } render() { let html; + let self = this; let {store, ...props} = this.props; //[this.props.cloud,this.props.sdn,this.props['config-agent']] let AccountData = [ @@ -128,42 +129,53 @@ class AccountSidebar extends React.Component{

VIM Accounts

{cloudAccounts} - - - Add VIM Account - - - + { + !self.props.readonly ? + + + Add VIM Account + + + + :
+ }
) : null}

SDN Accounts

{sdnAccounts} - - - Add SDN Account - - - + { + !self.props.readonly ? + + + Add SDN Account + + + + + :
+ }

Config Agent Accounts

{configAgentAccounts} - - - Add Config Agent Account - - - + { + !self.props.readonly ? + + + Add Config Agent Account + + + + :
+ }
); return html; diff --git a/skyquake/plugins/project_management/src/dashboard/dashboard.jsx b/skyquake/plugins/project_management/src/dashboard/dashboard.jsx index f1fca657c..bc67dbf33 100644 --- a/skyquake/plugins/project_management/src/dashboard/dashboard.jsx +++ b/skyquake/plugins/project_management/src/dashboard/dashboard.jsx @@ -91,9 +91,11 @@ class ProjectManagementDashboard extends React.Component { deleteProject = (e) => { e.preventDefault(); e.stopPropagation(); - this.Store.deleteProject({ + if (confirm('Are you sure you want to delete this project?')) { + this.Store.deleteProject({ 'name': this.state['name'] }); + } } createProject = (e) => { let self = this; diff --git a/skyquake/plugins/user_management/src/dashboard/dashboard.jsx b/skyquake/plugins/user_management/src/dashboard/dashboard.jsx index 2494df0fb..a3b6a6398 100644 --- a/skyquake/plugins/user_management/src/dashboard/dashboard.jsx +++ b/skyquake/plugins/user_management/src/dashboard/dashboard.jsx @@ -93,10 +93,13 @@ class UserManagementDashboard extends React.Component { deleteUser = (e) => { e.preventDefault(); e.stopPropagation(); - this.Store.deleteUser({ + if (confirm('Are you sure you want to delete this user?')) { + this.Store.deleteUser({ 'user-name': this.state['user-name'], 'user-domain': this.state['user-domain'] }); + } + } createUser = (e) => { e.preventDefault(); -- 2.25.1