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 ++- 5 files changed, 122 insertions(+), 56 deletions(-) (limited to 'webapp/components') 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} /> ); } -- cgit v1.2.3-1-g7c22