Merge branch 'fix/appm-publisher/android-for-work' into 'master'

Fix android enterprise view crashing by permission rendering

Closes product-iots#491

See merge request entgra/carbon-device-mgt!519
reporting
Dharmakeerthi Lasantha 5 years ago
commit 74b2e64649

@ -49,8 +49,8 @@ class Pages extends React.Component {
homePageId: null, homePageId: null,
}; };
this.hasPermissionToManage = isAuthorized( this.hasPermissionToManage = isAuthorized(
this.props.config.user, this.props.context.user,
'/device-mgt/enterprise/user/view', '/permission/admin/device-mgt/enterprise/user/modify',
); );
} }
@ -63,7 +63,9 @@ class Pages extends React.Component {
}; };
componentDidMount() { componentDidMount() {
if (this.hasPermissionToView) {
this.setHomePage(); this.setHomePage();
}
this.fetch(); this.fetch();
} }
@ -273,7 +275,7 @@ class Pages extends React.Component {
return ( return (
<div className="layout-pages"> <div className="layout-pages">
<Title level={4}>Pages</Title> <Title level={4}>Pages</Title>
<AddNewPage /> {this.hasPermissionToManage && <AddNewPage />}
<div style={{ backgroundColor: '#ffffff', borderRadius: 5 }}> <div style={{ backgroundColor: '#ffffff', borderRadius: 5 }}>
<Table <Table
columns={this.columns} columns={this.columns}

@ -295,8 +295,8 @@ class Cluster extends React.Component {
} }
return ( return (
<div className="product"> <div className="product">
{this.props.hasPermissionToManage && (
<div className="arrow"> <div className="arrow">
{this.props.hasPermissionToManage && (
<button <button
disabled={index === 0} disabled={index === 0}
className="btn" className="btn"
@ -306,8 +306,8 @@ class Cluster extends React.Component {
> >
<Icon type="caret-left" theme="filled" /> <Icon type="caret-left" theme="filled" />
</button> </button>
</div>
)} )}
</div>
<div className="product-icon"> <div className="product-icon">
<img src={imageSrc} /> <img src={imageSrc} />
<Tooltip title={packageId}> <Tooltip title={packageId}>
@ -348,9 +348,14 @@ class Cluster extends React.Component {
<Spin spinning={loading}> <Spin spinning={loading}>
<Row> <Row>
<Col span={16}> <Col span={16}>
{this.props.hasPermissionToManage && (
<Title editable={{ onChange: this.handleNameChange }} level={4}> <Title editable={{ onChange: this.handleNameChange }} level={4}>
{name} {name}
</Title> </Title>
)}
{!this.props.hasPermissionToManage && (
<Title level={4}>{name}</Title>
)}
</Col> </Col>
<Col span={8}> <Col span={8}>
{!isTemporary && this.props.hasPermissionToManage && ( {!isTemporary && this.props.hasPermissionToManage && (
@ -413,11 +418,14 @@ class Cluster extends React.Component {
); );
})} })}
</div> </div>
{this.props.hasPermissionToManage && (
<Row> <Row>
<Col> <Col>
{isTemporary && ( {isTemporary && (
<div> <div>
<Button onClick={this.cancelAddingNewCluster}>Cancel</Button> <Button onClick={this.cancelAddingNewCluster}>
Cancel
</Button>
<Divider type="vertical" /> <Divider type="vertical" />
<Tooltip <Tooltip
title={ title={
@ -458,6 +466,7 @@ class Cluster extends React.Component {
)} )}
</Col> </Col>
</Row> </Row>
)}
</Spin> </Spin>
</div> </div>
); );

@ -63,16 +63,23 @@ class Page extends React.Component {
links: [], links: [],
}; };
this.hasPermissionToManage = isAuthorized( this.hasPermissionToManage = isAuthorized(
this.props.config.user, this.props.context.user,
'/device-mgt/enterprise/user/view', '/permission/admin/device-mgt/enterprise/user/modify',
);
this.hasPermissionToView = isAuthorized(
this.props.context.user,
'/permission/admin/device-mgt/enterprise/user/view',
); );
} }
componentDidMount() { componentDidMount() {
if (this.hasPermissionToView) {
this.fetchClusters(); this.fetchClusters();
this.fetchApplications(); this.fetchApplications();
this.fetchPages(); this.fetchPages();
} }
}
removeLoadedCluster = clusterId => { removeLoadedCluster = clusterId => {
const clusters = [...this.state.clusters]; const clusters = [...this.state.clusters];
@ -344,12 +351,17 @@ class Page extends React.Component {
> >
<Row> <Row>
<Col md={8} sm={18} xs={24}> <Col md={8} sm={18} xs={24}>
{this.hasPermissionToManage && (
<Title <Title
editable={{ onChange: this.updatePageName }} editable={{ onChange: this.updatePageName }}
level={2} level={2}
> >
{pageName} {pageName}
</Title> </Title>
)}
{!this.hasPermissionToManage && (
<Title level={2}>{pageName}</Title>
)}
</Col> </Col>
</Row> </Row>
<Row> <Row>
@ -412,6 +424,7 @@ class Page extends React.Component {
name: 'New Cluster', name: 'New Cluster',
products: [], products: [],
}} }}
hasPermissionToManage={true}
orderInPage={clusters.length} orderInPage={clusters.length}
isTemporary={true} isTemporary={true}
pageId={this.pageId} pageId={this.pageId}

Loading…
Cancel
Save