mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[PLT-6838] Restrict channel delete option per permission policy even for last channel member (#6706)
* channel delete option is hidden from the menu unless there is appropriate permissions as set in the policy page * apply to public channel only and add restriction to API layer * updated channel deletion
This commit is contained in:
@@ -720,11 +720,7 @@ export default class ChannelHeader extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
|
||||
if (!ChannelStore.isDefault(channel)) {
|
||||
dropdownContents.push(deleteOption);
|
||||
}
|
||||
} else if (this.state.userCount === 1) {
|
||||
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) {
|
||||
dropdownContents.push(deleteOption);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ export default class DeleteChannelModal extends React.Component {
|
||||
|
||||
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/town-square');
|
||||
deleteChannel(this.props.channel.id);
|
||||
this.onHide();
|
||||
}
|
||||
|
||||
onHide() {
|
||||
|
||||
@@ -529,23 +529,21 @@ export default class Navbar extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin) || this.state.userCount === 1) {
|
||||
if (!ChannelStore.isDefault(channel)) {
|
||||
deleteChannelOption = (
|
||||
<li role='presentation'>
|
||||
<ToggleModalButton
|
||||
role='menuitem'
|
||||
dialogType={DeleteChannelModal}
|
||||
dialogProps={{channel}}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='channel_header.delete'
|
||||
defaultMessage='Delete Channel'
|
||||
/>
|
||||
</ToggleModalButton>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) {
|
||||
deleteChannelOption = (
|
||||
<li role='presentation'>
|
||||
<ToggleModalButton
|
||||
role='menuitem'
|
||||
dialogType={DeleteChannelModal}
|
||||
dialogProps={{channel}}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='channel_header.delete'
|
||||
defaultMessage='Delete Channel'
|
||||
/>
|
||||
</ToggleModalButton>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
const canLeave = channel.type === Constants.PRIVATE_CHANNEL ? this.state.userCount > 1 : true;
|
||||
|
||||
@@ -190,11 +190,15 @@ export function showManagementOptions(channel, isAdmin, isSystemAdmin, isChannel
|
||||
return true;
|
||||
}
|
||||
|
||||
export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin) {
|
||||
export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, userCount) {
|
||||
if (global.window.mm_license.IsLicensed !== 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ChannelStore.isDefault(channel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (channel.type === Constants.OPEN_CHANNEL) {
|
||||
if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
@@ -206,6 +210,9 @@ export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin
|
||||
return false;
|
||||
}
|
||||
} else if (channel.type === Constants.PRIVATE_CHANNEL) {
|
||||
if (userCount === 1) {
|
||||
return true;
|
||||
}
|
||||
if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user