Add permission based access control to APPM store

reporting
Jayasanka Weerasinghe 5 years ago
parent 0725ecc0d4
commit f6c332df15

@ -7,8 +7,8 @@
"footerText": "©2019 entgra.io" "footerText": "©2019 entgra.io"
}, },
"serverConfig": { "serverConfig": {
"invokerUri": "/ui-request-handler/invoke/application-mgt-store/v1.0",
"invoker": { "invoker": {
"contextPath" : "/store-ui-request-handler",
"uri": "/store-ui-request-handler/invoke", "uri": "/store-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",

@ -92,43 +92,67 @@ class App extends React.Component {
checkUserLoggedIn = config => { checkUserLoggedIn = config => {
axios axios
.post( .post(
window.location.origin + '/store-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 + '/store/'; window.location.href = window.location.origin + '/store/';
} else { } else {
this.setState({ this.getUserPermissions(config);
loading: false,
config: config,
});
} }
}) })
.catch(error => { .catch(error => {
if (error.hasOwnProperty('response') && error.response.status === 401) { this.handleApiError(error, config);
const redirectUrl = encodeURI(window.location.href); });
const pageURL = window.location.pathname; };
const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1);
if (lastURLSegment !== 'login') { getUserPermissions = config => {
window.location.href = axios
window.location.origin + `/store/login?redirect=${redirectUrl}`; .get(
} else { window.location.origin +
this.setState({ config.serverConfig.invoker.uri +
loading: false, config.serverConfig.invoker.deviceMgt +
config: config, '/users/current-user/permissions',
}); )
} .then(res => {
} else { config.user.permissions = res.data.data.permissions;
this.setState({ this.setState({
loading: false, loading: false,
error: true, config: 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 + `/store/login?redirect=${redirectUrl}`;
} else {
this.setState({
loading: false,
config: config,
});
}
} else {
this.setState({
loading: false,
error: true,
}); });
}
}; };
render() { render() {

@ -0,0 +1,45 @@
/*
* 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 '../context/ConfigContext';
class Authorized extends react.Component {
constructor(props) {
super(props);
}
isAuthorized = (user, permission) => {
if (!user || !permission) {
return false;
}
return user.permissions.includes(permission);
};
render() {
return this.isAuthorized(this.props.context.user, this.props.permission)
? this.props.yes
: this.props.no;
}
}
Authorized.defaultProps = {
yes: () => null,
no: () => null,
};
export default withConfigContext(Authorized);

@ -171,7 +171,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.user.username}
</span> </span>
} }
> >

@ -34,9 +34,6 @@ class AppList extends React.Component {
loading: true, loading: true,
hasMore: true, hasMore: true,
loadMore: true, loadMore: true,
forbiddenErrors: {
apps: false,
},
totalAppCount: 0, totalAppCount: 0,
}; };
} }
@ -101,23 +98,10 @@ class AppList extends React.Component {
} }
}) })
.catch(error => { .catch(error => {
handleApiError( handleApiError(error, 'Error occurred while trying to load apps.');
error, this.setState({
'Error occurred while trying to load apps.', loading: false,
true, });
);
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.apps = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({
loading: false,
});
}
}); });
}; };
@ -145,7 +129,7 @@ class AppList extends React.Component {
}; };
render() { render() {
const { apps, loading, forbiddenErrors, hasMore } = this.state; const { apps, loading, hasMore } = this.state;
return ( return (
<div> <div>
@ -158,14 +142,7 @@ class AppList extends React.Component {
useWindow={true} useWindow={true}
> >
<Row gutter={16}> <Row gutter={16}>
{forbiddenErrors.apps && ( {apps.length === 0 && (
<Result
status="403"
title="403"
subTitle="You don't have permission to view apps."
/>
)}
{!forbiddenErrors.apps && apps.length === 0 && (
<Result <Result
status="404" status="404"
title="No apps, yet." title="No apps, yet."

@ -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';
import { Result } from 'antd';
class Apps extends React.Component { class Apps extends React.Component {
routes; routes;
@ -32,9 +34,21 @@ class Apps extends React.Component {
<div> <div>
<div style={{ background: '#f0f2f5', padding: 24, minHeight: 760 }}> <div style={{ background: '#f0f2f5', padding: 24, minHeight: 760 }}>
{deviceType !== null && ( {deviceType !== null && (
<AppList <Authorized
changeSelectedMenuItem={this.props.changeSelectedMenuItem} permission="/permission/admin/app-mgt/store/application/view"
deviceType={deviceType} yes={
<AppList
changeSelectedMenuItem={this.props.changeSelectedMenuItem}
deviceType={deviceType}
/>
}
no={
<Result
status="403"
title="403"
subTitle="You don't have permission to view apps."
/>
}
/> />
)} )}
</div> </div>

@ -23,8 +23,8 @@ import TimeAgo from 'javascript-time-ago';
// Load locale-specific relative date/time formatting rules. // Load locale-specific relative date/time formatting rules.
import en from 'javascript-time-ago/locale/en'; import en from 'javascript-time-ago/locale/en';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -20,8 +20,8 @@ import React from 'react';
import { Typography, Select, Spin, Alert } from 'antd'; import { Typography, Select, Spin, Alert } from 'antd';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -20,8 +20,8 @@ import React from 'react';
import { Typography, Select, Spin, Alert } from 'antd'; import { Typography, Select, Spin, Alert } from 'antd';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -20,8 +20,8 @@ import React from 'react';
import { Typography, Select, Spin, Alert } from 'antd'; import { Typography, Select, Spin, Alert } from 'antd';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -31,8 +31,8 @@ import {
} from 'antd'; } from 'antd';
import StarRatings from 'react-star-ratings'; import StarRatings from 'react-star-ratings';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../../../services/utils/errorHandler';
const { Title } = Typography; const { Title } = Typography;
const { TextArea } = Input; const { TextArea } = Input;

@ -20,7 +20,8 @@ import React from 'react';
import { List, Typography, Empty, Alert } from 'antd'; import { List, Typography, Empty, Alert } from 'antd';
import SingleReview from '../Reviews/components/Review'; import SingleReview from '../Reviews/components/Review';
import AddReview from './components/AddReview'; import AddReview from './components/AddReview';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import Authorized from '../../../../../../../../../../../../../../components/Authorized';
const { Text } = Typography; const { Text } = Typography;
@ -30,45 +31,38 @@ class CurrentUsersReview extends React.Component {
return ( return (
<div> <div>
<Text>MY REVIEW</Text> <Text>MY REVIEW</Text>
{this.props.forbidden && ( <div
<Alert style={{
message="You don't have permission to add reviews." overflow: 'auto',
type="warning" paddingTop: 8,
banner paddingLeft: 24,
closable }}
/> >
)} {currentUserReviews.length > 0 && (
{!this.props.forbidden && ( <div>
<div <List
style={{ dataSource={currentUserReviews}
overflow: 'auto', renderItem={item => (
paddingTop: 8, <List.Item key={item.id}>
paddingLeft: 24, <SingleReview
}} uuid={uuid}
> review={item}
{currentUserReviews.length > 0 && ( isDeletable={true}
<div> isEditable={true}
<List deleteCallback={this.props.deleteCallback}
dataSource={currentUserReviews} onUpdateReview={this.props.onUpdateReview}
renderItem={item => ( isPersonalReview={true}
<List.Item key={item.id}> />
<SingleReview </List.Item>
uuid={uuid} )}
review={item} />
isDeletable={true} </div>
isEditable={true} )}
deleteCallback={this.props.deleteCallback}
onUpdateReview={this.props.onUpdateReview}
isPersonalReview={true}
/>
</List.Item>
)}
/>
</div>
)}
{currentUserReviews.length === 0 && ( {currentUserReviews.length === 0 && (
<div> <Authorized
permission="/permission/admin/app-mgt/store/review/update"
yes={
<Empty <Empty
image={Empty.PRESENTED_IMAGE_DEFAULT} image={Empty.PRESENTED_IMAGE_DEFAULT}
imagestyle={{ imagestyle={{
@ -81,16 +75,21 @@ class CurrentUsersReview extends React.Component {
</span> </span>
} }
> >
{/* <Button type="primary">Add review</Button>*/}
<AddReview <AddReview
uuid={uuid} uuid={uuid}
onUpdateReview={this.props.onUpdateReview} onUpdateReview={this.props.onUpdateReview}
/> />
</Empty> </Empty>
</div> }
)} no={
</div> <Alert
)} type="warning"
message="You don't have permission to add reviews"
/>
}
/>
)}
</div>
</div> </div>
); );
} }

