From fd6856b674cc24deb708f2cd36c247662ee10bc7 Mon Sep 17 00:00:00 2001
From: Jonathan <jonfritz@gmail.com>
Date: Wed, 9 Aug 2017 09:34:09 -0400
Subject: 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
---
 webapp/components/channel_header.jsx | 47 +++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

(limited to 'webapp/components/channel_header.jsx')

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;
-- 
cgit v1.2.3-1-g7c22

