From d4f5035c3b2113313560066f04b35d87f577a31d Mon Sep 17 00:00:00 2001 From: dougfabris Date: Tue, 4 May 2021 17:03:48 -0300 Subject: [PATCH 1/2] add permission to teams channels --- .../channels/BaseTeamsChannels.js | 7 +++-- .../contextualBar/channels/RoomActions.js | 29 +++++++++++++------ .../channels/TeamsChannelItem.js | 24 ++++++++++----- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/client/views/teams/contextualBar/channels/BaseTeamsChannels.js b/client/views/teams/contextualBar/channels/BaseTeamsChannels.js index 322c11d6aaf10..50a9d0e42697c 100644 --- a/client/views/teams/contextualBar/channels/BaseTeamsChannels.js +++ b/client/views/teams/contextualBar/channels/BaseTeamsChannels.js @@ -14,6 +14,7 @@ import { Virtuoso } from 'react-virtuoso'; import ScrollableContentWrapper from '../../../../components/ScrollableContentWrapper'; import VerticalBar from '../../../../components/VerticalBar'; +import { usePermission } from '../../../../contexts/AuthorizationContext'; import { useTranslation } from '../../../../contexts/TranslationContext'; import Row from './Row'; @@ -35,6 +36,8 @@ const BaseTeamsChannels = ({ const t = useTranslation(); const inputRef = useAutoFocus(true); + const canAddChannel = usePermission('add-team-channel'); + const options = useMemo( () => [ ['all', t('All')], @@ -102,12 +105,12 @@ const BaseTeamsChannels = ({ - {onClickAddExisting && ( + {onClickAddExisting && canAddChannel && ( )} - {onClickCreateNew && ( + {onClickCreateNew && canAddChannel && ( diff --git a/client/views/teams/contextualBar/channels/RoomActions.js b/client/views/teams/contextualBar/channels/RoomActions.js index 2a5d14581aec5..7b177d6fcf8c7 100644 --- a/client/views/teams/contextualBar/channels/RoomActions.js +++ b/client/views/teams/contextualBar/channels/RoomActions.js @@ -3,6 +3,7 @@ import { useMutableCallback } from '@rocket.chat/fuselage-hooks'; import React, { useMemo } from 'react'; import { roomTypes } from '../../../../../app/utils/client'; +import { usePermission } from '../../../../contexts/AuthorizationContext'; import { useSetModal } from '../../../../contexts/ModalContext'; import { useToastMessageDispatch } from '../../../../contexts/ToastMessagesContext'; import { useTranslation } from '../../../../contexts/TranslationContext'; @@ -23,8 +24,15 @@ const useReactModal = (Component, props) => { const RoomActions = ({ room, reload }) => { const t = useTranslation(); + const rid = room._id; + const type = room.t; + const dispatchToastMessage = useToastMessageDispatch(); + const canDeleteTeamChannel = usePermission(type === 'c' ? 'delete-c' : 'delete-p', rid); + const canEditTeamChannel = usePermission('edit-team-channel'); + const canRemoveTeamChannel = usePermission('remove-team-channel'); + const updateRoomEndpoint = useEndpointActionExperimental('POST', 'teams.updateRoom'); const removeRoomEndpoint = useEndpointActionExperimental( 'POST', @@ -83,7 +91,7 @@ const RoomActions = ({ room, reload }) => { const AutoJoinAction = async () => { try { await updateRoomEndpoint({ - roomId: room._id, + roomId: rid, isDefault: !room.teamDefault, }); } catch (error) { @@ -94,38 +102,41 @@ const RoomActions = ({ room, reload }) => { }; return [ - { + canEditTeamChannel && { label: { label: t('Team_Auto-join'), - icon: room.t === 'c' ? 'hash' : 'hashtag-lock', + icon: type === 'c' ? 'hash' : 'hashtag-lock', }, action: AutoJoinAction, }, - { + canRemoveTeamChannel && { label: { label: t('Team_Remove_from_team'), icon: 'cross', }, action: RemoveFromTeamAction, }, - { + canDeleteTeamChannel && { label: { label: t('Delete'), icon: 'trash', }, action: DeleteChannelAction, }, - ]; + ].filter(Boolean); }, [ DeleteChannelAction, RemoveFromTeamAction, - room._id, - room.t, + rid, + type, room.teamDefault, t, updateRoomEndpoint, reload, dispatchToastMessage, + canDeleteTeamChannel, + canRemoveTeamChannel, + canEditTeamChannel, ]); return ( @@ -144,7 +155,7 @@ const RoomActions = ({ room, reload }) => { ) } - options={menuOptions} + options={(canEditTeamChannel || canRemoveTeamChannel || canDeleteTeamChannel) && menuOptions} /> ); }; diff --git a/client/views/teams/contextualBar/channels/TeamsChannelItem.js b/client/views/teams/contextualBar/channels/TeamsChannelItem.js index 73ff3cffbbe4f..5107b74f505cb 100644 --- a/client/views/teams/contextualBar/channels/TeamsChannelItem.js +++ b/client/views/teams/contextualBar/channels/TeamsChannelItem.js @@ -4,14 +4,22 @@ import React, { useState } from 'react'; import { roomTypes } from '../../../../../app/utils/client'; import RoomAvatar from '../../../../components/avatar/RoomAvatar'; +import { usePermission } from '../../../../contexts/AuthorizationContext'; import { useTranslation } from '../../../../contexts/TranslationContext'; import { usePreventProgation } from '../../../../hooks/usePreventProgation'; import RoomActions from './RoomActions'; const TeamsChannelItem = ({ room, onClickView, reload }) => { const t = useTranslation(); + const rid = room._id; + const type = room.t; + const [showButton, setShowButton] = useState(); + const canRemoveTeamChannel = usePermission('remove-team-channel'); + const canEditTeamChannel = usePermission('edit-team-channel'); + const canDeleteTeamChannel = usePermission(type === 'c' ? 'delete-c' : 'delete-p', rid); + const isReduceMotionEnabled = usePrefersReducedMotion(); const handleMenuEvent = { [isReduceMotionEnabled ? 'onMouseEnter' : 'onTransitionEnd']: setShowButton, @@ -39,13 +47,15 @@ const TeamsChannelItem = ({ room, onClickView, reload }) => { )} - - {showButton ? ( - - ) : ( - - )} - + {(canRemoveTeamChannel || canEditTeamChannel || canDeleteTeamChannel) && ( + + {showButton ? ( + + ) : ( + + )} + + )} ); }; From 2cea8dcdaffcd0303f93c5c8d4b73ad9d0855ef9 Mon Sep 17 00:00:00 2001 From: dougfabris Date: Tue, 4 May 2021 17:58:55 -0300 Subject: [PATCH 2/2] remove add --- .../teams/contextualBar/channels/BaseTeamsChannels.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/client/views/teams/contextualBar/channels/BaseTeamsChannels.js b/client/views/teams/contextualBar/channels/BaseTeamsChannels.js index 50a9d0e42697c..322c11d6aaf10 100644 --- a/client/views/teams/contextualBar/channels/BaseTeamsChannels.js +++ b/client/views/teams/contextualBar/channels/BaseTeamsChannels.js @@ -14,7 +14,6 @@ import { Virtuoso } from 'react-virtuoso'; import ScrollableContentWrapper from '../../../../components/ScrollableContentWrapper'; import VerticalBar from '../../../../components/VerticalBar'; -import { usePermission } from '../../../../contexts/AuthorizationContext'; import { useTranslation } from '../../../../contexts/TranslationContext'; import Row from './Row'; @@ -36,8 +35,6 @@ const BaseTeamsChannels = ({ const t = useTranslation(); const inputRef = useAutoFocus(true); - const canAddChannel = usePermission('add-team-channel'); - const options = useMemo( () => [ ['all', t('All')], @@ -105,12 +102,12 @@ const BaseTeamsChannels = ({ - {onClickAddExisting && canAddChannel && ( + {onClickAddExisting && ( )} - {onClickCreateNew && canAddChannel && ( + {onClickCreateNew && (