@ -20,7 +20,7 @@ import React from 'react';
import { Row, Typography, Icon } from 'antd'; import { Row, Typography, Icon } from 'antd';
import StarRatings from 'react-star-ratings'; import StarRatings from 'react-star-ratings';
import './styles.css'; import './styles.css';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
const { Text } = Typography; const { Text } = Typography;

@ -31,8 +31,8 @@ import {
import StarRatings from 'react-star-ratings'; import StarRatings from 'react-star-ratings';
import axios from 'axios'; import axios from 'axios';
import './styles.css'; import './styles.css';
import { withConfigContext } from '../../../../../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../../../../../services/utils/errorHandler';
const { Title } = Typography; const { Title } = Typography;
const { TextArea } = Input; const { TextArea } = Input;

@ -24,8 +24,9 @@ import Twemoji from 'react-twemoji';
import './styles.css'; import './styles.css';
import EditReview from './components/Edit'; import EditReview from './components/Edit';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../../../services/utils/errorHandler';
import Authorized from '../../../../../../../../../../../../../../../../components/Authorized';
const { Text, Paragraph } = Typography; const { Text, Paragraph } = Typography;
const colorList = [ const colorList = [
@ -100,7 +101,7 @@ class Review extends React.Component {
}; };
render() { render() {
const { isEditable, isDeletable, uuid } = this.props; const { isEditable, isDeletable, uuid, isPersonalReview } = this.props;
const { color, review } = this.state; const { color, review } = this.state;
const { content, rating, username } = review; const { content, rating, username } = review;
const avatarLetter = username.charAt(0).toUpperCase(); const avatarLetter = username.charAt(0).toUpperCase();
@ -135,15 +136,35 @@ class Review extends React.Component {
updateCallback={this.updateCallback} updateCallback={this.updateCallback}
/> />
)} )}
{isDeletable && ( {isDeletable && !isPersonalReview && (
<Popconfirm <Authorized
title="Are you sure delete this review?" permission="/permission/admin/app-mgt/store/admin/review/update"
onConfirm={this.deleteReview} yes={
okText="Yes" <Popconfirm
cancelText="No" title="Are you sure delete this review?"
> onConfirm={this.deleteReview}
<span className="delete-button">delete</span> okText="Yes"
</Popconfirm> cancelText="No"
>
<span className="delete-button">delete</span>
</Popconfirm>
}
/>
)}
{isDeletable && isPersonalReview && (
<Authorized
permission="/permission/admin/app-mgt/store/review/update"
yes={
<Popconfirm
title="Are you sure delete this review?"
onConfirm={this.deleteReview}
okText="Yes"
cancelText="No"
>
<span className="delete-button">delete</span>
</Popconfirm>
}
/>
)} )}
</div> </div>
); );

