[MM-27274] Add and enforce convert public channel to private permission (#4756)
* Update permission check for convert public channel to private using new permission * Better variable name
This commit is contained in:
parent
4f4be1b319
commit
87802031f8
2 changed files with 22 additions and 3 deletions
|
|
@ -26,6 +26,7 @@ export default {
|
|||
LIST_TEAM_CHANNELS: 'list_team_channels',
|
||||
JOIN_PUBLIC_CHANNELS: 'join_public_channels',
|
||||
DELETE_PUBLIC_CHANNEL: 'delete_public_channel',
|
||||
CONVERT_PUBLIC_CHANNEL_TO_PRIVATE: 'convert_public_channel_to_private',
|
||||
DELETE_PRIVATE_CHANNEL: 'delete_private_channel',
|
||||
EDIT_OTHER_USERS: 'edit_other_users',
|
||||
READ_CHANNEL: 'read_channel',
|
||||
|
|
|
|||
|
|
@ -4,24 +4,42 @@
|
|||
import {connect} from 'react-redux';
|
||||
|
||||
import {convertChannelToPrivate} from '@mm-redux/actions/channels';
|
||||
import {General} from '@mm-redux/constants';
|
||||
import {General, Permissions} from '@mm-redux/constants';
|
||||
import {haveIChannelPermission} from '@mm-redux/selectors/entities/roles';
|
||||
import {getServerVersion} from '@mm-redux/selectors/entities/general';
|
||||
import {getCurrentChannel} from '@mm-redux/selectors/entities/channels';
|
||||
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
|
||||
import {getCurrentUserRoles} from '@mm-redux/selectors/entities/users';
|
||||
import {isAdmin as checkIsAdmin} from '@mm-redux/utils/user_utils';
|
||||
import {isMinimumServerVersion} from '@mm-redux/utils/helpers';
|
||||
|
||||
import ConvertPrivate from './convert_private';
|
||||
|
||||
function mapStateToProps(state) {
|
||||
const currentChannel = getCurrentChannel(state);
|
||||
const channelId = currentChannel?.id || '';
|
||||
const currentTeamId = getCurrentTeamId(state);
|
||||
const isDefaultChannel = currentChannel.name === General.DEFAULT_CHANNEL;
|
||||
const isPublicChannel = currentChannel.type === General.OPEN_CHANNEL;
|
||||
const isChannelConvertible = !isDefaultChannel && isPublicChannel;
|
||||
const roles = getCurrentUserRoles(state) || '';
|
||||
const isAdmin = checkIsAdmin(roles);
|
||||
const canConvert = !isDefaultChannel && isPublicChannel && isAdmin;
|
||||
let canConvert = isChannelConvertible && isAdmin;
|
||||
if (isMinimumServerVersion(getServerVersion(state), 5, 28)) {
|
||||
canConvert = isChannelConvertible && haveIChannelPermission(
|
||||
state,
|
||||
{
|
||||
channel: channelId,
|
||||
team: currentTeamId,
|
||||
permission: Permissions.CONVERT_PUBLIC_CHANNEL_TO_PRIVATE,
|
||||
default: isAdmin,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
canConvert,
|
||||
channelId: currentChannel?.id || '',
|
||||
channelId,
|
||||
displayName: (currentChannel?.display_name || '').trim(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue