diff --git a/webapp/components/admin_console/policy_settings.jsx b/webapp/components/admin_console/policy_settings.jsx index 501e3724e2f..50b9d40336b 100644 --- a/webapp/components/admin_console/policy_settings.jsx +++ b/webapp/components/admin_console/policy_settings.jsx @@ -23,8 +23,12 @@ export default class PolicySettings extends AdminSettings { getConfigFromState(config) { config.TeamSettings.RestrictTeamInvite = this.state.restrictTeamInvite; + config.TeamSettings.RestrictPublicChannelCreation = this.state.restrictPublicChannelCreation; + config.TeamSettings.RestrictPrivateChannelCreation = this.state.restrictPrivateChannelCreation; config.TeamSettings.RestrictPublicChannelManagement = this.state.restrictPublicChannelManagement; config.TeamSettings.RestrictPrivateChannelManagement = this.state.restrictPrivateChannelManagement; + config.TeamSettings.RestrictPublicChannelDeletion = this.state.restrictPublicChannelDeletion; + config.TeamSettings.RestrictPrivateChannelDeletion = this.state.restrictPrivateChannelDeletion; return config; } @@ -32,8 +36,12 @@ export default class PolicySettings extends AdminSettings { getStateFromConfig(config) { return { restrictTeamInvite: config.TeamSettings.RestrictTeamInvite, + restrictPublicChannelCreation: config.TeamSettings.RestrictPublicChannelCreation, + restrictPrivateChannelCreation: config.TeamSettings.RestrictPrivateChannelCreation, restrictPublicChannelManagement: config.TeamSettings.RestrictPublicChannelManagement, - restrictPrivateChannelManagement: config.TeamSettings.RestrictPrivateChannelManagement + restrictPrivateChannelManagement: config.TeamSettings.RestrictPrivateChannelManagement, + restrictPublicChannelDeletion: config.TeamSettings.RestrictPublicChannelDeletion, + restrictPrivateChannelDeletion: config.TeamSettings.RestrictPrivateChannelDeletion }; } @@ -74,46 +82,154 @@ export default class PolicySettings extends AdminSettings { } /> + } + value={this.state.restrictPublicChannelCreation} + onChange={this.handleChange} + helpText={ + + } + /> + } value={this.state.restrictPublicChannelManagement} onChange={this.handleChange} helpText={ - } /> + } + value={this.state.restrictPublicChannelDeletion} + onChange={this.handleChange} + helpText={ + + + + ) + }} + /> + } + /> + + } + value={this.state.restrictPrivateChannelCreation} + onChange={this.handleChange} + helpText={ + + } + /> + } value={this.state.restrictPrivateChannelManagement} onChange={this.handleChange} helpText={ - + } + /> + + } + value={this.state.restrictPrivateChannelDeletion} + onChange={this.handleChange} + helpText={ + + + + ) + }} /> } /> diff --git a/webapp/components/channel_header.jsx b/webapp/components/channel_header.jsx index 52bed85cdea..555b539cdea 100644 --- a/webapp/components/channel_header.jsx +++ b/webapp/components/channel_header.jsx @@ -206,30 +206,6 @@ export default class ChannelHeader extends React.Component { }); } - showManagementOptions(channel, isAdmin, isSystemAdmin) { - if (global.window.mm_license.IsLicensed !== 'true') { - return true; - } - - if (channel.type === Constants.OPEN_CHANNEL) { - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - return false; - } - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - return false; - } - } else if (channel.type === Constants.PRIVATE_CHANNEL) { - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - return false; - } - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - return false; - } - } - - return true; - } - initWebrtc(contactId, isOnline) { if (isOnline && !this.state.isBusy) { GlobalActions.emitCloseRightHandSide(); @@ -521,7 +497,7 @@ export default class ChannelHeader extends React.Component { ); - if (this.showManagementOptions(channel, isAdmin, isSystemAdmin)) { + if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin)) { dropdownContents.push(
  • ); + } + if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin)) { if (!ChannelStore.isDefault(channel)) { dropdownContents.push(deleteOption); } diff --git a/webapp/components/more_channels.jsx b/webapp/components/more_channels.jsx index b0064f18a6b..5374c33448f 100644 --- a/webapp/components/more_channels.jsx +++ b/webapp/components/more_channels.jsx @@ -9,6 +9,7 @@ import TeamStore from 'stores/team_store.jsx'; import Constants from 'utils/constants.jsx'; import * as AsyncClient from 'utils/async_client.jsx'; +import * as ChannelUtils from 'utils/channel_utils.jsx'; import {joinChannel, searchMoreChannels} from 'actions/channel_actions.jsx'; import React from 'react'; @@ -151,14 +152,9 @@ export default class MoreChannels extends React.Component { const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); const isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); - if (global.window.mm_license.IsLicensed === 'true') { - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - createNewChannelButton = null; - createChannelHelpText = null; - } else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - createNewChannelButton = null; - createChannelHelpText = null; - } + if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) { + createNewChannelButton = null; + createChannelHelpText = null; } return ( diff --git a/webapp/components/navbar.jsx b/webapp/components/navbar.jsx index 07049446d10..338d4edd13b 100644 --- a/webapp/components/navbar.jsx +++ b/webapp/components/navbar.jsx @@ -222,30 +222,6 @@ export default class Navbar extends React.Component { }); } - showManagementOptions(channel, isAdmin, isSystemAdmin) { - if (global.window.mm_license.IsLicensed !== 'true') { - return true; - } - - if (channel.type === Constants.OPEN_CHANNEL) { - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - return false; - } - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - return false; - } - } else if (channel.type === Constants.PRIVATE_CHANNEL) { - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - return false; - } - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - return false; - } - } - - return true; - } - toggleFavorite = (e) => { e.preventDefault(); @@ -388,7 +364,7 @@ export default class Navbar extends React.Component { ); - if (this.showManagementOptions(channel, isAdmin, isSystemAdmin)) { + if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin)) { setChannelHeaderOption = (
  • diff --git a/webapp/components/new_channel_modal.jsx b/webapp/components/new_channel_modal.jsx index 2a7d93b0c4e..fc9fd02951f 100644 --- a/webapp/components/new_channel_modal.jsx +++ b/webapp/components/new_channel_modal.jsx @@ -6,6 +6,7 @@ import ReactDOM from 'react-dom'; import * as UserAgent from 'utils/user_agent.jsx'; import * as Utils from 'utils/utils.jsx'; +import * as ChannelUtils from 'utils/channel_utils.jsx'; import Constants from 'utils/constants.jsx'; import UserStore from 'stores/user_store.jsx'; @@ -141,18 +142,12 @@ export default class NewChannelModal extends React.Component { const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); const isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); - if (global.window.mm_license.IsLicensed === 'true') { - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - createPublicChannelLink = null; - } else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - createPublicChannelLink = null; - } + if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) { + createPublicChannelLink = null; + } - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - createPrivateChannelLink = null; - } else if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - createPrivateChannelLink = null; - } + if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, isSystemAdmin)) { + createPrivateChannelLink = null; } var channelTerm = ''; diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx index 0651ebeeeae..1b802b1b015 100644 --- a/webapp/components/sidebar.jsx +++ b/webapp/components/sidebar.jsx @@ -722,18 +722,12 @@ export default class Sidebar extends React.Component { ); - if (global.window.mm_license.IsLicensed === 'true') { - if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - createPublicChannelIcon = null; - } else if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - createPublicChannelIcon = null; - } + if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) { + createPublicChannelIcon = null; + } - if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { - createPrivateChannelIcon = null; - } else if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { - createPrivateChannelIcon = null; - } + if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, isSystemAdmin)) { + createPrivateChannelIcon = null; } let moreDirectChannelsModal; diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json index 641c8daa8ed..55727c115f4 100644 --- a/webapp/i18n/en.json +++ b/webapp/i18n/en.json @@ -310,11 +310,22 @@ "admin.general.policy": "Policy", "admin.general.policy.permissionsAdmin": "Team and System Admins", "admin.general.policy.permissionsAll": "All team members", + "admin.general.policy.permissionsAllChannel": "All channel members", "admin.general.policy.permissionsSystemAdmin": "System Admins", - "admin.general.policy.restrictPrivateChannelManagementDescription": "Set policy on who can create, delete, rename, and set the header or purpose for private groups.", - "admin.general.policy.restrictPrivateChannelManagementTitle": "Enable private group management permissions for:", - "admin.general.policy.restrictPublicChannelManagementDescription": "Set policy on who can create, delete, rename, and set the header or purpose for public channels.", - "admin.general.policy.restrictPublicChannelManagementTitle": "Enable public channel management permissions for:", + "admin.general.policy.restrictPublicChannelCreationTitle": "Enable public channel creation for:", + "admin.general.policy.restrictPublicChannelCreationDescription": "Set policy on who can create public channels.", + "admin.general.policy.restrictPublicChannelManagementTitle": "Enable public channel renaming for:", + "admin.general.policy.restrictPublicChannelManagementDescription": "Set policy on who can rename and set the header or purpose for public channels.", + "admin.general.policy.restrictPublicChannelDeletionTitle": "Enable public channel deletion for:", + "admin.general.policy.restrictPublicChannelDeletionDescription": "Set policy on who can delete public channels. Deleted channels can be recovered from the database using a {commandLineToolLink}.", + "admin.general.policy.restrictPublicChannelDeletionCommandLineToolLink": "command line tool", + "admin.general.policy.restrictPrivateChannelCreationTitle": "Enable private group creation for:", + "admin.general.policy.restrictPrivateChannelCreationDescription": "Set policy on who can create private groups.", + "admin.general.policy.restrictPrivateChannelManagementTitle": "Enable private group renaming for:", + "admin.general.policy.restrictPrivateChannelManagementDescription": "Set policy on who can rename and set the header or purpose for private groups.", + "admin.general.policy.restrictPrivateChannelDeletionTitle": "Enable private group deletion for:", + "admin.general.policy.restrictPrivateChannelDeletionDescription": "Set policy on who can delete private groups. Deleted groups can be recovered from the database using a {commandLineToolLink}.", + "admin.general.policy.restrictPrivateChannelDeletionCommandLineToolLink": "command line tool", "admin.general.policy.teamInviteDescription": "Set policy on who can invite others to a team using Invite New Member to invite new users by email, or the Get Team Invite Link options from the Main Menu. If Get Team Invite Link is used to share a link, you can expire the invite code from Team Settings > Invite Code after the desired users join the team.", "admin.general.policy.teamInviteTitle": "Enable sending team invites from:", "admin.general.privacy": "Privacy", diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx index 113d86ea83a..50573e077fd 100644 --- a/webapp/utils/channel_utils.jsx +++ b/webapp/utils/channel_utils.jsx @@ -82,6 +82,76 @@ export function sortChannelsByDisplayName(a, b) { return buildDisplayNameAndTypeComparable(a).localeCompare(buildDisplayNameAndTypeComparable(b), locale, {numeric: true}); } +export function showCreateOption(channelType, isAdmin, isSystemAdmin) { + if (global.window.mm_license.IsLicensed !== 'true') { + return true; + } + + 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) { + 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) { + return false; + } + } + + return true; +} + +export function showManagementOptions(channel, isAdmin, isSystemAdmin) { + if (global.window.mm_license.IsLicensed !== 'true') { + return true; + } + + if (channel.type === Constants.OPEN_CHANNEL) { + if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + return false; + } + if (global.window.mm_config.RestrictPublicChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + return false; + } + } else if (channel.type === Constants.PRIVATE_CHANNEL) { + if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + return false; + } + if (global.window.mm_config.RestrictPrivateChannelManagement === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + return false; + } + } + + return true; +} + +export function showDeleteOption(channel, isAdmin, isSystemAdmin) { + if (global.window.mm_license.IsLicensed !== 'true') { + return true; + } + + if (channel.type === Constants.OPEN_CHANNEL) { + if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + return false; + } + if (global.window.mm_config.RestrictPublicChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + return false; + } + } else if (channel.type === Constants.PRIVATE_CHANNEL) { + if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_SYSTEM_ADMIN && !isSystemAdmin) { + return false; + } + if (global.window.mm_config.RestrictPrivateChannelDeletion === Constants.PERMISSIONS_TEAM_ADMIN && !isAdmin) { + return false; + } + } + + return true; +} + /* * not exported helpers */