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": {
"invoker": {
"contextPath" : "/publisher-ui-request-handler",
"uri": "/publisher-ui-request-handler/invoke",
"publisher": "/application-mgt-publisher/v1.0",
"store": "/application-mgt-store/v1.0",

@ -106,28 +106,64 @@ class App extends React.Component {
checkUserLoggedIn = config => {
axios
.post(
window.location.origin + '/publisher-ui-request-handler/user',
'platform=publisher',
window.location.origin +
config.serverConfig.invoker.contextPath +
'/user',
)
.then(res => {
config.user = res.data.data;
config.user = {
username: res.data.data,
};
const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment === 'login') {
window.location.href = window.location.origin + '/publisher/';
} else {
this.getAndroidEnterpriseToken(config);
this.getUserPermissions(config);
}
})
.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) {
const redirectUrl = encodeURI(window.location.href);
const pageURL = window.location.pathname;
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment !== 'login') {
window.location.href =
window.location.origin +
`/publisher/login?redirect=${redirectUrl}`;
window.location.origin + `/publisher/login?redirect=${redirectUrl}`;
} else {
this.getAndroidEnterpriseToken(config);
}
@ -137,19 +173,6 @@ class App extends React.Component {
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() {

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

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

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

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

@ -17,9 +17,10 @@
*/
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 { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography;
@ -70,7 +71,17 @@ class AddNewCustomApp extends React.Component {
</div>
</PageHeader>
<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>
);

@ -17,9 +17,10 @@
*/
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 { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography;
@ -64,7 +65,17 @@ class AddNewEnterpriseApp extends React.Component {
</div>
</PageHeader>
<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>
);

@ -17,9 +17,10 @@
*/
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 { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography;
@ -72,7 +73,17 @@ class AddNewPublicApp extends React.Component {
</div>
</PageHeader>
<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>
);

@ -17,9 +17,10 @@
*/
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 { Link } from 'react-router-dom';
import Authorized from '../../../../../../components/Authorized/Authorized';
const { Paragraph } = Typography;
@ -65,7 +66,17 @@ class AddNewEnterpriseApp extends React.Component {
</div>
</PageHeader>
<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>
);

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

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

@ -18,6 +18,8 @@
import React from 'react';
import AppList from './components/AppList';
import Authorized from '../../../../components/Authorized/Authorized';
import { Result } from 'antd';
class Apps extends React.Component {
routes;
@ -30,7 +32,17 @@ class Apps extends React.Component {
return (
<div>
<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>
);

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

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

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

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

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

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

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

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

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

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

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