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,23 +92,48 @@ 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.getUserPermissions(config);
}
})
.catch(error => {
this.handleApiError(error, config);
});
};
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.setState({ this.setState({
loading: false, loading: false,
config: config, config: config,
}); });
}
}) })
.catch(error => { .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;
@ -128,7 +153,6 @@ class App extends React.Component {
error: true, 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,
'Error occurred while trying to load apps.',
true,
);
if (error.hasOwnProperty('response') && error.response.status === 403) {
const { forbiddenErrors } = this.state;
forbiddenErrors.apps = true;
this.setState({ this.setState({
forbiddenErrors,
loading: false, 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,10 +34,22 @@ 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 && (
<Authorized
permission="/permission/admin/app-mgt/store/application/view"
yes={
<AppList <AppList
changeSelectedMenuItem={this.props.changeSelectedMenuItem} changeSelectedMenuItem={this.props.changeSelectedMenuItem}
deviceType={deviceType} deviceType={deviceType}
/> />
}
no={
<Result
status="403"
title="403"
subTitle="You don't have permission to view apps."
/>
}
/>
)} )}
</div> </div>
</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,15 +31,6 @@ class CurrentUsersReview extends React.Component {
return ( return (
<div> <div>
<Text>MY REVIEW</Text> <Text>MY REVIEW</Text>
{this.props.forbidden && (
<Alert
message="You don't have permission to add reviews."
type="warning"
banner
closable
/>
)}
{!this.props.forbidden && (
<div <div
style={{ style={{
overflow: 'auto', overflow: 'auto',
@ -68,7 +60,9 @@ class CurrentUsersReview extends React.Component {
)} )}
{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={
<Alert
type="warning"
message="You don't have permission to add reviews"
/>
}
/>
)} )}
</div> </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,7 +136,10 @@ class Review extends React.Component {
updateCallback={this.updateCallback} updateCallback={this.updateCallback}
/> />
)} )}
{isDeletable && ( {isDeletable && !isPersonalReview && (
<Authorized
permission="/permission/admin/app-mgt/store/admin/review/update"
yes={
<Popconfirm <Popconfirm
title="Are you sure delete this review?" title="Are you sure delete this review?"
onConfirm={this.deleteReview} onConfirm={this.deleteReview}
@ -144,6 +148,23 @@ class Review extends React.Component {
> >
<span className="delete-button">delete</span> <span className="delete-button">delete</span>
</Popconfirm> </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,11 +118,13 @@ 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 (
<Authorized
permission="/permission/admin/app-mgt/store/review/view"
yes={
<div> <div>
<CurrentUsersReview <CurrentUsersReview
forbidden={forbiddenErrors.currentReview}
uuid={uuid} uuid={uuid}
currentUserReviews={currentUserReviews} currentUserReviews={currentUserReviews}
onUpdateReview={this.onUpdateReview} onUpdateReview={this.onUpdateReview}
@ -147,8 +137,14 @@ class ReviewContainer extends React.Component {
<DetailedRating type="app" detailedRating={detailedRating} /> <DetailedRating type="app" detailedRating={detailedRating} />
</Col> </Col>
</Row> </Row>
<Reviews type="app" uuid={uuid} deleteCallback={this.onUpdateReview} /> <Reviews
type="app"
uuid={uuid}
deleteCallback={this.onUpdateReview}
/>
</div> </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,15 +224,10 @@ class SubscriptionDetails extends React.Component {
render() { render() {
const { data, pagination, loading } = this.state; const { data, pagination, loading } = this.state;
return ( return (
<Authorized
permission="/permission/admin/app-mgt/store/admin/subscription/view"
yes={
<div> <div>
{this.state.isForbidden && (
<Alert
message="You don't have permission to view subscription details."
type="warning"
banner
closable
/>
)}
<div style={{ paddingBottom: 24 }}> <div style={{ paddingBottom: 24 }}>
<Text> <Text>
The following are the subscription details of the application in The following are the subscription details of the application in
@ -254,17 +250,23 @@ class SubscriptionDetails extends React.Component {
pagination={{ pagination={{
...pagination, ...pagination,
size: 'small', size: 'small',
// position: "top",
total: data.recordsTotal, total: data.recordsTotal,
showTotal: (total, range) => showTotal: (total, range) =>
`showing ${range[0]}-${range[1]} of ${total} devices`, `showing ${range[0]}-${range[1]} of ${total} devices`,
// showQuickJumper: true
}} }}
onChange={this.handleTableChange} onChange={this.handleTableChange}
loading={loading} loading={loading}
scroll={{ x: 1000 }} scroll={{ x: 1000 }}
/> />
</div> </div>
}
no={
<Alert
type="warning"
message="You don't have permission to view subscription details"
/>
}
/>
); );
} }
} }

@ -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;
@ -166,6 +167,7 @@ class ReleaseView extends React.Component {
); );
return ( return (
<div>
<div> <div>
<AppInstallModal <AppInstallModal
uuid={release.uuid} uuid={release.uuid}
@ -183,6 +185,7 @@ class ReleaseView extends React.Component {
onClose={this.closeAppOperationModal} onClose={this.closeAppOperationModal}
onUninstall={this.appOperation} 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',
}} }}
> >
<Authorized
permission="/permission/admin/app-mgt/store/subscription"
yes={
<Dropdown overlay={menu}> <Dropdown overlay={menu}>
<Button type="primary"> <Button type="primary">
Subscribe <Icon type="down" /> Subscribe <Icon type="down" />
</Button> </Button>
</Dropdown> </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>
<Authorized
permission="/permission/admin/app-mgt/store/admin/subscription/view"
yes={
<TabPane tab="Subscription Details" key="2"> <TabPane tab="Subscription Details" key="2">
<SubscriptionDetails uuid={release.uuid} /> <SubscriptionDetails uuid={release.uuid} />
</TabPane> </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