[FIX] Permissions to edit livechat when the user is a livechat-agent (#3294)
* [FIX] Permissions to edit livechat * Added the permission to edit livechat room custom fields Co-authored-by: Levy Costa <levycosta471@gmail.com> Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
8e3b79ed7c
commit
8f1036f57e
|
@ -48,7 +48,9 @@ const PERMISSIONS = [
|
||||||
'view-user-administration',
|
'view-user-administration',
|
||||||
'view-all-teams',
|
'view-all-teams',
|
||||||
'view-all-team-channels',
|
'view-all-team-channels',
|
||||||
'convert-team'
|
'convert-team',
|
||||||
|
'edit-omnichannel-contact',
|
||||||
|
'edit-livechat-room-customfields'
|
||||||
];
|
];
|
||||||
|
|
||||||
export async function setPermissions() {
|
export async function setPermissions() {
|
||||||
|
|
|
@ -37,10 +37,11 @@ Title.propTypes = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const LivechatEditView = ({
|
const LivechatEditView = ({
|
||||||
user, navigation, route, theme
|
user, navigation, route, theme, editOmnichannelContact, editLivechatRoomCustomfields
|
||||||
}) => {
|
}) => {
|
||||||
const [customFields, setCustomFields] = useState({});
|
const [customFields, setCustomFields] = useState({});
|
||||||
const [availableUserTags, setAvailableUserTags] = useState([]);
|
const [availableUserTags, setAvailableUserTags] = useState([]);
|
||||||
|
const [permissions, setPermissions] = useState([]);
|
||||||
|
|
||||||
const params = {};
|
const params = {};
|
||||||
const inputs = {};
|
const inputs = {};
|
||||||
|
@ -139,9 +140,15 @@ const LivechatEditView = ({
|
||||||
|
|
||||||
const onChangeText = (key, text) => { params[key] = text; };
|
const onChangeText = (key, text) => { params[key] = text; };
|
||||||
|
|
||||||
|
const getPermissions = async() => {
|
||||||
|
const permissionsArray = await RocketChat.hasPermission([editOmnichannelContact, editLivechatRoomCustomfields], livechat.rid);
|
||||||
|
setPermissions(permissionsArray);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getAgentDepartments();
|
getAgentDepartments();
|
||||||
getCustomFields();
|
getCustomFields();
|
||||||
|
getPermissions();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -162,6 +169,7 @@ const LivechatEditView = ({
|
||||||
onChangeText={text => onChangeText('name', text)}
|
onChangeText={text => onChangeText('name', text)}
|
||||||
onSubmitEditing={() => { inputs.name.focus(); }}
|
onSubmitEditing={() => { inputs.name.focus(); }}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[0]}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={I18n.t('Email')}
|
label={I18n.t('Email')}
|
||||||
|
@ -170,6 +178,7 @@ const LivechatEditView = ({
|
||||||
onChangeText={text => onChangeText('email', text)}
|
onChangeText={text => onChangeText('email', text)}
|
||||||
onSubmitEditing={() => { inputs.phone.focus(); }}
|
onSubmitEditing={() => { inputs.phone.focus(); }}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[0]}
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={I18n.t('Phone')}
|
label={I18n.t('Phone')}
|
||||||
|
@ -186,6 +195,7 @@ const LivechatEditView = ({
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[0]}
|
||||||
/>
|
/>
|
||||||
{Object.entries(customFields?.visitor || {}).map(([key, value], index, array) => (
|
{Object.entries(customFields?.visitor || {}).map(([key, value], index, array) => (
|
||||||
<TextInput
|
<TextInput
|
||||||
|
@ -200,6 +210,7 @@ const LivechatEditView = ({
|
||||||
inputs.topic.focus();
|
inputs.topic.focus();
|
||||||
}}
|
}}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[0]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
<Title
|
<Title
|
||||||
|
@ -213,6 +224,7 @@ const LivechatEditView = ({
|
||||||
onChangeText={text => onChangeText('topic', text)}
|
onChangeText={text => onChangeText('topic', text)}
|
||||||
onSubmitEditing={() => inputs.tags.focus()}
|
onSubmitEditing={() => inputs.tags.focus()}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[1]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
|
@ -236,6 +248,7 @@ const LivechatEditView = ({
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[1]}
|
||||||
/>
|
/>
|
||||||
<Chips
|
<Chips
|
||||||
items={tagParam.map(tag => ({ text: { text: tag }, value: tag }))}
|
items={tagParam.map(tag => ({ text: { text: tag }, value: tag }))}
|
||||||
|
@ -257,6 +270,7 @@ const LivechatEditView = ({
|
||||||
submit();
|
submit();
|
||||||
}}
|
}}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
editable={!!permissions[1]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
@ -274,7 +288,9 @@ LivechatEditView.propTypes = {
|
||||||
user: PropTypes.object,
|
user: PropTypes.object,
|
||||||
navigation: PropTypes.object,
|
navigation: PropTypes.object,
|
||||||
route: PropTypes.object,
|
route: PropTypes.object,
|
||||||
theme: PropTypes.string
|
theme: PropTypes.string,
|
||||||
|
editOmnichannelContact: PropTypes.array,
|
||||||
|
editLivechatRoomCustomfields: PropTypes.array
|
||||||
};
|
};
|
||||||
LivechatEditView.navigationOptions = ({
|
LivechatEditView.navigationOptions = ({
|
||||||
title: I18n.t('Livechat_edit')
|
title: I18n.t('Livechat_edit')
|
||||||
|
@ -282,7 +298,9 @@ LivechatEditView.navigationOptions = ({
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
server: state.server.server,
|
server: state.server.server,
|
||||||
user: getUserSelector(state)
|
user: getUserSelector(state),
|
||||||
|
editOmnichannelContact: state.permissions['edit-omnichannel-contact'],
|
||||||
|
editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields']
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withTheme(LivechatEditView));
|
export default connect(mapStateToProps)(withTheme(LivechatEditView));
|
||||||
|
|
|
@ -55,6 +55,8 @@ class RoomInfoView extends React.Component {
|
||||||
isMasterDetail: PropTypes.bool,
|
isMasterDetail: PropTypes.bool,
|
||||||
jitsiEnabled: PropTypes.bool,
|
jitsiEnabled: PropTypes.bool,
|
||||||
editRoomPermission: PropTypes.array,
|
editRoomPermission: PropTypes.array,
|
||||||
|
editOmnichannelContact: PropTypes.array,
|
||||||
|
editLivechatRoomCustomfields: PropTypes.array,
|
||||||
roles: PropTypes.array
|
roles: PropTypes.array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +186,9 @@ class RoomInfoView extends React.Component {
|
||||||
|
|
||||||
loadRoom = async() => {
|
loadRoom = async() => {
|
||||||
const { room: roomState } = this.state;
|
const { room: roomState } = this.state;
|
||||||
const { route, editRoomPermission } = this.props;
|
const {
|
||||||
|
route, editRoomPermission, editOmnichannelContact, editLivechatRoomCustomfields
|
||||||
|
} = this.props;
|
||||||
let room = route.params?.room;
|
let room = route.params?.room;
|
||||||
if (room && room.observe) {
|
if (room && room.observe) {
|
||||||
this.roomObservable = room.observe();
|
this.roomObservable = room.observe();
|
||||||
|
@ -204,8 +208,10 @@ class RoomInfoView extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissions = await RocketChat.hasPermission([editRoomPermission], room.rid);
|
const permissionToEdit = this.isLivechat ? [editOmnichannelContact, editLivechatRoomCustomfields] : [editRoomPermission];
|
||||||
if (permissions[0]) {
|
|
||||||
|
const permissions = await RocketChat.hasPermission(permissionToEdit, room.rid);
|
||||||
|
if (permissions.some(Boolean)) {
|
||||||
this.setState({ showEdit: true }, () => this.setHeader());
|
this.setState({ showEdit: true }, () => this.setHeader());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,6 +376,8 @@ const mapStateToProps = state => ({
|
||||||
isMasterDetail: state.app.isMasterDetail,
|
isMasterDetail: state.app.isMasterDetail,
|
||||||
jitsiEnabled: state.settings.Jitsi_Enabled || false,
|
jitsiEnabled: state.settings.Jitsi_Enabled || false,
|
||||||
editRoomPermission: state.permissions['edit-room'],
|
editRoomPermission: state.permissions['edit-room'],
|
||||||
|
editOmnichannelContact: state.permissions['edit-omnichannel-contact'],
|
||||||
|
editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'],
|
||||||
roles: state.roles
|
roles: state.roles
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue