From 7df02c5db5f58a2f174047d95342cd1791a9d10c Mon Sep 17 00:00:00 2001 From: Jayasanka Weerasinghe Date: Fri, 24 Apr 2020 16:49:40 +0530 Subject: [PATCH] Fix android enterprise view crashing by permission rendering --- .../components/Pages/index.js | 10 +- .../scenes/Page/components/Cluster/index.js | 101 ++++++++++-------- .../AndroidEnterprise/scenes/Page/index.js | 35 ++++-- 3 files changed, 85 insertions(+), 61 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/components/Pages/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/components/Pages/index.js index 597fcc63c2..f94ccbce13 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/components/Pages/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/components/Pages/index.js @@ -49,8 +49,8 @@ class Pages extends React.Component { homePageId: null, }; this.hasPermissionToManage = isAuthorized( - this.props.config.user, - '/device-mgt/enterprise/user/view', + this.props.context.user, + '/permission/admin/device-mgt/enterprise/user/modify', ); } @@ -63,7 +63,9 @@ class Pages extends React.Component { }; componentDidMount() { - this.setHomePage(); + if (this.hasPermissionToView) { + this.setHomePage(); + } this.fetch(); } @@ -273,7 +275,7 @@ class Pages extends React.Component { return (
Pages - + {this.hasPermissionToManage && }
- {this.props.hasPermissionToManage && ( -
+
+ {this.props.hasPermissionToManage && ( -
- )} + )} +
@@ -348,9 +348,14 @@ class Cluster extends React.Component {
- - {name} - + {this.props.hasPermissionToManage && ( + + {name} + + )} + {!this.props.hasPermissionToManage && ( + {name} + )} {!isTemporary && this.props.hasPermissionToManage && ( @@ -413,51 +418,55 @@ class Cluster extends React.Component { ); })} - - - {isTemporary && ( -
- - - + {this.props.hasPermissionToManage && ( + +
+ {isTemporary && ( +
+ + + + + +
+ )} + {!isTemporary && ( +
+ + - -
- )} - {!isTemporary && ( -
- - - -
- )} - - + + )} + + + )} ); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/scenes/Page/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/scenes/Page/index.js index 170d31dbc4..066e17c6ad 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/scenes/Page/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Manage/scenes/AndroidEnterprise/scenes/Page/index.js @@ -63,15 +63,22 @@ class Page extends React.Component { links: [], }; this.hasPermissionToManage = isAuthorized( - this.props.config.user, - '/device-mgt/enterprise/user/view', + this.props.context.user, + '/permission/admin/device-mgt/enterprise/user/modify', + ); + + this.hasPermissionToView = isAuthorized( + this.props.context.user, + '/permission/admin/device-mgt/enterprise/user/view', ); } componentDidMount() { - this.fetchClusters(); - this.fetchApplications(); - this.fetchPages(); + if (this.hasPermissionToView) { + this.fetchClusters(); + this.fetchApplications(); + this.fetchPages(); + } } removeLoadedCluster = clusterId => { @@ -344,12 +351,17 @@ class Page extends React.Component { > - - {pageName} - + {this.hasPermissionToManage && ( + + {pageName} + + )} + {!this.hasPermissionToManage && ( + {pageName} + )} @@ -412,6 +424,7 @@ class Page extends React.Component { name: 'New Cluster', products: [], }} + hasPermissionToManage={true} orderInPage={clusters.length} isTemporary={true} pageId={this.pageId}