summaryrefslogtreecommitdiffstats
path: root/webapp/components
diff options
context:
space:
mode:
authorJonathan <jonfritz@gmail.com>2017-08-09 09:34:09 -0400
committerGitHub <noreply@github.com>2017-08-09 09:34:09 -0400
commitfd6856b674cc24deb708f2cd36c247662ee10bc7 (patch)
tree7c47d2468d894d7867fda71f0f6ac252832dd728 /webapp/components
parent6b741c4cea36f54b8f20c4a3e5871f00123db185 (diff)
downloadchat-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/components')
-rw-r--r--webapp/components/channel_header.jsx47
-rw-r--r--webapp/components/channel_members_dropdown/channel_members_dropdown.jsx2
-rw-r--r--webapp/components/channel_members_modal.jsx2
-rw-r--r--webapp/components/more_channels/more_channels.jsx4
-rw-r--r--webapp/components/navbar.jsx7
-rw-r--r--webapp/components/new_channel_modal/new_channel_modal.jsx6
-rw-r--r--webapp/components/popover_list_members/popover_list_members.jsx2
-rw-r--r--webapp/components/sidebar.jsx6
8 files changed, 35 insertions, 41 deletions
diff --git a/webapp/components/channel_header.jsx b/webapp/components/channel_header.jsx
index 42e66fd3a..f89c18745 100644
--- a/webapp/components/channel_header.jsx
+++ b/webapp/components/channel_header.jsx
@@ -286,10 +286,9 @@ export default class ChannelHeader extends React.Component {
</Popover>
);
let channelTitle = channel.display_name;
- const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
+ const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
- const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
const isDirect = (this.state.channel.type === Constants.DM_CHANNEL);
const isGroup = (this.state.channel.type === Constants.GM_CHANNEL);
let webrtc;
@@ -533,7 +532,7 @@ export default class ChannelHeader extends React.Component {
/>
);
- if (ChannelUtils.canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin)) {
+ if (ChannelUtils.canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
dropdownContents.push(
<li
key='add_members'
@@ -594,26 +593,7 @@ export default class ChannelHeader extends React.Component {
}
}
- const deleteOption = (
- <li
- key='delete_channel'
- role='presentation'
- >
- <ToggleModalButton
- id='channelDelete'
- role='menuitem'
- dialogType={DeleteChannelModal}
- dialogProps={{channel}}
- >
- <FormattedMessage
- id='channel_header.delete'
- defaultMessage='Delete Channel'
- />
- </ToggleModalButton>
- </li>
- );
-
- if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
+ if (ChannelUtils.showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
dropdownContents.push(
<li
key='divider-2'
@@ -679,8 +659,25 @@ export default class ChannelHeader extends React.Component {
);
}
- if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) {
- dropdownContents.push(deleteOption);
+ if (ChannelUtils.showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
+ dropdownContents.push(
+ <li
+ key='delete_channel'
+ role='presentation'
+ >
+ <ToggleModalButton
+ id='channelDelete'
+ role='menuitem'
+ dialogType={DeleteChannelModal}
+ dialogProps={{channel}}
+ >
+ <FormattedMessage
+ id='channel_header.delete'
+ defaultMessage='Delete Channel'
+ />
+ </ToggleModalButton>
+ </li>
+ );
}
const canLeave = channel.type === Constants.PRIVATE_CHANNEL ? this.state.userCount > 1 : true;
diff --git a/webapp/components/channel_members_dropdown/channel_members_dropdown.jsx b/webapp/components/channel_members_dropdown/channel_members_dropdown.jsx
index f8ff3a4f6..fbad6cde1 100644
--- a/webapp/components/channel_members_dropdown/channel_members_dropdown.jsx
+++ b/webapp/components/channel_members_dropdown/channel_members_dropdown.jsx
@@ -95,7 +95,7 @@ export default class ChannelMembersDropdown extends React.Component {
// Checks if the current user has the power to remove this member from the channel.
canRemoveMember() {
- return canManageMembers(this.props.channel, UserStore.isSystemAdminForCurrentUser(), TeamStore.isTeamAdminForCurrentTeam(), ChannelStore.isChannelAdminForCurrentChannel());
+ return canManageMembers(this.props.channel, ChannelStore.isChannelAdminForCurrentChannel(), TeamStore.isTeamAdminForCurrentTeam(), UserStore.isSystemAdminForCurrentUser());
}
render() {
diff --git a/webapp/components/channel_members_modal.jsx b/webapp/components/channel_members_modal.jsx
index d361f6b7c..f991b7599 100644
--- a/webapp/components/channel_members_modal.jsx
+++ b/webapp/components/channel_members_modal.jsx
@@ -38,7 +38,7 @@ export default class ChannelMembersModal extends React.Component {
const isChannelAdmin = ChannelStore.isChannelAdminForCurrentChannel();
let addMembersButton = null;
- if (canManageMembers(this.state.channel, isSystemAdmin, isTeamAdmin, isChannelAdmin) && this.state.channel.name !== Constants.DEFAULT_CHANNEL) {
+ if (canManageMembers(this.state.channel, isChannelAdmin, isTeamAdmin, isSystemAdmin) && this.state.channel.name !== Constants.DEFAULT_CHANNEL) {
addMembersButton = (
<a
id='showInviteModal'
diff --git a/webapp/components/more_channels/more_channels.jsx b/webapp/components/more_channels/more_channels.jsx
index 45833ead2..ecc7aecf8 100644
--- a/webapp/components/more_channels/more_channels.jsx
+++ b/webapp/components/more_channels/more_channels.jsx
@@ -165,10 +165,10 @@ export default class MoreChannels extends React.Component {
</p>
);
- const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
+ const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
- if (!showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
+ if (!showCreateOption(Constants.OPEN_CHANNEL, isTeamAdmin, isSystemAdmin)) {
createNewChannelButton = null;
createChannelHelpText = null;
}
diff --git a/webapp/components/navbar.jsx b/webapp/components/navbar.jsx
index 0217dc15c..25c458523 100644
--- a/webapp/components/navbar.jsx
+++ b/webapp/components/navbar.jsx
@@ -287,7 +287,6 @@ export default class Navbar extends React.Component {
};
createDropdown(channel, channelTitle, isSystemAdmin, isTeamAdmin, isChannelAdmin, isDirect, isGroup, popoverContent) {
- const isAdmin = isSystemAdmin || isTeamAdmin;
const infoIcon = Constants.INFO_ICON_SVG;
if (channel) {
@@ -434,7 +433,7 @@ export default class Navbar extends React.Component {
</li>
);
- if (ChannelUtils.canManageMembers(channel, isSystemAdmin, isTeamAdmin, isChannelAdmin)) {
+ if (ChannelUtils.canManageMembers(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
manageMembersOption = (
<li
key='manage_members'
@@ -492,7 +491,7 @@ export default class Navbar extends React.Component {
</li>
);
- if (ChannelUtils.showManagementOptions(channel, isAdmin, isSystemAdmin, isChannelAdmin)) {
+ if (ChannelUtils.showManagementOptions(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
setChannelHeaderOption = (
<li role='presentation'>
<a
@@ -539,7 +538,7 @@ export default class Navbar extends React.Component {
);
}
- if (ChannelUtils.showDeleteOption(channel, isAdmin, isSystemAdmin, isChannelAdmin, this.state.userCount)) {
+ if (ChannelUtils.showDeleteOptionForCurrentUser(channel, isChannelAdmin, isTeamAdmin, isSystemAdmin)) {
deleteChannelOption = (
<li role='presentation'>
<ToggleModalButton
diff --git a/webapp/components/new_channel_modal/new_channel_modal.jsx b/webapp/components/new_channel_modal/new_channel_modal.jsx
index 60c0271a7..721defe08 100644
--- a/webapp/components/new_channel_modal/new_channel_modal.jsx
+++ b/webapp/components/new_channel_modal/new_channel_modal.jsx
@@ -192,13 +192,11 @@ export default class NewChannelModal extends React.PureComponent {
</a>
);
- const isAdmin = this.props.isTeamAdmin || this.props.isSystemAdmin;
-
- if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, this.props.isSystemAdmin)) {
+ if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, this.props.isTeamAdmin, this.props.isSystemAdmin)) {
createPublicChannelLink = null;
}
- if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, this.props.isSystemAdmin)) {
+ if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, this.props.isTeamAdmin, this.props.isSystemAdmin)) {
createPrivateChannelLink = null;
}
diff --git a/webapp/components/popover_list_members/popover_list_members.jsx b/webapp/components/popover_list_members/popover_list_members.jsx
index e706a1cec..35d0eab6b 100644
--- a/webapp/components/popover_list_members/popover_list_members.jsx
+++ b/webapp/components/popover_list_members/popover_list_members.jsx
@@ -156,7 +156,7 @@ export default class PopoverListMembers extends React.Component {
/>
);
- const manageMembers = canManageMembers(this.props.channel, isSystemAdmin, isTeamAdmin, isChannelAdmin);
+ const manageMembers = canManageMembers(this.props.channel, isChannelAdmin, isTeamAdmin, isSystemAdmin);
const isDefaultChannel = ChannelStore.isDefault(this.props.channel);
if ((manageMembers === false && isDefaultChannel === false) || isDefaultChannel) {
diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx
index 9b4625ea5..31d6825c8 100644
--- a/webapp/components/sidebar.jsx
+++ b/webapp/components/sidebar.jsx
@@ -714,7 +714,7 @@ export default class Sidebar extends React.Component {
/>
);
- const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
+ const isTeamAdmin = TeamStore.isTeamAdminForCurrentTeam();
const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
let createPublicChannelIcon = (
@@ -753,11 +753,11 @@ export default class Sidebar extends React.Component {
</OverlayTrigger>
);
- if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isAdmin, isSystemAdmin)) {
+ if (!ChannelUtils.showCreateOption(Constants.OPEN_CHANNEL, isTeamAdmin, isSystemAdmin)) {
createPublicChannelIcon = null;
}
- if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isAdmin, isSystemAdmin)) {
+ if (!ChannelUtils.showCreateOption(Constants.PRIVATE_CHANNEL, isTeamAdmin, isSystemAdmin)) {
createPrivateChannelIcon = null;
}