mattermost-mobile/app/components/autocomplete/at_mention/index.js
Farhan Munshi 7952b5aeb7
[MM-21923] Enforce channel mentions permission (#3875)
* MM-21923 Enforce channel mentions permission by hiding it from autocomplete and disabling @mention confirmation modal

Add tests for post_textbox channel mentions

* MM-21923 Set use channel mentions to true if server version is not minimum required

* MM-21923 Point to specific redux hash and update permission check to be easier to read

* MM-21923 Fix currentChannel.id
2020-02-26 18:41:47 -07:00

77 lines
2.5 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers';
import {autocompleteUsers} from 'mattermost-redux/actions/users';
import {getCurrentChannelId, getDefaultChannel} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {isLandscape} from 'app/selectors/device';
import {
filterMembersInChannel,
filterMembersNotInChannel,
filterMembersInCurrentTeam,
getMatchTermForAtMention,
} from 'app/selectors/autocomplete';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles';
import {Permissions} from 'mattermost-redux/constants';
import AtMention from './at_mention';
function mapStateToProps(state, ownProps) {
const {cursorPosition, isSearch} = ownProps;
const currentChannelId = getCurrentChannelId(state);
let useChannelMentions = true;
if (isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)) {
useChannelMentions = haveIChannelPermission(
state,
{
channel: currentChannelId,
permission: Permissions.USE_CHANNEL_MENTIONS,
},
);
}
const value = ownProps.value.substring(0, cursorPosition);
const matchTerm = getMatchTermForAtMention(value, isSearch);
let teamMembers;
let inChannel;
let outChannel;
if (isSearch) {
teamMembers = filterMembersInCurrentTeam(state, matchTerm);
} else {
inChannel = filterMembersInChannel(state, matchTerm);
outChannel = filterMembersNotInChannel(state, matchTerm);
}
return {
currentChannelId,
currentTeamId: getCurrentTeamId(state),
defaultChannel: getDefaultChannel(state),
matchTerm,
teamMembers,
inChannel,
outChannel,
requestStatus: state.requests.users.autocompleteUsers.status,
theme: getTheme(state),
isLandscape: isLandscape(state),
useChannelMentions,
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
autocompleteUsers,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(AtMention);