diff options
author | Jonathan <jonfritz@gmail.com> | 2017-08-09 09:34:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-09 09:34:09 -0400 |
commit | fd6856b674cc24deb708f2cd36c247662ee10bc7 (patch) | |
tree | 7c47d2468d894d7867fda71f0f6ac252832dd728 /webapp/utils/channel_utils.jsx | |
parent | 6b741c4cea36f54b8f20c4a3e5871f00123db185 (diff) | |
download | chat-fd6856b674cc24deb708f2cd36c247662ee10bc7.tar.gz chat-fd6856b674cc24deb708f2cd36c247662ee10bc7.tar.bz2 chat-fd6856b674cc24deb708f2cd36c247662ee10bc7.zip |
PLT-7206: Remove the "Delete Channel" option for private channels if you're the last channel member and policy setting restricts channel deletion (#7050)
* PLT-7206: UI changes. Removed last user in channel loophole, refactored code to clean it up, added differentiated support for public and private channels, added unit tests. Still need to implement server-side checks
* PLT-7206: All helper methods in channel_utils.jsx now accept the same three boolean variables in the same order and use the same boolean logic to check their values.
* PLT-7206: Added unit tests for showManagementOptions(...)
* PLT-7206: Fixed test case descriptions
* Added unit tests for showCreateOption(...)
* PLT-7206: Added unit tests for canManageMembers(...)
* PLT-7206: Removed last person in channel loophole from server-side code
* PLT-7206: Reverted config.json
* PLT-7206: Fixed double negatives in unit test names
* PLT-7206: PR feedback - Removed confusing comment and unused variable
Diffstat (limited to 'webapp/utils/channel_utils.jsx')
-rw-r--r-- | webapp/utils/channel_utils.jsx | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx index c29cea386..d9887ff89 100644 --- a/webapp/utils/channel_utils.jsx +++ b/webapp/utils/channel_utils.jsx @@ -138,7 +138,7 @@ export function getChannelDisplayName(channel) { return channel.display_name; } -export function showCreateOption(channelType, isAdmin, isSystemAdmin) { +export function showCreateOption(channelType, isTeamAdmin, isSystemAdmin) { if (global.window.mm_license.IsLicensed !== 'true') { return true; } @@ -146,13 +146,13 @@ export function showCreateOption(channelType, isAdmin, isSystemAdmin) { if (channelType === Constants.OPEN_CHANNEL) { if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { return false; - } else if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + } else if (global.window.mm_config.RestrictPublicChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } } else if (channelType === Constants.PRIVATE_CHANNEL) { if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { return false; - } else if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + } else if (global.window.mm_config.RestrictPrivateChannelCreation === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } } @@ -160,29 +160,30 @@ export function showCreateOption(channelType, isAdmin, isSystemAdmin) { return true; } -export function showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin) { +export function showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) { if (global.window.mm_license.IsLicensed !== 'true') { + // policies are only enforced in enterprise editions return true; } if (channel.type === Constants.OPEN_CHANNEL) { - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) { + if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { return false; } } else if (channel.type === Constants.PRIVATE_CHANNEL) { - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) { + if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { return false; } } @@ -190,36 +191,35 @@ export function showManagementOptions(channel, isAdmin, isSystemAdmin, isChannel return true; } -export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, userCount) { +export function showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) { if (global.window.mm_license.IsLicensed !== 'true') { + // policies are only enforced in enterprise editions return true; } if (ChannelStore.isDefault(channel)) { + // can't delete default channels, no matter who you are return false; } if (channel.type === Constants.OPEN_CHANNEL) { - if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) { + if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { 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) { + if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isAdmin) { + if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { return false; } } @@ -227,19 +227,19 @@ export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin return true; } -export function canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) { +export function canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) { if (global.window.mm_license.IsLicensed !== 'true') { return true; } if (channel.type === Constants.PRIVATE_CHANNEL) { - if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_CHANNEL_ADMIN && !(isChannelAdmin || isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_TEAM_ADMIN && !isTeamAdmin && !isSystemAdmin) { + if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_TEAM_ADMIN && !(isTeamAdmin || isSystemAdmin)) { return false; } - if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_CHANNEL_ADMIN && !isChannelAdmin && !isTeamAdmin && !isSystemAdmin) { + if (global.window.mm_config.RestrictPrivateChannelManageMembers === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { return false; } } |