From 98e9d2c427887b2f4c70fe064ced5dadf6dcf088 Mon Sep 17 00:00:00 2001 From: ThomasRoehl Date: Mon, 19 Mar 2018 11:24:20 +0100 Subject: [PATCH] user can only access room creation tabs he has permission for --- packages/rocketchat-ui-sidenav/client/toolbar.js | 4 ++-- .../client/views/app/createRooms.js | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/rocketchat-ui-sidenav/client/toolbar.js b/packages/rocketchat-ui-sidenav/client/toolbar.js index e0ba6163e0ea..9aa07a0b88da 100644 --- a/packages/rocketchat-ui-sidenav/client/toolbar.js +++ b/packages/rocketchat-ui-sidenav/client/toolbar.js @@ -93,7 +93,7 @@ const getFromServerDebounced = _.debounce(getFromServer, 500); Template.toolbar.helpers({ canCreate() { - return RocketChat.authz.hasAtLeastOnePermission(['create-c', 'create-p']); + return RocketChat.authz.hasAtLeastOnePermission(RocketChat.roomTypes.roomTypesOrder.map((type) => `create-${ type.identifier }`)); }, results() { return Template.instance().resultsList.get(); @@ -231,7 +231,7 @@ Template.toolbar.events({ }, 'click [role="search"] button, touchend [role="search"] button'(e) { - if (RocketChat.authz.hasAtLeastOnePermission(['create-c', 'create-p'])) { + if (RocketChat.authz.hasAtLeastOnePermission(RocketChat.roomTypes.roomTypesOrder.map((type) => `create-${ type.identifier }`))) { // TODO: resolve this name menu/sidebar/sidebav/flex... menu.close(); FlowRouter.go('create-channel'); diff --git a/packages/rocketchat-ui/client/views/app/createRooms.js b/packages/rocketchat-ui/client/views/app/createRooms.js index 905ef9297fe6..1d770a9edec0 100644 --- a/packages/rocketchat-ui/client/views/app/createRooms.js +++ b/packages/rocketchat-ui/client/views/app/createRooms.js @@ -20,12 +20,20 @@ const roomTypesAfterStandard = function() { ).filter((roomType) => roomType.creationTemplate && roomType.canBeCreated()); }; -const allTemplatesOrdered = function() { - return roomTypesBeforeStandard() - .concat([{ +const standardRoomType = function() { + if (RocketChat.authz.hasAtLeastOnePermission(['create-c', 'create-p'])) { + return [{ creationLabel: 'Create_A_New_Channel', creationTemplate: 'createChannel' - }]) + }]; + } else { + return []; + } +}; + +const allTemplatesOrdered = function() { + return roomTypesBeforeStandard() + .concat(standardRoomType()) .concat(roomTypesAfterStandard()) .map((roomtype) => { return {