@ -23,8 +23,8 @@ import './styles.css';
import InfiniteScroll from 'react-infinite-scroller'; import InfiniteScroll from 'react-infinite-scroller';
import SingleReview from './components/Review'; import SingleReview from './components/Review';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
const limit = 5; const limit = 5;

@ -22,8 +22,9 @@ import { Col, Divider, Row, Typography } from 'antd';
import DetailedRating from './componets/Rating'; import DetailedRating from './componets/Rating';
import Reviews from './componets/Reviews'; import Reviews from './componets/Reviews';
import axios from 'axios'; import axios from 'axios';
import { handleApiError } from '../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler';
import { withConfigContext } from '../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext';
import Authorized from '../../../../../../../../../../../../components/Authorized';
const { Text } = Typography; const { Text } = Typography;
@ -34,7 +35,6 @@ class ReviewContainer extends React.Component {
currentUserReviews: [], currentUserReviews: [],
detailedRating: null, detailedRating: null,
forbiddenErrors: { forbiddenErrors: {
currentReview: false,
reviews: false, reviews: false,
rating: false, rating: false,
}, },
@ -70,18 +70,6 @@ class ReviewContainer extends React.Component {
'Error occurred while trying to get your review.', 'Error occurred while trying to get your review.',
true, true,
); );
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.currentReview = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({
loading: false,
});
}
}); });
}; };
@ -130,25 +118,33 @@ class ReviewContainer extends React.Component {
render() { render() {
const { uuid } = this.props; const { uuid } = this.props;
const { currentUserReviews, detailedRating, forbiddenErrors } = this.state; const { currentUserReviews, detailedRating } = this.state;
return ( return (
<div> <Authorized
<CurrentUsersReview permission="/permission/admin/app-mgt/store/review/view"
forbidden={forbiddenErrors.currentReview} yes={
uuid={uuid} <div>
currentUserReviews={currentUserReviews} <CurrentUsersReview
onUpdateReview={this.onUpdateReview} uuid={uuid}
deleteCallback={this.deleteCurrentUserReviewCallback} currentUserReviews={currentUserReviews}
/> onUpdateReview={this.onUpdateReview}
<Divider dashed={true} /> deleteCallback={this.deleteCurrentUserReviewCallback}
<Text>REVIEWS</Text> />
<Row> <Divider dashed={true} />
<Col lg={18} md={24}> <Text>REVIEWS</Text>
<DetailedRating type="app" detailedRating={detailedRating} /> <Row>
</Col> <Col lg={18} md={24}>
</Row> <DetailedRating type="app" detailedRating={detailedRating} />
<Reviews type="app" uuid={uuid} deleteCallback={this.onUpdateReview} /> </Col>
</div> </Row>
<Reviews
type="app"
uuid={uuid}
deleteCallback={this.onUpdateReview}
/>
</div>
}
/>
); );
} }
} }

