From 6bb65ef420fba17ec02e9b8005ca58bb60321cdc Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 4 Apr 2017 19:43:22 +0100 Subject: PLT-6139 (WebApp): Manage Private Channel Members (#5947) Honour the policy setting for add/remove members from private channels in the WebApp UI. --- .../components/admin_console/policy_settings.jsx | 27 ++++++- webapp/components/channel_header.jsx | 92 ++++++++++++++-------- webapp/components/channel_members_dropdown.jsx | 4 +- webapp/components/channel_members_modal.jsx | 45 +++++++---- webapp/components/popover_list_members.jsx | 10 ++- webapp/i18n/en.json | 10 ++- webapp/utils/channel_utils.jsx | 20 +++++ 7 files changed, 148 insertions(+), 60 deletions(-) diff --git a/webapp/components/admin_console/policy_settings.jsx b/webapp/components/admin_console/policy_settings.jsx index 13101e828..471d2d336 100644 --- a/webapp/components/admin_console/policy_settings.jsx +++ b/webapp/components/admin_console/policy_settings.jsx @@ -34,6 +34,7 @@ export default class PolicySettings extends AdminSettings { config.TeamSettings.RestrictPrivateChannelManagement = this.state.restrictPrivateChannelManagement; config.TeamSettings.RestrictPublicChannelDeletion = this.state.restrictPublicChannelDeletion; config.TeamSettings.RestrictPrivateChannelDeletion = this.state.restrictPrivateChannelDeletion; + config.TeamSettings.RestrictPrivateChannelManageMembers = this.state.restrictPrivateChannelManageMembers; return config; } @@ -49,7 +50,8 @@ export default class PolicySettings extends AdminSettings { restrictPublicChannelManagement: config.TeamSettings.RestrictPublicChannelManagement, restrictPrivateChannelManagement: config.TeamSettings.RestrictPrivateChannelManagement, restrictPublicChannelDeletion: config.TeamSettings.RestrictPublicChannelDeletion, - restrictPrivateChannelDeletion: config.TeamSettings.RestrictPrivateChannelDeletion + restrictPrivateChannelDeletion: config.TeamSettings.RestrictPrivateChannelDeletion, + restrictPrivateChannelManageMembers: config.TeamSettings.RestrictPrivateChannelManageMembers }; } @@ -214,6 +216,29 @@ export default class PolicySettings extends AdminSettings { /> } /> + + } + value={this.state.restrictPrivateChannelManageMembers} + onChange={this.handleChange} + helpText={ + + } + /> ); - dropdownContents.push( - - ); + + + + + ); - dropdownContents.push( - - ); + this.setState({showMembersModal: true})} + > + + + + ); + } else { + dropdownContents.push( + + ); + } } const deleteOption = ( diff --git a/webapp/components/channel_members_dropdown.jsx b/webapp/components/channel_members_dropdown.jsx index 5ccdcd4c1..8c8c7dc3a 100644 --- a/webapp/components/channel_members_dropdown.jsx +++ b/webapp/components/channel_members_dropdown.jsx @@ -9,6 +9,7 @@ import {removeUserFromChannel, makeUserChannelAdmin, makeUserChannelMember} from import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; +import {canManageMembers} from 'utils/channel_utils.jsx'; import React from 'react'; import {FormattedMessage} from 'react-intl'; @@ -91,8 +92,7 @@ export default class ChannelMembersDropdown extends React.Component { // Checks if the current user has the power to remove this member from the channel. canRemoveMember() { - // TODO: This will be implemented as part of PLT-5047. - return true; + return canManageMembers(this.props.channel, UserStore.isSystemAdminForCurrentUser(), TeamStore.isTeamAdminForCurrentTeam(), ChannelStore.isChannelAdminForCurrentChannel()); } render() { diff --git a/webapp/components/channel_members_modal.jsx b/webapp/components/channel_members_modal.jsx index ec5423fe2..a82c620ca 100644 --- a/webapp/components/channel_members_modal.jsx +++ b/webapp/components/channel_members_modal.jsx @@ -3,6 +3,12 @@ import MemberListChannel from './member_list_channel.jsx'; +import TeamStore from 'stores/team_store.jsx'; +import UserStore from 'stores/user_store.jsx'; +import ChannelStore from 'stores/channel_store.jsx'; + +import {canManageMembers} from 'utils/channel_utils.jsx'; + import React from 'react'; import {Modal} from 'react-bootstrap'; import {FormattedMessage} from 'react-intl'; @@ -24,6 +30,30 @@ export default class ChannelMembersModal extends React.Component { } render() { + const isSystemAdmin = UserStore.isSystemAdminForCurrentUser(); + const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam(); + const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel(); + + let addMembersButton = null; + if (canManageMembers(this.state.channel, isSystemAdmin, isTeamAdmin, isChannelAdmin)) { + addMembersButton = ( + { + this.props.showInviteModal(); + this.onHide(); + }} + > + + + ); + } + return (
- { - this.props.showInviteModal(); - this.onHide(); - }} - > - - + {addMembersButton} { @@ -156,7 +158,7 @@ export default class PopoverListMembers extends React.Component { defaultMessage='Manage Members' /> ); - if (!isAdmin && ChannelStore.isDefault(this.props.channel)) { + if (!canManageMembers(this.props.channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) && !ChannelStore.isDefault(this.props.channel)) { membersName = ( this.setState({showTeamMembersModal: false})} - isAdmin={isAdmin} + isAdmin={isTeamAdmin || isSystemAdmin} /> ); } diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json index 65ca9d1d4..37207b279 100755 --- a/webapp/i18n/en.json +++ b/webapp/i18n/en.json @@ -331,10 +331,12 @@ "admin.general.policy.restrictPrivateChannelCreationDescription": "Set policy on who can create private groups.", "admin.general.policy.restrictPrivateChannelCreationTitle": "Enable private group creation for:", "admin.general.policy.restrictPrivateChannelDeletionCommandLineToolLink": "command line tool", - "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.restrictPrivateChannelDeletionTitle": "Enable private group deletion for:", - "admin.general.policy.restrictPrivateChannelManagementDescription": "Set policy on who can rename and set the header or purpose for private groups.", - "admin.general.policy.restrictPrivateChannelManagementTitle": "Enable private group renaming for:", + "admin.general.policy.restrictPrivateChannelDeletionDescription": "Set policy on who can delete private channels. Deleted channels can be recovered from the database using a {commandLineToolLink}.", + "admin.general.policy.restrictPrivateChannelDeletionTitle": "Enable private channel deletion for:", + "admin.general.policy.restrictPrivateChannelManagementDescription": "Set policy on who can rename and set the header or purpose for private channels.", + "admin.general.policy.restrictPrivateChannelManagementTitle": "Enable private channel renaming for:", + "admin.general.policy.restrictPrivateChannelManageMembersDescription": "Set policy on who can add and remove members from private channels.", + "admin.general.policy.restrictPrivateChannelManageMembersTitle": "Enable managing of private channel members for:", "admin.general.policy.restrictPublicChannelCreationDescription": "Set policy on who can create public channels.", "admin.general.policy.restrictPublicChannelCreationTitle": "Enable public channel creation for:", "admin.general.policy.restrictPublicChannelDeletionCommandLineToolLink": "command line tool", diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx index d916ca254..2930e58b6 100644 --- a/webapp/utils/channel_utils.jsx +++ b/webapp/utils/channel_utils.jsx @@ -208,6 +208,26 @@ export function showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin return true; } +export function canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) { + 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) { + return false; + } + 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) { + return false; + } + } + + return true; +} + export function buildGroupChannelName(channelId) { const profiles = UserStore.getProfileListInChannel(channelId, true); let displayName = ''; -- cgit v1.2.3-1-g7c22