From 8f8a978e84ec8bbeac22928e6112bc697fa7176d Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Wed, 5 Jul 2017 06:32:27 +0800 Subject: [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 --- webapp/components/channel_header.jsx | 6 +----- webapp/components/delete_channel_modal.jsx | 1 + webapp/components/navbar.jsx | 32 ++++++++++++++---------------- webapp/utils/channel_utils.jsx | 9 ++++++++- 4 files changed, 25 insertions(+), 23 deletions(-) (limited to 'webapp') diff --git a/webapp/components/channel_header.jsx b/webapp/components/channel_header.jsx index a409baec6..b6fcf7ef7 100644 --- a/webapp/components/channel_header.jsx +++ b/webapp/components/channel_header.jsx @@ -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); } diff --git a/webapp/components/delete_channel_modal.jsx b/webapp/components/delete_channel_modal.jsx index 74ba51a4c..fd5447524 100644 --- a/webapp/components/delete_channel_modal.jsx +++ b/webapp/components/delete_channel_modal.jsx @@ -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() { diff --git a/webapp/components/navbar.jsx b/webapp/components/navbar.jsx index b27e22709..fa759cae7 100644 --- a/webapp/components/navbar.jsx +++ b/webapp/components/navbar.jsx @@ -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 = ( -
  • - - - -
  • - ); - } + if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) { + deleteChannelOption = ( +
  • + + + +
  • + ); } const canLeave = channel.type === Constants.PRIVATE_CHANNEL ? this.state.userCount > 1 : true; diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx index e3a9f0423..c29cea386 100644 --- a/webapp/utils/channel_utils.jsx +++ b/webapp/utils/channel_utils.jsx @@ -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; } -- cgit v1.2.3-1-g7c22