From 5f7cb8cfbf879aa0b0d43a7b7068688368fda9fc Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Wed, 6 Jul 2016 08:23:24 -0400
Subject: PLT-3346/PLT-3342/PLT-3360 EE: Add the ability to restrict channel
 management permissions (#3453)

* EE: Add the ability to restrict channel management permissions

* Always allow last user in a channel to delete that channel
---
 webapp/components/sidebar.jsx | 77 ++++++++++++++++++++++++++++---------------
 1 file changed, 51 insertions(+), 26 deletions(-)

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

diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx
index 4f678274d..fdcae1dff 100644
--- a/webapp/components/sidebar.jsx
+++ b/webapp/components/sidebar.jsx
@@ -682,6 +682,55 @@ export default class Sidebar extends React.Component {
             />
         );
 
+        const isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser();
+        const isSystemAdmin = UserStore.isSystemAdminForCurrentUser();
+
+        let createPublicChannelIcon = (
+            <OverlayTrigger
+                delayShow={500}
+                placement='top'
+                overlay={createChannelTootlip}
+            >
+                <a
+                    className='add-channel-btn'
+                    href='#'
+                    onClick={this.showNewChannelModal.bind(this, Constants.OPEN_CHANNEL)}
+                >
+                    {'+'}
+                </a>
+            </OverlayTrigger>
+        );
+
+        let createPrivateChannelIcon = (
+            <OverlayTrigger
+                delayShow={500}
+                placement='top'
+                overlay={createGroupTootlip}
+            >
+                <a
+                    className='add-channel-btn'
+                    href='#'
+                    onClick={this.showNewChannelModal.bind(this, Constants.PRIVATE_CHANNEL)}
+                >
+                    {'+'}
+                </a>
+            </OverlayTrigger>
+        );
+
+        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 (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;
+            }
+        }
+
         return (
             <div
                 className='sidebar--left'
@@ -728,19 +777,7 @@ export default class Sidebar extends React.Component {
                                     id='sidebar.channels'
                                     defaultMessage='Channels'
                                 />
-                                <OverlayTrigger
-                                    delayShow={500}
-                                    placement='top'
-                                    overlay={createChannelTootlip}
-                                >
-                                    <a
-                                        className='add-channel-btn'
-                                        href='#'
-                                        onClick={this.showNewChannelModal.bind(this, 'O')}
-                                    >
-                                        {'+'}
-                                    </a>
-                                </OverlayTrigger>
+                                {createPublicChannelIcon}
                             </h4>
                         </li>
                         {publicChannelItems}
@@ -765,19 +802,7 @@ export default class Sidebar extends React.Component {
                                     id='sidebar.pg'
                                     defaultMessage='Private Groups'
                                 />
-                                <OverlayTrigger
-                                    delayShow={500}
-                                    placement='top'
-                                    overlay={createGroupTootlip}
-                                >
-                                    <a
-                                        className='add-channel-btn'
-                                        href='#'
-                                        onClick={this.showNewChannelModal.bind(this, 'P')}
-                                    >
-                                        {'+'}
-                                    </a>
-                                </OverlayTrigger>
+                                {createPrivateChannelIcon}
                             </h4>
                         </li>
                         {privateChannelItems}
-- 
cgit v1.2.3-1-g7c22

