Merge branch 'master' into 'master'

Add unrestricted roles editing functionality

See merge request entgra/carbon-device-mgt!627
revert-70ac1926
Dharmakeerthi Lasantha 4 years ago
commit 813a150060

@ -2029,8 +2029,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
appUnrestrictedRoles = applicationUpdateWrapper.getUnrestrictedRoles(); appUnrestrictedRoles = applicationUpdateWrapper.getUnrestrictedRoles();
} else { } else {
List<String> addingRoleList = getDifference(applicationUpdateWrapper.getUnrestrictedRoles(), List<String> addingRoleList = getDifference(applicationUpdateWrapper.getUnrestrictedRoles(),
applicationDTO.getUnrestrictedRoles()); appUnrestrictedRoles);
List<String> removingRoleList = getDifference(applicationDTO.getUnrestrictedRoles(), List<String> removingRoleList = getDifference(appUnrestrictedRoles,
applicationUpdateWrapper.getUnrestrictedRoles()); applicationUpdateWrapper.getUnrestrictedRoles());
if (!addingRoleList.isEmpty()) { if (!addingRoleList.isEmpty()) {
visibilityDAO.addUnrestrictedRoles(addingRoleList, applicationId, tenantId); visibilityDAO.addUnrestrictedRoles(addingRoleList, applicationId, tenantId);

@ -18,6 +18,7 @@
import React from 'react'; import React from 'react';
import { import {
Alert,
Drawer, Drawer,
Select, Select,
Avatar, Avatar,
@ -84,6 +85,7 @@ const formats = [
class AppDetailsDrawer extends React.Component { class AppDetailsDrawer extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.config = this.props.context;
const drawerWidth = window.innerWidth <= 770 ? '80%' : '40%'; const drawerWidth = window.innerWidth <= 770 ? '80%' : '40%';
this.state = { this.state = {
@ -92,14 +94,18 @@ class AppDetailsDrawer extends React.Component {
description: null, description: null,
globalCategories: [], globalCategories: [],
globalTags: [], globalTags: [],
globalUnrestrictedRoles: [],
categories: [], categories: [],
tags: [], tags: [],
unrestrictedRoles: [],
temporaryDescription: null, temporaryDescription: null,
temporaryCategories: [], temporaryCategories: [],
temporaryTags: [], temporaryTags: [],
temporaryUnrestrictedRoles: [],
isDescriptionEditEnabled: false, isDescriptionEditEnabled: false,
isCategoriesEditEnabled: false, isCategoriesEditEnabled: false,
isTagsEditEnabled: false, isTagsEditEnabled: false,
isUnrestrictedRolesEditEnabled: false,
drawer: null, drawer: null,
drawerWidth, drawerWidth,
}; };
@ -114,31 +120,39 @@ class AppDetailsDrawer extends React.Component {
) { ) {
this.getCategories(); this.getCategories();
this.getTags(); this.getTags();
this.getUnrestrictedRoles();
} }
} }
componentDidUpdate(prevProps, prevState, snapshot) { componentDidUpdate(prevProps, prevState, snapshot) {
if (prevProps.app !== this.props.app) { if (prevProps.app !== this.props.app) {
const { name, description, tags, categories } = this.props.app; const {
name,
description,
tags,
categories,
unrestrictedRoles,
} = this.props.app;
this.setState({ this.setState({
name, name,
description, description,
tags, tags,
categories, categories,
unrestrictedRoles,
isDescriptionEditEnabled: false, isDescriptionEditEnabled: false,
isCategoriesEditEnabled: false, isCategoriesEditEnabled: false,
isTagsEditEnabled: false, isTagsEditEnabled: false,
isUnrestrictedRolesEditEnabled: false,
}); });
} }
} }
getCategories = () => { getCategories = () => {
const config = this.props.context;
axios axios
.get( .get(
window.location.origin + window.location.origin +
config.serverConfig.invoker.uri + this.config.serverConfig.invoker.uri +
config.serverConfig.invoker.publisher + this.config.serverConfig.invoker.publisher +
'/applications/categories', '/applications/categories',
) )
.then(res => { .then(res => {
@ -171,12 +185,11 @@ class AppDetailsDrawer extends React.Component {
}; };
getTags = () => { getTags = () => {
const config = this.props.context;
axios axios
.get( .get(
window.location.origin + window.location.origin +
config.serverConfig.invoker.uri + this.config.serverConfig.invoker.uri +
config.serverConfig.invoker.publisher + this.config.serverConfig.invoker.publisher +
'/applications/tags', '/applications/tags',
) )
.then(res => { .then(res => {
@ -201,17 +214,46 @@ class AppDetailsDrawer extends React.Component {
}); });
}; };
getUnrestrictedRoles = () => {
axios
.get(
window.location.origin +
this.config.serverConfig.invoker.uri +
this.config.serverConfig.invoker.deviceMgt +
'/roles',
)
.then(res => {
if (res.status === 200) {
const globalUnrestrictedRoles = res.data.data.roles;
this.setState({
globalUnrestrictedRoles,
loading: false,
});
}
})
.catch(error => {
handleApiError(
error,
'Error occurred while trying to load roles.',
true,
);
this.setState({
loading: false,
});
});
};
// change the app name // change the app name
handleNameSave = name => { handleNameSave = name => {
const config = this.props.context;
const { id } = this.props.app; const { id } = this.props.app;
if (name !== this.state.name && name !== '') { if (name !== this.state.name && name !== '') {
const data = { name: name }; const data = { name: name };
axios axios
.put( .put(
window.location.origin + window.location.origin +
config.serverConfig.invoker.uri + this.config.serverConfig.invoker.uri +
config.serverConfig.invoker.publisher + this.config.serverConfig.invoker.publisher +
'/applications/' + '/applications/' +
id, id,
data, data,
@ -288,7 +330,6 @@ class AppDetailsDrawer extends React.Component {
// change app categories // change app categories
handleCategorySave = () => { handleCategorySave = () => {
const config = this.props.context;
const { id } = this.props.app; const { id } = this.props.app;
const { temporaryCategories, categories } = this.state; const { temporaryCategories, categories } = this.state;
@ -301,8 +342,8 @@ class AppDetailsDrawer extends React.Component {
axios axios
.put( .put(
window.location.origin + window.location.origin +
config.serverConfig.invoker.uri + this.config.serverConfig.invoker.uri +
config.serverConfig.invoker.publisher + this.config.serverConfig.invoker.publisher +
'/applications/' + '/applications/' +
id, id,
data, data,
@ -363,7 +404,6 @@ class AppDetailsDrawer extends React.Component {
// change app tags // change app tags
handleTagsSave = () => { handleTagsSave = () => {
const config = this.props.context;
const { id } = this.props.app; const { id } = this.props.app;
const { temporaryTags, tags } = this.state; const { temporaryTags, tags } = this.state;
@ -376,8 +416,8 @@ class AppDetailsDrawer extends React.Component {
axios axios
.put( .put(
window.location.origin + window.location.origin +
config.serverConfig.invoker.uri + this.config.serverConfig.invoker.uri +
config.serverConfig.invoker.publisher + this.config.serverConfig.invoker.publisher +
'/applications/' + '/applications/' +
id, id,
data, data,
@ -385,6 +425,7 @@ class AppDetailsDrawer extends React.Component {
.then(res => { .then(res => {
if (res.status === 200) { if (res.status === 200) {
const app = res.data.data; const app = res.data.data;
this.props.onUpdateApp('tags', temporaryTags);
notification.success({ notification.success({
message: 'Saved!', message: 'Saved!',
description: 'App tags updated successfully!', description: 'App tags updated successfully!',
@ -416,9 +457,75 @@ class AppDetailsDrawer extends React.Component {
} }
}; };
enableUnrestrictedRolesEdit = () => {
this.setState({
isUnrestrictedRolesEditEnabled: true,
temporaryUnrestrictedRoles: this.state.unrestrictedRoles,
});
};
disableUnrestrictedRolesEdit = () => {
this.setState({
isUnrestrictedRolesEditEnabled: false,
});
};
handleUnrestrictedRolesChange = temporaryUnrestrictedRoles => {
this.setState({ temporaryUnrestrictedRoles });
};
handleUnrestrictedRolesSave = () => {
const { id } = this.props.app;
const { temporaryUnrestrictedRoles, unrestrictedRoles } = this.state;
temporaryUnrestrictedRoles
.filter(x => !unrestrictedRoles.includes(x))
.concat(
unrestrictedRoles.filter(x => !temporaryUnrestrictedRoles.includes(x)),
);
const data = { unrestrictedRoles: temporaryUnrestrictedRoles };
axios
.put(
window.location.origin +
this.config.serverConfig.invoker.uri +
this.config.serverConfig.invoker.publisher +
'/applications/' +
id,
data,
)
.then(res => {
if (res.status === 200) {
const app = res.data.data;
this.props.onUpdateApp(
'unrestrictedRoles',
temporaryUnrestrictedRoles,
);
notification.success({
message: 'Saved!',
description: 'App unrestricted roles updated successfully!',
});
this.setState({
loading: false,
unrestrictedRoles: app.unrestrictedRoles,
isUnrestrictedRolesEditEnabled: false,
});
}
})
.catch(error => {
handleApiError(
error,
'Error occurred while trying to update unrestricted roles.',
true,
);
this.setState({
loading: false,
});
});
};
// handle description save // handle description save
handleDescriptionSave = () => { handleDescriptionSave = () => {
const config = this.props.context;
const { id } = this.props.app; const { id } = this.props.app;
const { description, temporaryDescription } = this.state; const { description, temporaryDescription } = this.state;
@ -430,8 +537,8 @@ class AppDetailsDrawer extends React.Component {
axios axios
.put( .put(
window.location.origin + window.location.origin +
config.serverConfig.invoker.uri + this.config.serverConfig.invoker.uri +
config.serverConfig.invoker.publisher + this.config.serverConfig.invoker.publisher +
'/applications/' + '/applications/' +
id, id,
data, data,
@ -469,7 +576,6 @@ class AppDetailsDrawer extends React.Component {
}; };
render() { render() {
const config = this.props.context;
const { app, visible, onClose } = this.props; const { app, visible, onClose } = this.props;
const { const {
name, name,
@ -478,13 +584,17 @@ class AppDetailsDrawer extends React.Component {
isDescriptionEditEnabled, isDescriptionEditEnabled,
isCategoriesEditEnabled, isCategoriesEditEnabled,
isTagsEditEnabled, isTagsEditEnabled,
isUnrestrictedRolesEditEnabled,
temporaryDescription, temporaryDescription,
temporaryCategories, temporaryCategories,
temporaryTags, temporaryTags,
temporaryUnrestrictedRoles,
globalCategories, globalCategories,
globalTags, globalTags,
globalUnrestrictedRoles,
categories, categories,
tags, tags,
unrestrictedRoles,
} = this.state; } = this.state;
if (app == null) { if (app == null) {
return null; return null;
@ -502,7 +612,7 @@ class AppDetailsDrawer extends React.Component {
style={{ style={{
marginBottom: 10, marginBottom: 10,
borderRadius: '28%', borderRadius: '28%',
backgroundColor: pSBC(0.5, config.theme.primaryColor), backgroundColor: pSBC(0.5, this.config.theme.primaryColor),
}} }}
> >
{avatarLetter} {avatarLetter}
@ -543,9 +653,9 @@ class AppDetailsDrawer extends React.Component {
<Menu.Item key="1"> <Menu.Item key="1">
<RetireApp id={id} isHideableApp={app.isHideableApp} /> <RetireApp id={id} isHideableApp={app.isHideableApp} />
</Menu.Item> </Menu.Item>
{config.androidEnterpriseToken !== null && {this.config.androidEnterpriseToken !== null &&
isAuthorized( isAuthorized(
config.user, this.config.user,
'/permission/admin/device-mgt/enterprise/user/modify', '/permission/admin/device-mgt/enterprise/user/modify',
) && ( ) && (
<Menu.Item key="2"> <Menu.Item key="2">
@ -682,7 +792,7 @@ class AppDetailsDrawer extends React.Component {
!isDescriptionEditEnabled && ( !isDescriptionEditEnabled && (
<Text <Text
style={{ style={{
color: config.theme.primaryColor, color: this.config.theme.primaryColor,
cursor: 'pointer', cursor: 'pointer',
}} }}
onClick={this.enableDescriptionEdit} onClick={this.enableDescriptionEdit}
@ -738,7 +848,7 @@ class AppDetailsDrawer extends React.Component {
!isCategoriesEditEnabled && ( !isCategoriesEditEnabled && (
<Text <Text
style={{ style={{
color: config.theme.primaryColor, color: this.config.theme.primaryColor,
cursor: 'pointer', cursor: 'pointer',
}} }}
onClick={this.enableCategoriesEdit} onClick={this.enableCategoriesEdit}
@ -786,7 +896,7 @@ class AppDetailsDrawer extends React.Component {
{categories.map(category => { {categories.map(category => {
return ( return (
<Tag <Tag
color={pSBC(0.3, config.theme.primaryColor)} color={pSBC(0.3, this.config.theme.primaryColor)}
key={category} key={category}
style={{ marginBottom: 5 }} style={{ marginBottom: 5 }}
> >
@ -805,7 +915,7 @@ class AppDetailsDrawer extends React.Component {
!isTagsEditEnabled && ( !isTagsEditEnabled && (
<Text <Text
style={{ style={{
color: config.theme.primaryColor, color: this.config.theme.primaryColor,
cursor: 'pointer', cursor: 'pointer',
}} }}
onClick={this.enableTagsEdit} onClick={this.enableTagsEdit}
@ -859,6 +969,85 @@ class AppDetailsDrawer extends React.Component {
})} })}
</span> </span>
)} )}
<Divider dashed={true} />
<Text strong={true}>Unrestricted Roles</Text>
<Authorized
permission="/permission/admin/app-mgt/publisher/application/update"
yes={
!isUnrestrictedRolesEditEnabled && (
<Text
style={{
color: this.config.theme.primaryColor,
cursor: 'pointer',
}}
onClick={this.enableUnrestrictedRolesEdit}
>
<EditOutlined />
</Text>
)
}
/>
<br />
<br />
{!unrestrictedRoles.length && (
<Alert
message="Application is not restricted to any roles."
type="info"
showIcon
/>
)}
{isUnrestrictedRolesEditEnabled && (
<div>
<Select
mode="multiple"
style={{ width: '100%' }}
placeholder="Please select unrestricted roles"
onChange={this.handleUnrestrictedRolesChange}
value={temporaryUnrestrictedRoles}
>
{globalUnrestrictedRoles.map(unrestrictedRole => {
return (
<Option key={unrestrictedRole}>{unrestrictedRole}</Option>
);
})}
</Select>
<div style={{ marginTop: 10 }}>
<Button
style={{ marginRight: 10 }}
size="small"
htmlType="button"
onClick={this.disableUnrestrictedRolesEdit}
>
Cancel
</Button>
<Button
size="small"
type="primary"
htmlType="button"
onClick={this.handleUnrestrictedRolesSave}
>
Save
</Button>
</div>
</div>
)}
{!isUnrestrictedRolesEditEnabled && (
<span>
{unrestrictedRoles.map(unrestrictedRole => {
return (
<Tag
color={this.config.theme.primaryColor}
key={unrestrictedRole}
style={{ marginBottom: 5 }}
>
{unrestrictedRole}
</Tag>
);
})}
</span>
)}
<Authorized <Authorized
permission="/permission/admin/app-mgt/publisher/review/view" permission="/permission/admin/app-mgt/publisher/review/view"
yes={ yes={

Loading…
Cancel
Save