Merge branch 'feature/appm-publisher/pbac' into 'master'

Add permission based access control to APPM Publisher

Closes product-iots#483

See merge request entgra/carbon-device-mgt!507
reporting
Dharmakeerthi Lasantha 5 years ago
commit 831b2fa89f

@ -6,6 +6,7 @@
}, },
"serverConfig": { "serverConfig": {
"invoker": { "invoker": {
"contextPath" : "/publisher-ui-request-handler",
"uri": "/publisher-ui-request-handler/invoke", "uri": "/publisher-ui-request-handler/invoke",
"publisher": "/application-mgt-publisher/v1.0", "publisher": "/application-mgt-publisher/v1.0",
"store": "/application-mgt-store/v1.0", "store": "/application-mgt-store/v1.0",

@ -106,28 +106,64 @@ class App extends React.Component {
checkUserLoggedIn = config => { checkUserLoggedIn = config => {
axios axios
.post( .post(
window.location.origin + '/publisher-ui-request-handler/user', window.location.origin +
'platform=publisher', config.serverConfig.invoker.contextPath +
'/user',
) )
.then(res => { .then(res => {
config.user = res.data.data; config.user = {
username: res.data.data,
};
const pageURL = window.location.pathname; const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment === 'login') { if (lastURLSegment === 'login') {
window.location.href = window.location.origin + '/publisher/'; window.location.href = window.location.origin + '/publisher/';
} else { } else {
this.getAndroidEnterpriseToken(config); this.getUserPermissions(config);
} }
}) })
.catch(error => { .catch(error => {
this.handleApiError(error, config);
});
};
updateFavicon = () => {
const link =
document.querySelector("link[rel*='icon']") ||
document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href =
window.location.origin +
'/devicemgt/public/uuf.unit.favicon/img/favicon.png';
document.getElementsByTagName('head')[0].appendChild(link);
};
getUserPermissions = config => {
axios
.get(
window.location.origin +
config.serverConfig.invoker.uri +
config.serverConfig.invoker.deviceMgt +
'/users/current-user/permissions',
)
.then(res => {
config.user.permissions = res.data.data.permissions;
this.getAndroidEnterpriseToken(config);
})
.catch(error => {
this.handleApiError(error, config);
});
};
handleApiError = (error, config) => {
if (error.hasOwnProperty('response') && error.response.status === 401) { if (error.hasOwnProperty('response') && error.response.status === 401) {
const redirectUrl = encodeURI(window.location.href); const redirectUrl = encodeURI(window.location.href);
const pageURL = window.location.pathname; const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment !== 'login') { if (lastURLSegment !== 'login') {
window.location.href = window.location.href =
window.location.origin + window.location.origin + `/publisher/login?redirect=${redirectUrl}`;
`/publisher/login?redirect=${redirectUrl}`;
} else { } else {
this.getAndroidEnterpriseToken(config); this.getAndroidEnterpriseToken(config);
} }
@ -137,19 +173,6 @@ class App extends React.Component {
error: true, error: true,
}); });
} }
});
};
updateFavicon = () => {
const link =
document.querySelector("link[rel*='icon']") ||
document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href =
window.location.origin +
'/devicemgt/public/uuf.unit.favicon/img/favicon.png';
document.getElementsByTagName('head')[0].appendChild(link);
}; };
render() { render() {

@ -0,0 +1,39 @@
/*
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import react from 'react';
import { withConfigContext } from '../ConfigContext';
import { isAuthorized } from '../../services/utils/authorizationHandler';
class Authorized extends react.Component {
constructor(props) {
super(props);
}
render() {
return isAuthorized(this.props.context.user, this.props.permission)
? this.props.yes
: this.props.no;
}
}
Authorized.defaultProps = {
yes: null,
no: null,
};
export default withConfigContext(Authorized);

@ -24,6 +24,7 @@ import { Redirect } from 'react-router';
import './styles.css'; import './styles.css';
import { withConfigContext } from '../../components/ConfigContext'; import { withConfigContext } from '../../components/ConfigContext';
import Logout from './components/Logout'; import Logout from './components/Logout';
import { isAuthorized } from '../../services/utils/authorizationHandler';
const { Header, Content, Footer } = Layout; const { Header, Content, Footer } = Layout;
const { SubMenu } = Menu; const { SubMenu } = Menu;
@ -84,7 +85,10 @@ class Dashboard extends React.Component {
Apps Apps
</Link> </Link>
</Menu.Item> </Menu.Item>
{isAuthorized(
this.props.context.user,
'/permission/admin/app-mgt/publisher/application/update',
) && (
<SubMenu <SubMenu
title={ title={
<span className="submenu-title-wrapper"> <span className="submenu-title-wrapper">
@ -110,7 +114,7 @@ class Dashboard extends React.Component {
</Link> </Link>
</Menu.Item> </Menu.Item>
</SubMenu> </SubMenu>
)}
<SubMenu <SubMenu
title={ title={
<span className="submenu-title-wrapper"> <span className="submenu-title-wrapper">
@ -139,7 +143,7 @@ class Dashboard extends React.Component {
title={ title={
<span className="submenu-title-wrapper"> <span className="submenu-title-wrapper">
<Icon type="user" /> <Icon type="user" />
{this.config.user} {this.config.username}
</span> </span>
} }
> >

@ -22,6 +22,7 @@ import axios from 'axios';
import { withConfigContext } from '../../../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../../../components/ConfigContext';
import { handleApiError } from '../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../services/utils/errorHandler';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import Authorized from '../../../../../../../../components/Authorized/Authorized';
const formItemLayout = { const formItemLayout = {
labelCol: { labelCol: {
@ -46,12 +47,6 @@ class NewAppDetailsForm extends React.Component {
fetching: false, fetching: false,
roleSearchValue: [], roleSearchValue: [],
unrestrictedRoles: [], unrestrictedRoles: [],
forbiddenErrors: {
categories: false,
tags: false,
deviceTypes: false,
roles: false,
},
}; };
this.lastFetchId = 0; this.lastFetchId = 0;
this.fetchRoles = debounce(this.fetchRoles, 800); this.fetchRoles = debounce(this.fetchRoles, 800);
@ -127,18 +122,9 @@ class NewAppDetailsForm extends React.Component {
'Error occurred while trying to load categories.', 'Error occurred while trying to load categories.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.categories = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({ this.setState({
loading: false, loading: false,
}); });
}
}); });
}; };
@ -166,18 +152,9 @@ class NewAppDetailsForm extends React.Component {
'Error occurred while trying to load tags.', 'Error occurred while trying to load tags.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.tags = true;
this.setState({ this.setState({
forbiddenErrors,
loading: false, loading: false,
}); });
} else {
this.setState({
loading: false,
});
}
}); });
}; };
@ -279,18 +256,9 @@ class NewAppDetailsForm extends React.Component {
'Error occurred while trying to load roles.', 'Error occurred while trying to load roles.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.roles = true;
this.setState({ this.setState({
forbiddenErrors,
fetching: false, fetching: false,
}); });
} else {
this.setState({
fetching: false,
});
}
}); });
}; };
@ -310,7 +278,6 @@ class NewAppDetailsForm extends React.Component {
deviceTypes, deviceTypes,
fetching, fetching,
unrestrictedRoles, unrestrictedRoles,
forbiddenErrors,
} = this.state; } = this.state;
const { getFieldDecorator } = this.props.form; const { getFieldDecorator } = this.props.form;
@ -326,14 +293,17 @@ class NewAppDetailsForm extends React.Component {
> >
{formConfig.installationType !== 'WEB_CLIP' && ( {formConfig.installationType !== 'WEB_CLIP' && (
<div> <div>
{forbiddenErrors.deviceTypes && ( <Authorized
permission="/permission/admin/device-mgt/admin/device-type/view"
no={
<Alert <Alert
message="You don't have permission to view device types." message="You don't have permission to view device types."
type="warning" type="warning"
banner banner
closable closable
/> />
)} }
/>
<Form.Item {...formItemLayout} label="Device Type"> <Form.Item {...formItemLayout} label="Device Type">
{getFieldDecorator('deviceType', { {getFieldDecorator('deviceType', {
rules: [ rules: [
@ -387,14 +357,16 @@ class NewAppDetailsForm extends React.Component {
</Form.Item> </Form.Item>
{/* Unrestricted Roles*/} {/* Unrestricted Roles*/}
{forbiddenErrors.roles && ( <Authorized
permission="/permission/admin/device-mgt/roles/view"
no={
<Alert <Alert
message="You don't have permission to view roles." message="You don't have permission to view roles."
type="warning" type="warning"
banner banner
closable
/> />
)} }
/>
<Form.Item {...formItemLayout} label="Visible Roles"> <Form.Item {...formItemLayout} label="Visible Roles">
{getFieldDecorator('unrestrictedRoles', { {getFieldDecorator('unrestrictedRoles', {
rules: [], rules: [],
@ -417,14 +389,6 @@ class NewAppDetailsForm extends React.Component {
</Select>, </Select>,
)} )}
</Form.Item> </Form.Item>
{forbiddenErrors.categories && (
<Alert
message="You don't have permission to view categories."
type="warning"
banner
closable
/>
)}
<Form.Item {...formItemLayout} label="Categories"> <Form.Item {...formItemLayout} label="Categories">
{getFieldDecorator('categories', { {getFieldDecorator('categories', {
rules: [ rules: [
@ -450,14 +414,6 @@ class NewAppDetailsForm extends React.Component {
</Select>, </Select>,
)} )}
</Form.Item> </Form.Item>
{forbiddenErrors.tags && (
<Alert
message="You don't have permission to view tags."
type="warning"
banner
closable
/>
)}
<Form.Item {...formItemLayout} label="Tags"> <Form.Item {...formItemLayout} label="Tags">
{getFieldDecorator('tags', { {getFieldDecorator('tags', {
rules: [ rules: [

@ -31,6 +31,7 @@ import {
Alert, Alert,
} from 'antd'; } from 'antd';
import '@babel/polyfill'; import '@babel/polyfill';
import Authorized from '../../../../../../../../components/Authorized/Authorized';
const { Text } = Typography; const { Text } = Typography;
@ -466,14 +467,16 @@ class NewAppUploadForm extends React.Component {
{formConfig.installationType !== 'WEB_CLIP' && {formConfig.installationType !== 'WEB_CLIP' &&
formConfig.installationType !== 'CUSTOM' && ( formConfig.installationType !== 'CUSTOM' && (
<div> <div>
{this.props.forbiddenErrors.supportedOsVersions && ( <Authorized
permission="/permission/admin/device-mgt/admin/device-type"
no={
<Alert <Alert
message="You don't have permission to view supported OS versions." message="You don't have permission to view supported OS versions."
type="warning" type="warning"
banner banner
closable
/> />
)} }
/>
<Form.Item <Form.Item
{...formItemLayout} {...formItemLayout}
label="Supported OS Versions" label="Supported OS Versions"

@ -149,18 +149,9 @@ class AddNewAppFormComponent extends React.Component {
'Error occurred while trying to load supported OS versions.', 'Error occurred while trying to load supported OS versions.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.supportedOsVersions = true;
this.setState({ this.setState({
forbiddenErrors,
loading: false, loading: false,
}); });
} else {
this.setState({
loading: false,
});
}
}); });
}; };
@ -171,7 +162,6 @@ class AddNewAppFormComponent extends React.Component {
isError, isError,
supportedOsVersions, supportedOsVersions,
errorText, errorText,
forbiddenErrors,
} = this.state; } = this.state;
const { formConfig } = this.props; const { formConfig } = this.props;
return ( return (
@ -193,7 +183,6 @@ class AddNewAppFormComponent extends React.Component {
</div> </div>
<div style={{ display: current === 1 ? 'unset' : 'none' }}> <div style={{ display: current === 1 ? 'unset' : 'none' }}>
<NewAppUploadForm <NewAppUploadForm
forbiddenErrors={forbiddenErrors}
formConfig={formConfig} formConfig={formConfig}
supportedOsVersions={supportedOsVersions} supportedOsVersions={supportedOsVersions}
onSuccessReleaseData={this.onSuccessReleaseData} onSuccessReleaseData={this.onSuccessReleaseData}

@ -17,9 +17,10 @@
*/ */
import React from 'react'; import React from 'react';
import { PageHeader, Typography, Breadcrumb, Icon } from 'antd'; import { PageHeader, Typography, Breadcrumb, Icon, Result } from 'antd';
import AddNewAppForm from '../../components/AddNewAppForm'; import AddNewAppForm from '../../components/AddNewAppForm';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography; const { Paragraph } = Typography;
@ -70,7 +71,17 @@ class AddNewCustomApp extends React.Component {
</div> </div>
</PageHeader> </PageHeader>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}>
<AddNewAppForm formConfig={formConfig} /> <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={<AddNewAppForm formConfig={formConfig} />}
no={
<Result
status="403"
title="You don't have permission to add new apps."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
</div> </div>
); );

@ -17,9 +17,10 @@
*/ */
import React from 'react'; import React from 'react';
import { PageHeader, Typography, Breadcrumb, Icon } from 'antd'; import { PageHeader, Typography, Breadcrumb, Icon, Result } from 'antd';
import AddNewAppForm from '../../components/AddNewAppForm'; import AddNewAppForm from '../../components/AddNewAppForm';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography; const { Paragraph } = Typography;
@ -64,7 +65,17 @@ class AddNewEnterpriseApp extends React.Component {
</div> </div>
</PageHeader> </PageHeader>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}>
<AddNewAppForm formConfig={formConfig} /> <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={<AddNewAppForm formConfig={formConfig} />}
no={
<Result
status="403"
title="You don't have permission to add new apps."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
</div> </div>
); );

@ -17,9 +17,10 @@
*/ */
import React from 'react'; import React from 'react';
import { Icon, PageHeader, Typography, Breadcrumb } from 'antd'; import { Icon, PageHeader, Typography, Breadcrumb, Result } from 'antd';
import AddNewAppForm from '../../components/AddNewAppForm'; import AddNewAppForm from '../../components/AddNewAppForm';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography; const { Paragraph } = Typography;
@ -72,7 +73,17 @@ class AddNewPublicApp extends React.Component {
</div> </div>
</PageHeader> </PageHeader>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}>
<AddNewAppForm formConfig={formConfig} /> <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={<AddNewAppForm formConfig={formConfig} />}
no={
<Result
status="403"
title="You don't have permission to add new apps."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
</div> </div>
); );

@ -17,9 +17,10 @@
*/ */
import React from 'react'; import React from 'react';
import { Icon, PageHeader, Typography, Breadcrumb } from 'antd'; import { Icon, PageHeader, Typography, Breadcrumb, Result } from 'antd';
import AddNewAppForm from '../../components/AddNewAppForm'; import AddNewAppForm from '../../components/AddNewAppForm';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography; const { Paragraph } = Typography;
@ -65,7 +66,17 @@ class AddNewEnterpriseApp extends React.Component {
</div> </div>
</PageHeader> </PageHeader>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}>
<AddNewAppForm formConfig={formConfig} /> <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={<AddNewAppForm formConfig={formConfig} />}
no={
<Result
status="403"
title="You don't have permission to add new apps."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
</div> </div>
); );

@ -44,6 +44,8 @@ import pSBC from 'shade-blend-color';
import { withConfigContext } from '../../../../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../../../../components/ConfigContext';
import ManagedConfigurationsIframe from './components/ManagedConfigurationsIframe'; import ManagedConfigurationsIframe from './components/ManagedConfigurationsIframe';
import { handleApiError } from '../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../services/utils/errorHandler';
import Authorized from '../../../../../../../../../components/Authorized/Authorized';
import { isAuthorized } from '../../../../../../../../../services/utils/authorizationHandler';
const { Meta } = Card; const { Meta } = Card;
const { Text, Title } = Typography; const { Text, Title } = Typography;
@ -100,7 +102,15 @@ class AppDetailsDrawer extends React.Component {
} }
componentDidMount() { componentDidMount() {
if (
isAuthorized(
this.props.context.user,
'/permission/admin/app-mgt/publisher/application/update',
)
) {
this.getCategories(); this.getCategories();
this.getTags();
}
} }
componentDidUpdate(prevProps, prevState, snapshot) { componentDidUpdate(prevProps, prevState, snapshot) {
@ -130,7 +140,6 @@ class AppDetailsDrawer extends React.Component {
.then(res => { .then(res => {
if (res.status === 200) { if (res.status === 200) {
const categories = JSON.parse(res.data.data); const categories = JSON.parse(res.data.data);
this.getTags();
const globalCategories = categories.map(category => { const globalCategories = categories.map(category => {
return ( return (
<Option key={category.categoryName}> <Option key={category.categoryName}>
@ -520,27 +529,37 @@ class AppDetailsDrawer extends React.Component {
<Spin spinning={loading} delay={500}> <Spin spinning={loading} delay={500}>
<div style={{ textAlign: 'center' }}> <div style={{ textAlign: 'center' }}>
{avatar} {avatar}
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
<Title editable={{ onChange: this.handleNameSave }} level={2}> <Title editable={{ onChange: this.handleNameSave }} level={2}>
{name} {name}
</Title> </Title>
}
no={<Title level={2}>{name}</Title>}
/>
</div> </div>
<Divider /> <Divider />
{/* display manage config button only if the app is public android app*/} {/* display manage config button only if the app is public android app*/}
{app.isAndroidEnterpriseApp && {app.isAndroidEnterpriseApp &&
config.androidEnterpriseToken !== null && ( config.androidEnterpriseToken !== null && (
<Authorized
permission="/permission/admin/device-mgt/enterprise/user/modify"
yes={
<div> <div>
<div> <div>
<Text strong={true}>Set up managed configurations</Text> <Text strong={true}>Set up managed configurations</Text>
</div> </div>
<div style={{ paddingTop: 16 }}> <div style={{ paddingTop: 16 }}>
<Text> <Text>
If you are developing apps for the enterprise market, you If you are developing apps for the enterprise market,
may need to satisfy particular requirements set by a you may need to satisfy particular requirements set by
organization&apos;s policies. Managed configurations, a organization&apos;s policies. Managed
previously known as application restrictions, allow the configurations, previously known as application
organization&apos;s IT admin to remotely specify settings restrictions, allow the organization&apos;s IT admin
for apps. This capability is particularly useful for to remotely specify settings for apps. This capability
organization-approved apps deployed to a work profile. is particularly useful for organization-approved apps
deployed to a work profile.
</Text> </Text>
</div> </div>
<br /> <br />
@ -550,6 +569,8 @@ class AppDetailsDrawer extends React.Component {
/> />
<Divider dashed={true} /> <Divider dashed={true} />
</div> </div>
}
/>
)} )}
<Text strong={true}>Releases </Text> <Text strong={true}>Releases </Text>
<div className="releases-details"> <div className="releases-details">
@ -640,6 +661,9 @@ class AppDetailsDrawer extends React.Component {
{/* display add new release only if app type is enterprise*/} {/* display add new release only if app type is enterprise*/}
{app.type === 'ENTERPRISE' && ( {app.type === 'ENTERPRISE' && (
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
<div> <div>
<Divider dashed={true} /> <Divider dashed={true} />
<div style={{ paddingBottom: 16 }}> <div style={{ paddingBottom: 16 }}>
@ -653,11 +677,16 @@ class AppDetailsDrawer extends React.Component {
</Button> </Button>
</Link> </Link>
</div> </div>
}
/>
)} )}
<Divider dashed={true} /> <Divider dashed={true} />
<Text strong={true}>Description </Text> <Text strong={true}>Description </Text>
{!isDescriptionEditEnabled && ( <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
!isDescriptionEditEnabled && (
<Text <Text
style={{ style={{
color: config.theme.primaryColor, color: config.theme.primaryColor,
@ -667,7 +696,9 @@ class AppDetailsDrawer extends React.Component {
> >
<Icon type="edit" /> <Icon type="edit" />
</Text> </Text>
)} )
}
/>
{!isDescriptionEditEnabled && ( {!isDescriptionEditEnabled && (
<div>{ReactHtmlParser(description)}</div> <div>{ReactHtmlParser(description)}</div>
@ -708,14 +739,22 @@ class AppDetailsDrawer extends React.Component {
<Divider dashed={true} /> <Divider dashed={true} />
<Text strong={true}>Categories </Text> <Text strong={true}>Categories </Text>
{!isCategoriesEditEnabled && ( <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
!isCategoriesEditEnabled && (
<Text <Text
style={{ color: config.theme.primaryColor, cursor: 'pointer' }} style={{
color: config.theme.primaryColor,
cursor: 'pointer',
}}
onClick={this.enableCategoriesEdit} onClick={this.enableCategoriesEdit}
> >
<Icon type="edit" /> <Icon type="edit" />
</Text> </Text>
)} )
}
/>
<br /> <br />
<br /> <br />
{isCategoriesEditEnabled && ( {isCategoriesEditEnabled && (
@ -767,14 +806,22 @@ class AppDetailsDrawer extends React.Component {
<Divider dashed={true} /> <Divider dashed={true} />
<Text strong={true}>Tags </Text> <Text strong={true}>Tags </Text>
{!isTagsEditEnabled && ( <Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
!isTagsEditEnabled && (
<Text <Text
style={{ color: config.theme.primaryColor, cursor: 'pointer' }} style={{
color: config.theme.primaryColor,
cursor: 'pointer',
}}
onClick={this.enableTagsEdit} onClick={this.enableTagsEdit}
> >
<Icon type="edit" /> <Icon type="edit" />
</Text> </Text>
)} )
}
/>
<br /> <br />
<br /> <br />
{isTagsEditEnabled && ( {isTagsEditEnabled && (
@ -819,9 +866,11 @@ class AppDetailsDrawer extends React.Component {
})} })}
</span> </span>
)} )}
<Authorized
permission="/permission/admin/app-mgt/publisher/review/view"
yes={
<div>
<Divider dashed={true} /> <Divider dashed={true} />
<div className="app-rate"> <div className="app-rate">
{app.applicationReleases.length > 0 && ( {app.applicationReleases.length > 0 && (
<DetailedRating <DetailedRating
@ -830,6 +879,9 @@ class AppDetailsDrawer extends React.Component {
/> />
)} )}
</div> </div>
</div>
}
/>
</Spin> </Spin>
</Drawer> </Drawer>
</div> </div>

@ -26,11 +26,11 @@ import {
Select, Select,
Button, Button,
Form, Form,
Alert,
} from 'antd'; } from 'antd';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../../../components/ConfigContext';
import { handleApiError } from '../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../services/utils/errorHandler';
import Authorized from '../../../../../../../../components/Authorized/Authorized';
const { Option } = Select; const { Option } = Select;
const { Title } = Typography; const { Title } = Typography;
@ -42,11 +42,6 @@ class FiltersForm extends React.Component {
categories: [], categories: [],
tags: [], tags: [],
deviceTypes: [], deviceTypes: [],
forbiddenErrors: {
categories: false,
tags: false,
deviceTypes: false,
},
}; };
} }
@ -101,18 +96,9 @@ class FiltersForm extends React.Component {
'Error occurred while trying to load categories.', 'Error occurred while trying to load categories.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.categories = true;
this.setState({ this.setState({
forbiddenErrors,
loading: false, loading: false,
}); });
} else {
this.setState({
loading: false,
});
}
}); });
}; };
@ -140,18 +126,9 @@ class FiltersForm extends React.Component {
'Error occurred while trying to load tags.', 'Error occurred while trying to load tags.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.tags = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({ this.setState({
loading: false, loading: false,
}); });
}
}); });
}; };
@ -179,23 +156,14 @@ class FiltersForm extends React.Component {
'Error occurred while trying to load device types.', 'Error occurred while trying to load device types.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.deviceTypes = true;
this.setState({ this.setState({
forbiddenErrors,
loading: false, loading: false,
}); });
} else {
this.setState({
loading: false,
});
}
}); });
}; };
render() { render() {
const { categories, tags, deviceTypes, forbiddenErrors } = this.state; const { categories, tags, deviceTypes } = this.state;
const { getFieldDecorator } = this.props.form; const { getFieldDecorator } = this.props.form;
return ( return (
@ -224,14 +192,10 @@ class FiltersForm extends React.Component {
</Form.Item> </Form.Item>
</Col> </Col>
</Row> </Row>
{forbiddenErrors.categories && ( <Authorized
<Alert permission="/permission/admin/app-mgt/publisher/application/update"
message="You don't have permission to view categories." yes={
type="warning" <div>
banner
closable
/>
)}
<Form.Item label="Categories"> <Form.Item label="Categories">
{getFieldDecorator('categories', { {getFieldDecorator('categories', {
rules: [ rules: [
@ -257,66 +221,56 @@ class FiltersForm extends React.Component {
</Select>, </Select>,
)} )}
</Form.Item> </Form.Item>
<Form.Item label="Tags">
{forbiddenErrors.deviceTypes && ( {getFieldDecorator('tags', {
<Alert
message="You don't have permission to view device types."
type="warning"
banner
closable
/>
)}
<Form.Item label="Device Type">
{getFieldDecorator('deviceType', {
rules: [ rules: [
{ {
required: false, required: false,
message: 'Please select device types', message: 'Please select tags',
}, },
], ],
})( })(
<Select <Select
mode="multiple"
style={{ width: '100%' }} style={{ width: '100%' }}
placeholder="Select device types" placeholder="Select tags"
> >
{deviceTypes.map(deviceType => { {tags.map(tag => {
return ( return <Option key={tag.tagName}>{tag.tagName}</Option>;
<Option key={deviceType.name}>{deviceType.name}</Option>
);
})} })}
<Option key="ALL">All</Option>
</Select>, </Select>,
)} )}
</Form.Item> </Form.Item>
{forbiddenErrors.tags && ( </div>
<Alert }
message="You don't have permission to view tags."
type="warning"
banner
closable
/> />
)} <Authorized
<Form.Item label="Tags"> permission="/permission/admin/device-mgt/admin/device-type/view"
{getFieldDecorator('tags', { yes={
<Form.Item label="Device Type">
{getFieldDecorator('deviceType', {
rules: [ rules: [
{ {
required: false, required: false,
message: 'Please select tags', message: 'Please select device types',
}, },
], ],
})( })(
<Select <Select
mode="multiple"
style={{ width: '100%' }} style={{ width: '100%' }}
placeholder="Select tags" placeholder="Select device types"
> >
{tags.map(tag => { {deviceTypes.map(deviceType => {
return <Option key={tag.tagName}>{tag.tagName}</Option>; return (
<Option key={deviceType.name}>{deviceType.name}</Option>
);
})} })}
<Option key="ALL">All</Option>
</Select>, </Select>,
)} )}
</Form.Item> </Form.Item>
}
/>
<Form.Item label="App Type"> <Form.Item label="App Type">
{getFieldDecorator('appType', {})( {getFieldDecorator('appType', {})(
<Select style={{ width: '100%' }} placeholder="Select app type"> <Select style={{ width: '100%' }} placeholder="Select app type">

@ -18,6 +18,8 @@
import React from 'react'; import React from 'react';
import AppList from './components/AppList'; import AppList from './components/AppList';
import Authorized from '../../../../components/Authorized/Authorized';
import { Result } from 'antd';
class Apps extends React.Component { class Apps extends React.Component {
routes; routes;
@ -30,7 +32,17 @@ class Apps extends React.Component {
return ( return (
<div> <div>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 780 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 780 }}>
<AppList /> <Authorized
permission="/permission/admin/app-mgt/publisher/application/view"
yes={<AppList />}
no={
<Result
status="403"
title="You don't have permission to view apps."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
</div> </div>
); );

@ -36,6 +36,7 @@ import {
import axios from 'axios'; import axios from 'axios';
import '@babel/polyfill'; import '@babel/polyfill';
import { withConfigContext } from '../../../../../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../components/ConfigContext';
import Authorized from '../../../../../../../../../../components/Authorized/Authorized';
const { TextArea } = Input; const { TextArea } = Input;
const InputGroup = Input.Group; const InputGroup = Input.Group;
@ -549,14 +550,16 @@ class EditReleaseModal extends React.Component {
</Form.Item> </Form.Item>
{config.deviceTypes.mobileTypes.includes(deviceType) && ( {config.deviceTypes.mobileTypes.includes(deviceType) && (
<div> <div>
{this.props.forbiddenErrors.supportedOsVersions && ( <Authorized
permission="/permission/admin/device-mgt/admin/device-type"
no={
<Alert <Alert
message="You don't have permission to view supported OS versions." message="You don't have permission to view supported OS versions."
type="warning" type="warning"
banner banner
closable
/> />
)} }
/>
<Form.Item <Form.Item
{...formItemLayout} {...formItemLayout}
label="Supported OS Versions" label="Supported OS Versions"

@ -17,7 +17,7 @@
*/ */
import React from 'react'; import React from 'react';
import { List, Spin, Button, Alert } from 'antd'; import { List, Spin, Button } from 'antd';
import './styles.css'; import './styles.css';
import InfiniteScroll from 'react-infinite-scroller'; import InfiniteScroll from 'react-infinite-scroller';
@ -130,14 +130,6 @@ class Reviews extends React.Component {
render() { render() {
return ( return (
<div> <div>
{this.state.forbiddenErrors.reviews && (
<Alert
message="You don't have permission to view reviews."
type="warning"
banner
closable
/>
)}
<div className="demo-infinite-container"> <div className="demo-infinite-container">
<InfiniteScroll <InfiniteScroll
initialLoad={false} initialLoad={false}

@ -17,13 +17,23 @@
*/ */
import React from 'react'; import React from 'react';
import { Divider, Row, Col, Typography, Button, Icon, Tooltip } from 'antd'; import {
Divider,
Row,
Col,
Typography,
Button,
Icon,
Tooltip,
Alert,
} from 'antd';
import StarRatings from 'react-star-ratings'; import StarRatings from 'react-star-ratings';
import Reviews from './components/Reviews'; import Reviews from './components/Reviews';
import '../../../../../../../../App.css'; import '../../../../../../../../App.css';
import DetailedRating from '../../../../components/DetailedRating'; import DetailedRating from '../../../../components/DetailedRating';
import EditRelease from './components/EditRelease'; import EditRelease from './components/EditRelease';
import { withConfigContext } from '../../../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../../../components/ConfigContext';
import Authorized from '../../../../../../../../components/Authorized/Authorized';
const { Title, Text, Paragraph } = Typography; const { Title, Text, Paragraph } = Typography;
@ -33,22 +43,19 @@ class ReleaseView extends React.Component {
this.state = {}; this.state = {};
} }
componentDidMount() {
console.log('mounted: Release view');
}
render() { render() {
const { app, release } = this.props; const { app, release } = this.props;
const config = this.props.context; const config = this.props.context;
const { lifecycle, currentLifecycleStatus } = this.props; const { lifecycle, currentLifecycleStatus } = this.props;
if (release == null) {
if (release == null || lifecycle == null) {
return null; return null;
} }
let isAppUpdatable,
const { isAppUpdatable, isAppInstallable } = lifecycle[ isAppInstallable = false;
currentLifecycleStatus if (lifecycle != null) {
]; isAppUpdatable = lifecycle[currentLifecycleStatus].isAppUpdatable;
isAppInstallable = lifecycle[currentLifecycleStatus].isAppInstallable;
}
const platform = app.deviceType; const platform = app.deviceType;
const defaultPlatformIcons = config.defaultPlatformIcons; const defaultPlatformIcons = config.defaultPlatformIcons;
@ -93,9 +100,10 @@ class ReleaseView extends React.Component {
<Divider type="vertical" /> <Divider type="vertical" />
<Text>Version : {release.version}</Text> <Text>Version : {release.version}</Text>
<br /> <br />
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
<EditRelease <EditRelease
forbiddenErrors={this.props.forbiddenErrors}
isAppUpdatable={isAppUpdatable} isAppUpdatable={isAppUpdatable}
type={app.type} type={app.type}
deviceType={app.deviceType} deviceType={app.deviceType}
@ -103,9 +111,14 @@ class ReleaseView extends React.Component {
updateRelease={this.props.updateRelease} updateRelease={this.props.updateRelease}
supportedOsVersions={[...this.props.supportedOsVersions]} supportedOsVersions={[...this.props.supportedOsVersions]}
/> />
}
/>
</Col> </Col>
<Col xl={8} md={10} sm={24} xs={24} style={{ float: 'right' }}> <Col xl={8} md={10} sm={24} xs={24} style={{ float: 'right' }}>
<div> <div>
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
<Tooltip <Tooltip
title={ title={
isAppInstallable isAppInstallable
@ -132,6 +145,8 @@ class ReleaseView extends React.Component {
Open in store Open in store
</Button> </Button>
</Tooltip> </Tooltip>
}
/>
</div> </div>
</Col> </Col>
</Row> </Row>
@ -173,6 +188,10 @@ class ReleaseView extends React.Component {
</Row> </Row>
<Divider /> <Divider />
<Text>REVIEWS</Text> <Text>REVIEWS</Text>
<Authorized
permission="/permission/admin/app-mgt/publisher/admin/review/view"
yes={
<div>
<Row> <Row>
<Col lg={18}> <Col lg={18}>
<DetailedRating type="release" uuid={release.uuid} /> <DetailedRating type="release" uuid={release.uuid} />
@ -180,6 +199,17 @@ class ReleaseView extends React.Component {
</Row> </Row>
<Reviews type="release" uuid={release.uuid} /> <Reviews type="release" uuid={release.uuid} />
</div> </div>
}
no={
<Alert
message="You don't have permission to view reviews."
type="warning"
banner
closable
/>
}
/>
</div>
</div> </div>
); );
} }

@ -24,6 +24,8 @@ import ReleaseView from './components/ReleaseView';
import LifeCycle from './components/LifeCycle'; import LifeCycle from './components/LifeCycle';
import { withConfigContext } from '../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../components/ConfigContext';
import { handleApiError } from '../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../services/utils/errorHandler';
import Authorized from '../../../../../../components/Authorized/Authorized';
import { isAuthorized } from '../../../../../../services/utils/authorizationHandler';
const { Title } = Typography; const { Title } = Typography;
@ -41,18 +43,21 @@ class Release extends React.Component {
currentLifecycleStatus: null, currentLifecycleStatus: null,
lifecycle: null, lifecycle: null,
supportedOsVersions: [], supportedOsVersions: [],
forbiddenErrors: {
supportedOsVersions: false,
lifeCycle: false,
},
}; };
} }
componentDidMount() { componentDidMount() {
const { uuid } = this.props.match.params; const { uuid } = this.props.match.params;
this.fetchData(uuid); this.fetchData(uuid);
if (
isAuthorized(
this.props.context.user,
'/permission/admin/app-mgt/publisher/application/update',
)
) {
this.getLifecycle(); this.getLifecycle();
} }
}
changeCurrentLifecycleStatus = status => { changeCurrentLifecycleStatus = status => {
this.setState({ this.setState({
@ -92,7 +97,16 @@ class Release extends React.Component {
uuid: uuid, uuid: uuid,
}); });
if (config.deviceTypes.mobileTypes.includes(app.deviceType)) { if (config.deviceTypes.mobileTypes.includes(app.deviceType)) {
if (
isAuthorized(
config.user,
'/permission/admin/device-mgt/admin/device-type',
)
) {
this.getSupportedOsVersions(app.deviceType); this.getSupportedOsVersions(app.deviceType);
} else {
this.setState({ loading: false });
}
} }
} }
}) })
@ -128,13 +142,6 @@ class Release extends React.Component {
'Error occurred while trying to load lifecycle configuration.', 'Error occurred while trying to load lifecycle configuration.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.lifeCycle = true;
this.setState({
forbiddenErrors,
});
}
}); });
}; };
@ -161,18 +168,9 @@ class Release extends React.Component {
'Error occurred while trying to load supported OS versions.', 'Error occurred while trying to load supported OS versions.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.supportedOsVersions = true;
this.setState({ this.setState({
forbiddenErrors,
loading: false, loading: false,
}); });
} else {
this.setState({
loading: false,
});
}
}); });
}; };
@ -193,7 +191,6 @@ class Release extends React.Component {
</div> </div>
); );
} }
// todo remove uppercase // todo remove uppercase
return ( return (
<div> <div>
@ -221,6 +218,9 @@ class Release extends React.Component {
</Skeleton> </Skeleton>
</Card> </Card>
</Col> </Col>
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
<Col lg={8} md={24} style={{ padding: 3 }}> <Col lg={8} md={24} style={{ padding: 3 }}>
<Card lg={8} md={24}> <Card lg={8} md={24}>
<Skeleton loading={loading} active paragraph={{ rows: 8 }}> <Skeleton loading={loading} active paragraph={{ rows: 8 }}>
@ -237,6 +237,8 @@ class Release extends React.Component {
</Skeleton> </Skeleton>
</Card> </Card>
</Col> </Col>
}
/>
</Row> </Row>
</div> </div>
</div> </div>

@ -40,6 +40,7 @@ import { TweenOneGroup } from 'rc-tween-one';
import pSBC from 'shade-blend-color'; import pSBC from 'shade-blend-color';
import { withConfigContext } from '../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../components/ConfigContext';
import { handleApiError } from '../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../services/utils/errorHandler';
import { isAuthorized } from '../../../../../../services/utils/authorizationHandler';
const { Title } = Typography; const { Title } = Typography;
@ -62,6 +63,10 @@ class ManageCategories extends React.Component {
componentDidMount() { componentDidMount() {
const config = this.props.context; const config = this.props.context;
this.hasPermissionToManage = isAuthorized(
config.user,
'/permission/admin/app-mgt/publisher/admin/application/update',
);
axios axios
.get( .get(
window.location.origin + window.location.origin +
@ -84,18 +89,9 @@ class ManageCategories extends React.Component {
'Error occured while trying to load categories', 'Error occured while trying to load categories',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.categories = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({ this.setState({
loading: false, loading: false,
}); });
}
}); });
} }
@ -157,6 +153,8 @@ class ManageCategories extends React.Component {
style={{ marginTop: 8 }} style={{ marginTop: 8 }}
> >
{categoryName} {categoryName}
{this.hasPermissionToManage && (
<>
<Divider type="vertical" /> <Divider type="vertical" />
<Tooltip title="edit"> <Tooltip title="edit">
<Icon <Icon
@ -187,6 +185,8 @@ class ManageCategories extends React.Component {
<Icon type="delete" /> <Icon type="delete" />
</Popconfirm> </Popconfirm>
</Tooltip> </Tooltip>
</>
)}
</Tag> </Tag>
); );
return ( return (
@ -377,18 +377,16 @@ class ManageCategories extends React.Component {
inputValue, inputValue,
tempElements, tempElements,
isAddNewVisible, isAddNewVisible,
forbiddenErrors,
} = this.state; } = this.state;
const categoriesElements = categories.map(this.renderElement); const categoriesElements = categories.map(this.renderElement);
const temporaryElements = tempElements.map(this.renderTempElement); const temporaryElements = tempElements.map(this.renderTempElement);
return ( return (
<div style={{ marginBottom: 16 }}> <div style={{ marginBottom: 16 }}>
{forbiddenErrors.categories && ( {!this.hasPermissionToManage && (
<Alert <Alert
message="You don't have permission to view categories." message="You don't have permission to add / edit / delete categories."
type="warning" type="warning"
banner banner
closable
/> />
)} )}
<Card> <Card>
@ -414,6 +412,7 @@ class ManageCategories extends React.Component {
); );
}} }}
htmlType="button" htmlType="button"
disabled={!this.hasPermissionToManage}
> >
Add Add
</Button> </Button>

@ -39,6 +39,7 @@ import axios from 'axios';
import { TweenOneGroup } from 'rc-tween-one'; import { TweenOneGroup } from 'rc-tween-one';
import { withConfigContext } from '../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../components/ConfigContext';
import { handleApiError } from '../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../services/utils/errorHandler';
import { isAuthorized } from '../../../../../../services/utils/authorizationHandler';
const { Title } = Typography; const { Title } = Typography;
@ -61,6 +62,10 @@ class ManageTags extends React.Component {
componentDidMount() { componentDidMount() {
const config = this.props.context; const config = this.props.context;
this.hasPermissionToManage = isAuthorized(
config.user,
'/permission/admin/app-mgt/publisher/admin/application/update',
);
axios axios
.get( .get(
window.location.origin + window.location.origin +
@ -83,18 +88,9 @@ class ManageTags extends React.Component {
'Error occurred while trying to load tags.', 'Error occurred while trying to load tags.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.tags = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({ this.setState({
loading: false, loading: false,
}); });
}
}); });
} }
@ -151,6 +147,8 @@ class ManageTags extends React.Component {
const tagElem = ( const tagElem = (
<Tag color="#34495e" style={{ marginTop: 8 }}> <Tag color="#34495e" style={{ marginTop: 8 }}>
{tagName} {tagName}
{this.hasPermissionToManage && (
<>
<Divider type="vertical" /> <Divider type="vertical" />
<Tooltip title="edit"> <Tooltip title="edit">
<Icon <Icon
@ -181,6 +179,8 @@ class ManageTags extends React.Component {
<Icon type="delete" /> <Icon type="delete" />
</Popconfirm> </Popconfirm>
</Tooltip> </Tooltip>
</>
)}
</Tag> </Tag>
); );
return ( return (
@ -368,18 +368,16 @@ class ManageTags extends React.Component {
inputValue, inputValue,
tempElements, tempElements,
isAddNewVisible, isAddNewVisible,
forbiddenErrors,
} = this.state; } = this.state;
const tagsElements = tags.map(this.renderElement); const tagsElements = tags.map(this.renderElement);
const temporaryElements = tempElements.map(this.renderTempElement); const temporaryElements = tempElements.map(this.renderTempElement);
return ( return (
<div style={{ marginBottom: 16 }}> <div style={{ marginBottom: 16 }}>
{forbiddenErrors.tags && ( {!this.hasPermissionToManage && (
<Alert <Alert
message="You don't have permission to view tags." message="You don't have permission to add / edit / delete tags."
type="warning" type="warning"
banner banner
closable
/> />
)} )}
<Card> <Card>
@ -405,6 +403,7 @@ class ManageTags extends React.Component {
); );
}} }}
htmlType="button" htmlType="button"
disabled={!this.hasPermissionToManage}
> >
Add Add
</Button> </Button>

@ -21,6 +21,7 @@ import { PageHeader, Typography, Breadcrumb, Row, Col, Icon } from 'antd';
import ManageCategories from './components/Categories'; import ManageCategories from './components/Categories';
import ManageTags from './components/Tags'; import ManageTags from './components/Tags';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import Authorized from '../../../../components/Authorized/Authorized';
const { Paragraph } = Typography; const { Paragraph } = Typography;
@ -54,12 +55,19 @@ class Manage extends React.Component {
</PageHeader> </PageHeader>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 780 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 780 }}>
<Row gutter={16}> <Row gutter={16}>
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
<>
<Col sm={24} md={12}> <Col sm={24} md={12}>
<ManageCategories /> <ManageCategories />
</Col> </Col>
<Col sm={24} md={12}> <Col sm={24} md={12}>
<ManageTags /> <ManageTags />
</Col> </Col>
</>
}
/>
</Row> </Row>
</div> </div>
</div> </div>

@ -34,6 +34,7 @@ import './styles.css';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import AddNewPage from './components/AddNewPage'; import AddNewPage from './components/AddNewPage';
import { handleApiError } from '../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../services/utils/errorHandler';
import { isAuthorized } from '../../../../../../../../services/utils/authorizationHandler';
const { Text, Title } = Typography; const { Text, Title } = Typography;
@ -47,6 +48,10 @@ class Pages extends React.Component {
selectedRows: [], selectedRows: [],
homePageId: null, homePageId: null,
}; };
this.hasPermissionToManage = isAuthorized(
this.props.config.user,
'/device-mgt/enterprise/user/view',
);
} }
rowSelection = { rowSelection = {
@ -226,6 +231,8 @@ class Pages extends React.Component {
key: 'actions', key: 'actions',
render: (name, page) => ( render: (name, page) => (
<div> <div>
{this.hasPermissionToManage && (
<>
<span className="action"> <span className="action">
<Button <Button
disabled={page.id === this.state.homePageId} disabled={page.id === this.state.homePageId}
@ -254,6 +261,8 @@ class Pages extends React.Component {
</Text> </Text>
</span> </span>
</Popconfirm> </Popconfirm>
</>
)}
</div> </div>
), ),
}, },

@ -17,12 +17,13 @@
*/ */
import React from 'react'; import React from 'react';
import { PageHeader, Breadcrumb, Divider, Icon } from 'antd'; import { PageHeader, Breadcrumb, Divider, Icon, Result } from 'antd';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import SyncAndroidApps from './components/SyncAndroidApps'; import SyncAndroidApps from './components/SyncAndroidApps';
import { withConfigContext } from '../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../components/ConfigContext';
import GooglePlayIframe from './components/GooglePlayIframe'; import GooglePlayIframe from './components/GooglePlayIframe';
import Pages from './components/Pages'; import Pages from './components/Pages';
import Authorized from '../../../../../../components/Authorized/Authorized';
class ManageAndroidEnterprise extends React.Component { class ManageAndroidEnterprise extends React.Component {
routes; routes;
@ -52,10 +53,27 @@ class ManageAndroidEnterprise extends React.Component {
</div> </div>
</PageHeader> </PageHeader>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}>
<Authorized
permission="/permission/admin/device-mgt/enterprise/user/view"
yes={
<>
<SyncAndroidApps /> <SyncAndroidApps />
<GooglePlayIframe /> <Authorized
permission="/permission/admin/device-mgt/enterprise/user/modify"
yes={<GooglePlayIframe />}
/>
<Divider /> <Divider />
<Pages /> <Pages />
</>
}
no={
<Result
status="403"
title="You don't have permission to view android enterprise configurations."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
</div> </div>
); );

@ -295,6 +295,7 @@ class Cluster extends React.Component {
} }
return ( return (
<div className="product"> <div className="product">
{this.props.hasPermissionToManage && (
<div className="arrow"> <div className="arrow">
<button <button
disabled={index === 0} disabled={index === 0}
@ -306,12 +307,15 @@ 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}>
<div className="title">{packageId}</div> <div className="title">{packageId}</div>
</Tooltip> </Tooltip>
</div> </div>
{this.props.hasPermissionToManage && (
<>
<div className="arrow"> <div className="arrow">
<button <button
disabled={index === products.length - 1} disabled={index === products.length - 1}
@ -333,6 +337,8 @@ class Cluster extends React.Component {
<Icon type="close-circle" theme="filled" /> <Icon type="close-circle" theme="filled" />
</button> </button>
</div> </div>
</>
)}
</div> </div>
); );
}; };
@ -347,7 +353,7 @@ class Cluster extends React.Component {
</Title> </Title>
</Col> </Col>
<Col span={8}> <Col span={8}>
{!isTemporary && ( {!isTemporary && this.props.hasPermissionToManage && (
<div style={{ float: 'right' }}> <div style={{ float: 'right' }}>
<Tooltip title="Move Up"> <Tooltip title="Move Up">
<Button <Button
@ -391,10 +397,12 @@ class Cluster extends React.Component {
</Col> </Col>
</Row> </Row>
<div className="products-row"> <div className="products-row">
{this.props.hasPermissionToManage && (
<AddAppsToClusterModal <AddAppsToClusterModal
addSelectedProducts={this.addSelectedProducts} addSelectedProducts={this.addSelectedProducts}
unselectedProducts={unselectedProducts} unselectedProducts={unselectedProducts}
/> />
)}
{products.map((product, index) => { {products.map((product, index) => {
return ( return (
<Product <Product

@ -30,6 +30,7 @@ import {
Spin, Spin,
Tag, Tag,
Divider, Divider,
Result,
} from 'antd'; } from 'antd';
import { Link, withRouter } from 'react-router-dom'; import { Link, withRouter } from 'react-router-dom';
import { withConfigContext } from '../../../../../../../../components/ConfigContext'; import { withConfigContext } from '../../../../../../../../components/ConfigContext';
@ -37,6 +38,8 @@ import axios from 'axios';
import Cluster from './components/Cluster'; import Cluster from './components/Cluster';
import EditLinks from './components/EditLinks'; import EditLinks from './components/EditLinks';
import { handleApiError } from '../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../services/utils/errorHandler';
import Authorized from '../../../../../../../../components/Authorized/Authorized';
import { isAuthorized } from '../../../../../../../../services/utils/authorizationHandler';
const { Title } = Typography; const { Title } = Typography;
@ -59,6 +62,10 @@ class Page extends React.Component {
isAddNewClusterVisible: false, isAddNewClusterVisible: false,
links: [], links: [],
}; };
this.hasPermissionToManage = isAuthorized(
this.props.config.user,
'/device-mgt/enterprise/user/view',
);
} }
componentDidMount() { componentDidMount() {
@ -328,11 +335,19 @@ class Page extends React.Component {
{/* <Paragraph>Lorem ipsum</Paragraph>*/} {/* <Paragraph>Lorem ipsum</Paragraph>*/}
</div> </div>
</PageHeader> </PageHeader>
<Authorized
permission="/permission/admin/device-mgt/enterprise/user/view"
yes={
<Spin spinning={loading}> <Spin spinning={loading}>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}> <div
style={{ background: '#f0f2f5', padding: 24, minHeight: 720 }}
>
<Row> <Row>
<Col md={8} sm={18} xs={24}> <Col md={8} sm={18} xs={24}>
<Title editable={{ onChange: this.updatePageName }} level={2}> <Title
editable={{ onChange: this.updatePageName }}
level={2}
>
{pageName} {pageName}
</Title> </Title>
</Col> </Col>
@ -350,12 +365,17 @@ class Page extends React.Component {
} }
return null; return null;
})} })}
<Authorized
permission="/permission/admin/device-mgt/enterprise/user/modify"
yes={
<EditLinks <EditLinks
updateLinks={this.updateLinks} updateLinks={this.updateLinks}
pageId={this.pageId} pageId={this.pageId}
selectedLinks={links} selectedLinks={links}
pages={this.pages} pages={this.pages}
/> />
}
/>
</Col> </Col>
{/* <Col>*/} {/* <Col>*/}
@ -364,7 +384,9 @@ class Page extends React.Component {
<Divider dashed={true} /> <Divider dashed={true} />
<Title level={4}>Clusters</Title> <Title level={4}>Clusters</Title>
<Authorized
permission="/permission/admin/device-mgt/enterprise/user/modify"
yes={
<div <div
hidden={isAddNewClusterVisible} hidden={isAddNewClusterVisible}
style={{ textAlign: 'center' }} style={{ textAlign: 'center' }}
@ -381,6 +403,8 @@ class Page extends React.Component {
Add new cluster Add new cluster
</Button> </Button>
</div> </div>
}
/>
<div hidden={!isAddNewClusterVisible}> <div hidden={!isAddNewClusterVisible}>
<Cluster <Cluster
cluster={{ cluster={{
@ -402,6 +426,7 @@ class Page extends React.Component {
{clusters.map((cluster, index) => { {clusters.map((cluster, index) => {
return ( return (
<Cluster <Cluster
hasPermissionToManage={this.hasPermissionToManage}
key={cluster.clusterId} key={cluster.clusterId}
index={index} index={index}
orderInPage={cluster.orderInPage} orderInPage={cluster.orderInPage}
@ -416,6 +441,15 @@ class Page extends React.Component {
})} })}
</div> </div>
</Spin> </Spin>
}
no={
<Result
status="403"
title="You don't have permission to view android enterprise configurations."
subTitle="Please contact system administrator"
/>
}
/>
</div> </div>
); );
} }

@ -0,0 +1,24 @@
/*
* Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
export const isAuthorized = (user, permission) => {
if (!user || !permission) {
return false;
}
return user.permissions.includes(permission);
};
Loading…
Cancel
Save