Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const PERMISSIONS = [
'view-user-administration',
'view-all-teams',
'view-all-team-channels',
'convert-team'
'convert-team',
'edit-omnichannel-contact',
'edit-livechat-room-customfields'
];

export async function setPermissions() {
Expand Down
24 changes: 21 additions & 3 deletions app/views/LivechatEditView.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ Title.propTypes = {
};

const LivechatEditView = ({
user, navigation, route, theme
user, navigation, route, theme, editOmnichannelContact, editLivechatRoomCustomfields
}) => {
const [customFields, setCustomFields] = useState({});
const [availableUserTags, setAvailableUserTags] = useState([]);
const [permissions, setPermissions] = useState([]);

const params = {};
const inputs = {};
Expand Down Expand Up @@ -139,9 +140,15 @@ const LivechatEditView = ({

const onChangeText = (key, text) => { params[key] = text; };

const getPermissions = async() => {
const permissionsArray = await RocketChat.hasPermission([editOmnichannelContact, editLivechatRoomCustomfields], livechat.rid);
setPermissions(permissionsArray);
};

useEffect(() => {
getAgentDepartments();
getCustomFields();
getPermissions();
}, []);

return (
Expand All @@ -162,6 +169,7 @@ const LivechatEditView = ({
onChangeText={text => onChangeText('name', text)}
onSubmitEditing={() => { inputs.name.focus(); }}
theme={theme}
editable={!!permissions[0]}
/>
<TextInput
label={I18n.t('Email')}
Expand All @@ -170,6 +178,7 @@ const LivechatEditView = ({
onChangeText={text => onChangeText('email', text)}
onSubmitEditing={() => { inputs.phone.focus(); }}
theme={theme}
editable={!!permissions[0]}
/>
<TextInput
label={I18n.t('Phone')}
Expand All @@ -186,6 +195,7 @@ const LivechatEditView = ({
}
}}
theme={theme}
editable={!!permissions[0]}
/>
{Object.entries(customFields?.visitor || {}).map(([key, value], index, array) => (
<TextInput
Expand All @@ -200,6 +210,7 @@ const LivechatEditView = ({
inputs.topic.focus();
}}
theme={theme}
editable={!!permissions[0]}
/>
))}
<Title
Expand All @@ -213,6 +224,7 @@ const LivechatEditView = ({
onChangeText={text => onChangeText('topic', text)}
onSubmitEditing={() => inputs.tags.focus()}
theme={theme}
editable={!!permissions[1]}
/>

<TextInput
Expand All @@ -236,6 +248,7 @@ const LivechatEditView = ({
}
}}
theme={theme}
editable={!!permissions[1]}
/>
<Chips
items={tagParam.map(tag => ({ text: { text: tag }, value: tag }))}
Expand All @@ -257,6 +270,7 @@ const LivechatEditView = ({
submit();
}}
theme={theme}
editable={!!permissions[1]}
/>
))}

Expand All @@ -274,15 +288,19 @@ LivechatEditView.propTypes = {
user: PropTypes.object,
navigation: PropTypes.object,
route: PropTypes.object,
theme: PropTypes.string
theme: PropTypes.string,
editOmnichannelContact: PropTypes.array,
editLivechatRoomCustomfields: PropTypes.array
};
LivechatEditView.navigationOptions = ({
title: I18n.t('Livechat_edit')
});

const mapStateToProps = state => ({
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));
14 changes: 11 additions & 3 deletions app/views/RoomInfoView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class RoomInfoView extends React.Component {
isMasterDetail: PropTypes.bool,
jitsiEnabled: PropTypes.bool,
editRoomPermission: PropTypes.array,
editOmnichannelContact: PropTypes.array,
editLivechatRoomCustomfields: PropTypes.array,
roles: PropTypes.array
}

Expand Down Expand Up @@ -184,7 +186,9 @@ class RoomInfoView extends React.Component {

loadRoom = async() => {
const { room: roomState } = this.state;
const { route, editRoomPermission } = this.props;
const {
route, editRoomPermission, editOmnichannelContact, editLivechatRoomCustomfields
} = this.props;
let room = route.params?.room;
if (room && room.observe) {
this.roomObservable = room.observe();
Expand All @@ -204,8 +208,10 @@ class RoomInfoView extends React.Component {
}
}

const permissions = await RocketChat.hasPermission([editRoomPermission], room.rid);
if (permissions[0]) {
const permissionToEdit = this.isLivechat ? [editOmnichannelContact, editLivechatRoomCustomfields] : [editRoomPermission];

const permissions = await RocketChat.hasPermission(permissionToEdit, room.rid);
if (permissions.some(Boolean)) {
this.setState({ showEdit: true }, () => this.setHeader());
}
}
Expand Down Expand Up @@ -370,6 +376,8 @@ const mapStateToProps = state => ({
isMasterDetail: state.app.isMasterDetail,
jitsiEnabled: state.settings.Jitsi_Enabled || false,
editRoomPermission: state.permissions['edit-room'],
editOmnichannelContact: state.permissions['edit-omnichannel-contact'],
editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'],
roles: state.roles
});

Expand Down