@ -23,8 +23,9 @@ import TimeAgo from 'javascript-time-ago';
// Load locale-specific relative date/time formatting rules. // Load locale-specific relative date/time formatting rules.
import en from 'javascript-time-ago/locale/en'; import en from 'javascript-time-ago/locale/en';
import { withConfigContext } from '../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler';
import Authorized from '../../../../../../../../../../../../components/Authorized';
const { Text } = Typography; const { Text } = Typography;
@ -223,48 +224,49 @@ class SubscriptionDetails extends React.Component {
render() { render() {
const { data, pagination, loading } = this.state; const { data, pagination, loading } = this.state;
return ( return (
<div> <Authorized
{this.state.isForbidden && ( permission="/permission/admin/app-mgt/store/admin/subscription/view"
yes={
<div>
<div style={{ paddingBottom: 24 }}>
<Text>
The following are the subscription details of the application in
each respective device.
</Text>
</div>
<div style={{ textAlign: 'right', paddingBottom: 6 }}>
<Button icon="sync" onClick={this.fetch}>
Refresh
</Button>
</div>
<Table
columns={columns}
rowKey={record =>
record.device.deviceIdentifier +
record.device.enrolmentInfo.owner +
record.device.enrolmentInfo.ownership
}
dataSource={data.data}
pagination={{
...pagination,
size: 'small',
total: data.recordsTotal,
showTotal: (total, range) =>
`showing ${range[0]}-${range[1]} of ${total} devices`,
}}
onChange={this.handleTableChange}
loading={loading}
scroll={{ x: 1000 }}
/>
</div>
}
no={
<Alert <Alert
message="You don't have permission to view subscription details."
type="warning" type="warning"
banner message="You don't have permission to view subscription details"
closable
/> />
)} }
<div style={{ paddingBottom: 24 }}> />
<Text>
The following are the subscription details of the application in
each respective device.
</Text>
</div>
<div style={{ textAlign: 'right', paddingBottom: 6 }}>
<Button icon="sync" onClick={this.fetch}>
Refresh
</Button>
</div>
<Table
columns={columns}
rowKey={record =>
record.device.deviceIdentifier +
record.device.enrolmentInfo.owner +
record.device.enrolmentInfo.ownership
}
dataSource={data.data}
pagination={{
...pagination,
size: 'small',
// position: "top",
total: data.recordsTotal,
showTotal: (total, range) =>
`showing ${range[0]}-${range[1]} of ${total} devices`,
// showQuickJumper: true
}}
onChange={this.handleTableChange}
loading={loading}
scroll={{ x: 1000 }}
/>
</div>
); );
} }
} }

@ -23,8 +23,8 @@ import TimeAgo from 'javascript-time-ago';
// Load locale-specific relative date/time formatting rules. // Load locale-specific relative date/time formatting rules.
import en from 'javascript-time-ago/locale/en'; import en from 'javascript-time-ago/locale/en';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -20,8 +20,8 @@ import React from 'react';
import { Typography, Select, Spin, Alert } from 'antd'; import { Typography, Select, Spin, Alert } from 'antd';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -20,8 +20,8 @@ import React from 'react';
import { Typography, Select, Spin, Alert } from 'antd'; import { Typography, Select, Spin, Alert } from 'antd';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -20,8 +20,8 @@ import React from 'react';
import { Typography, Select, Spin, Alert } from 'antd'; import { Typography, Select, Spin, Alert } from 'antd';
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import axios from 'axios'; import axios from 'axios';
import { withConfigContext } from '../../../../../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../../../../../services/utils/errorHandler';
import InstallModalFooter from '../../../installModalFooter'; import InstallModalFooter from '../../../installModalFooter';
const { Text } = Typography; const { Text } = Typography;

@ -30,17 +30,18 @@ import {
Tabs, Tabs,
Tag, Tag,
} from 'antd'; } from 'antd';
import '../../../../../../../../App.css'; import '../../../../../../../../../../App.css';
import ImageViewer from './components/ImageViewer'; import ImageViewer from './components/ImageViewer';
import StarRatings from 'react-star-ratings'; import StarRatings from 'react-star-ratings';
import axios from 'axios'; import axios from 'axios';
import pSBC from 'shade-blend-color'; import pSBC from 'shade-blend-color';
import AppInstallModal from './components/Install'; import AppInstallModal from './components/Install';
import Uninstall from './components/Uninstall'; import Uninstall from './components/Uninstall';
import { withConfigContext } from '../../../../../../../../components/context/ConfigContext'; import { withConfigContext } from '../../../../../../../../../../components/context/ConfigContext';
import { handleApiError } from '../../../../../../../../services/utils/errorHandler'; import { handleApiError } from '../../../../../../../../../../services/utils/errorHandler';
import ReviewContainer from './components/ReviewContainer'; import ReviewContainer from './components/ReviewContainer';
import SubscriptionDetails from './components/SubscriptionDetails'; import SubscriptionDetails from './components/SubscriptionDetails';
import Authorized from '../../../../../../../../../../components/Authorized';
const { Title, Text, Paragraph } = Typography; const { Title, Text, Paragraph } = Typography;
const { TabPane } = Tabs; const { TabPane } = Tabs;
@ -167,22 +168,24 @@ class ReleaseView extends React.Component {
return ( return (
<div> <div>
<AppInstallModal <div>
uuid={release.uuid} <AppInstallModal
loading={this.state.loading} uuid={release.uuid}
visible={this.state.appInstallModalVisible} loading={this.state.loading}
deviceType={deviceType} visible={this.state.appInstallModalVisible}
onClose={this.closeAppOperationModal} deviceType={deviceType}
onInstall={this.appOperation} onClose={this.closeAppOperationModal}
/> onInstall={this.appOperation}
<Uninstall />
uuid={release.uuid} <Uninstall
loading={this.state.loading} uuid={release.uuid}
visible={this.state.appUninstallModalVisible} loading={this.state.loading}
deviceType={deviceType} visible={this.state.appUninstallModalVisible}
onClose={this.closeAppOperationModal} deviceType={deviceType}
onUninstall={this.appOperation} onClose={this.closeAppOperationModal}
/> onUninstall={this.appOperation}
/>
</div>
<div className="release"> <div className="release">
<Row> <Row>
<Col xl={4} sm={6} xs={8} className="release-icon"> <Col xl={4} sm={6} xs={8} className="release-icon">
@ -208,11 +211,21 @@ class ReleaseView extends React.Component {
textAlign: 'right', textAlign: 'right',
}} }}
> >
<Dropdown overlay={menu}> <Authorized
<Button type="primary"> permission="/permission/admin/app-mgt/store/subscription"
Subscribe <Icon type="down" /> yes={
</Button> <Dropdown overlay={menu}>
</Dropdown> <Button type="primary">
Subscribe <Icon type="down" />
</Button>
</Dropdown>
}
no={
<Button type="primary" disabled={true}>
Subscribe <Icon type="down" />
</Button>
}
/>
</div> </div>
</Col> </Col>
</Row> </Row>
@ -281,9 +294,14 @@ class ReleaseView extends React.Component {
<Divider /> <Divider />
<ReviewContainer uuid={release.uuid} /> <ReviewContainer uuid={release.uuid} />
</TabPane> </TabPane>
<TabPane tab="Subscription Details" key="2"> <Authorized
<SubscriptionDetails uuid={release.uuid} /> permission="/permission/admin/app-mgt/store/admin/subscription/view"
</TabPane> yes={
<TabPane tab="Subscription Details" key="2">
<SubscriptionDetails uuid={release.uuid} />
</TabPane>
}
/>
</Tabs> </Tabs>
</div> </div>
</div> </div>

@ -0,0 +1,135 @@
/*
* 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 '../../../../../../../../App.css';
import { Skeleton, Typography, Row, Col, Card, Breadcrumb, Icon } from 'antd';
import ReleaseView from './components/ReleaseView';
import axios from 'axios';
import { withConfigContext } from '../../../../../../../../components/context/ConfigContext';
import { Link } from 'react-router-dom';
import { handleApiError } from '../../../../../../../../services/utils/errorHandler';
const { Title } = Typography;
class ReleasePage extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: true,
app: null,
uuid: null,
forbiddenErrors: {
app: false,
},
};
}
componentDidMount() {
const { uuid, deviceType } = this.props;
this.fetchData(uuid);
this.props.changeSelectedMenuItem(deviceType);
}
fetchData = uuid => {
const config = this.props.context;
// send request to the invoker
axios
.get(
window.location.origin +
config.serverConfig.invoker.uri +
config.serverConfig.invoker.store +
'/applications/' +
uuid,
)
.then(res => {
if (res.status === 200) {
let app = res.data.data;
this.setState({
app: app,
loading: false,
uuid: uuid,
});
}
})
.catch(error => {
handleApiError(
error,
'Error occurred while trying to load releases.',
false,
);
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.app = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({
loading: false,
});
}
});
};
render() {
const { app, loading } = this.state;
const { deviceType } = this.props;
let content = <Title level={3}>No Releases Found</Title>;
let appName = 'loading...';
if (app != null && app.applicationReleases.length !== 0) {
content = <ReleaseView app={app} deviceType={deviceType} />;
appName = app.name;
}
return (
<div style={{ background: '#f0f2f5', minHeight: 780 }}>
<Row style={{ padding: 10 }}>
<Col lg={4}></Col>
<Col lg={16} md={24} style={{ padding: 3 }}>
<Breadcrumb style={{ paddingBottom: 16 }}>
<Breadcrumb.Item>
<Link to={'/store/' + deviceType}>
<Icon type="home" /> {deviceType + ' apps'}{' '}
</Link>
</Breadcrumb.Item>
<Breadcrumb.Item>{appName}</Breadcrumb.Item>
</Breadcrumb>
<Card>
<Skeleton
loading={loading}
avatar={{ size: 'large' }}
active
paragraph={{ rows: 8 }}
>
{content}
</Skeleton>
</Card>
</Col>
</Row>
</div>
);
}
}
export default withConfigContext(ReleasePage);

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. * Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved.
* *
* Entgra (pvt) Ltd. licenses this file to you under the Apache License, * Entgra (pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -17,122 +17,33 @@
*/ */
import React from 'react'; import React from 'react';
import '../../../../../../App.css'; import Authorized from '../../../../../../components/Authorized';
import { Skeleton, Typography, Row, Col, Card, Breadcrumb, Icon } from 'antd'; import ReleasePage from './components/ReleasePage';
import ReleaseView from './components/ReleaseView'; import { Result } from 'antd';
import axios from 'axios';
import { withConfigContext } from '../../../../../../components/context/ConfigContext';
import { Link } from 'react-router-dom';
import { handleApiError } from '../../../../../../services/utils/errorHandler';
const { Title } = Typography;
class Release extends React.Component { class Release extends React.Component {
routes; render() {
constructor(props) {
super(props);
this.routes = props.routes;
this.state = {
loading: true,
app: null,
uuid: null,
forbiddenErrors: {
app: false,
},
};
}
componentDidMount() {
const { uuid, deviceType } = this.props.match.params; const { uuid, deviceType } = this.props.match.params;
this.fetchData(uuid); return (
this.props.changeSelectedMenuItem(deviceType); <Authorized
} permission="/permission/admin/app-mgt/store/application/view"
yes={
fetchData = uuid => { <ReleasePage
const config = this.props.context; uuid={uuid}
deviceType={deviceType}
// send request to the invoker changeSelectedMenuItem={this.props.changeSelectedMenuItem}
axios />
.get(
window.location.origin +
config.serverConfig.invoker.uri +
config.serverConfig.invoker.store +
'/applications/' +
uuid,
)
.then(res => {
if (res.status === 200) {
let app = res.data.data;
this.setState({
app: app,
loading: false,
uuid: uuid,
});
} }
}) no={
.catch(error => { <Result
handleApiError( status="403"
error, title="403"
'Error occurred while trying to load releases.', subTitle="You don't have permission to view apps."
false, />
);
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.app = true;
this.setState({
forbiddenErrors,
loading: false,
});
} else {
this.setState({
loading: false,
});
} }
}); />
};
render() {
const { app, loading } = this.state;
const { deviceType } = this.props.match.params;
let content = <Title level={3}>No Releases Found</Title>;
let appName = 'loading...';
if (app != null && app.applicationReleases.length !== 0) {
content = <ReleaseView app={app} deviceType={deviceType} />;
appName = app.name;
}
return (
<div style={{ background: '#f0f2f5', minHeight: 780 }}>
<Row style={{ padding: 10 }}>
<Col lg={4}></Col>
<Col lg={16} md={24} style={{ padding: 3 }}>
<Breadcrumb style={{ paddingBottom: 16 }}>
<Breadcrumb.Item>
<Link to={'/store/' + deviceType}>
<Icon type="home" /> {deviceType + ' apps'}{' '}
</Link>
</Breadcrumb.Item>
<Breadcrumb.Item>{appName}</Breadcrumb.Item>
</Breadcrumb>
<Card>
<Skeleton
loading={loading}
avatar={{ size: 'large' }}
active
paragraph={{ rows: 8 }}
>
{content}
</Skeleton>
</Card>
</Col>
</Row>
</div>
); );
} }
} }
export default withConfigContext(Release); export default Release;

@ -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