From de3c86619d12192e7f2418f1ff42a2bf15122ba7 Mon Sep 17 00:00:00 2001 From: Mariam A <tomariam@gmail.com> Date: Wed, 21 Jun 2023 10:39:54 -0400 Subject: [PATCH] Hide recording tabs when recording is disabled by admin (#5263) * Hide recording tabs when recording is disabled by admin * test and PR fixes --- .../api/v1/rooms_configurations_controller.rb | 16 +++++++++++- app/javascript/components/rooms/Rooms.jsx | 13 +++++++--- .../components/rooms/room/FeatureTabs.jsx | 17 +++++++++---- .../rooms/room/presentation/Presentation.jsx | 2 +- .../queries/rooms/useRoomConfigValue.jsx | 25 +++++++++++++++++++ config/routes.rb | 2 +- .../rooms_configurations_controller_spec.rb | 20 +++++++++++++++ 7 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 app/javascript/hooks/queries/rooms/useRoomConfigValue.jsx diff --git a/app/controllers/api/v1/rooms_configurations_controller.rb b/app/controllers/api/v1/rooms_configurations_controller.rb index c36d20a4..66524eb4 100644 --- a/app/controllers/api/v1/rooms_configurations_controller.rb +++ b/app/controllers/api/v1/rooms_configurations_controller.rb @@ -19,7 +19,7 @@ module Api module V1 class RoomsConfigurationsController < ApiController - before_action only: %i[index] do + before_action only: %i[index show] do ensure_authorized(%w[CreateRoom ManageSiteSettings ManageRoles ManageRooms], friendly_id: params[:friendly_id]) end @@ -33,6 +33,20 @@ module Api render_data data: rooms_configs, status: :ok end + + # GET /api/v1/rooms_configurations/:name.json + # Fetches and returns the value of the passed in configuration + def show + config_value = RoomsConfiguration.joins(:meeting_option) + .find_by( + provider: current_provider, + meeting_option: { name: params[:name] } + ).value + + render_data data: config_value, status: :ok + rescue StandardError + return render_error status: :not_found unless config_value + end end end end diff --git a/app/javascript/components/rooms/Rooms.jsx b/app/javascript/components/rooms/Rooms.jsx index 817730f9..e4b4beee 100644 --- a/app/javascript/components/rooms/Rooms.jsx +++ b/app/javascript/components/rooms/Rooms.jsx @@ -23,18 +23,25 @@ import RoomsList from './RoomsList'; import UserRecordings from '../recordings/UserRecordings'; import RecordingsCountTab from '../recordings/RecordingsCountTab'; import useRecordingsCount from '../../hooks/queries/recordings/useRecordingsCount'; +import useRoomConfigValue from '../../hooks/queries/rooms/useRoomConfigValue'; export default function Rooms() { const { data: recordingsCount } = useRecordingsCount(); const { t } = useTranslation(); + const { data: recordValue } = useRoomConfigValue('record'); + return ( <Tabs className="wide-white pt-5" defaultActiveKey="rooms" unmountOnExit> <Tab className="background-whitesmoke" eventKey="rooms" title={t('room.rooms')}> <RoomsList /> </Tab> - <Tab className="background-whitesmoke" eventKey="recordings" title={<RecordingsCountTab count={recordingsCount} />}> - <UserRecordings /> - </Tab> + + { (recordValue !== 'false') + && ( + <Tab className="background-whitesmoke" eventKey="recordings" title={<RecordingsCountTab count={recordingsCount} />}> + <UserRecordings /> + </Tab> + )} </Tabs> ); } diff --git a/app/javascript/components/rooms/room/FeatureTabs.jsx b/app/javascript/components/rooms/room/FeatureTabs.jsx index 8de3b18b..8071cd20 100644 --- a/app/javascript/components/rooms/room/FeatureTabs.jsx +++ b/app/javascript/components/rooms/room/FeatureTabs.jsx @@ -25,6 +25,7 @@ import { useAuth } from '../../../contexts/auth/AuthProvider'; import useSiteSetting from '../../../hooks/queries/site_settings/useSiteSetting'; import RoomRecordings from '../../recordings/room_recordings/RoomRecordings'; import useRoom from '../../../hooks/queries/rooms/useRoom'; +import useRoomConfigValue from '../../../hooks/queries/rooms/useRoomConfigValue'; export default function FeatureTabs() { const { t } = useTranslation(); @@ -33,8 +34,9 @@ export default function FeatureTabs() { const { friendlyId } = useParams(); const { data: room } = useRoom(friendlyId); + const { isLoading: isRoomConfigLoading, data: recordValue } = useRoomConfigValue('record'); - if (isLoading) { + if (isLoading || isRoomConfigLoading) { return ( <div className="wide-white pt-4 pb-2 mx-0"> <Placeholder className="ps-0" animation="glow"> @@ -47,11 +49,16 @@ export default function FeatureTabs() { ); } + const showRecTabs = (recordValue !== 'false'); + return ( - <Tabs className="wide-white pt-4 mx-0" defaultActiveKey="recordings" unmountOnExit> - <Tab className="background-whitesmoke" eventKey="recordings" title={t('recording.recordings')}> - <RoomRecordings /> - </Tab> + <Tabs className="wide-white pt-4 mx-0" defaultActiveKey={showRecTabs ? 'recordings' : 'presentation'} unmountOnExit> + {showRecTabs + && ( + <Tab className="background-whitesmoke" eventKey="recordings" title={t('recording.recordings')}> + <RoomRecordings /> + </Tab> + )} {settings?.PreuploadPresentation && ( <Tab className="background-whitesmoke" eventKey="presentation" title={t('room.presentation.presentation')}> diff --git a/app/javascript/components/rooms/room/presentation/Presentation.jsx b/app/javascript/components/rooms/room/presentation/Presentation.jsx index 21fa2aaf..3b14be58 100644 --- a/app/javascript/components/rooms/room/presentation/Presentation.jsx +++ b/app/javascript/components/rooms/room/presentation/Presentation.jsx @@ -38,7 +38,7 @@ export default function Presentation() { onSubmit(files[0]); }; - if (!room.presentation_name) { + if (!room?.presentation_name) { return ( <FilesDragAndDrop onDrop={onDrop} diff --git a/app/javascript/hooks/queries/rooms/useRoomConfigValue.jsx b/app/javascript/hooks/queries/rooms/useRoomConfigValue.jsx new file mode 100644 index 00000000..6a4c0388 --- /dev/null +++ b/app/javascript/hooks/queries/rooms/useRoomConfigValue.jsx @@ -0,0 +1,25 @@ +// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. +// +// Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below). +// +// This program is free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License as published by the Free Software +// Foundation; either version 3.0 of the License, or (at your option) any later +// version. +// +// Greenlight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License along +// with Greenlight; if not, see <http://www.gnu.org/licenses/>. + +import { useQuery } from 'react-query'; +import axios from '../../../helpers/Axios'; + +export default function useRoomConfigValue(name) { + return useQuery( + ['getRoomsConfigValue', name], + () => axios.get(`/rooms_configurations/${name}.json`).then((resp) => resp.data.data), + ); +} diff --git a/config/routes.rb b/config/routes.rb index 31b3881f..6851e54b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -83,7 +83,7 @@ Rails.application.routes.draw do post '/activate', to: 'verify_account#activate', on: :collection end resources :site_settings, only: :index - resources :rooms_configurations, only: :index + resources :rooms_configurations, only: %i[index show], param: :name resources :locales, only: %i[index show], param: :name namespace :admin do diff --git a/spec/controllers/rooms_configurations_controller_spec.rb b/spec/controllers/rooms_configurations_controller_spec.rb index 4aab1b6e..9d38dd8c 100644 --- a/spec/controllers/rooms_configurations_controller_spec.rb +++ b/spec/controllers/rooms_configurations_controller_spec.rb @@ -46,4 +46,24 @@ RSpec.describe Api::V1::RoomsConfigurationsController, type: :controller do expect(response).to have_http_status(:ok) end end + + describe 'rooms_configurations#show' do + before do + create(:rooms_configuration, meeting_option: create(:meeting_option, name: 'record'), value: 'false') + end + + it 'returns the correct configuration value' do + get :show, params: { name: 'record' } + + expect(JSON.parse(response.body)['data']).to eq('false') + + expect(response).to have_http_status(:ok) + end + + it 'returns :not_found if the configuration :name passed does not exist' do + get :show, params: { name: 'nonexistent' } + + expect(response).to have_http_status(:not_found) + end + end end -- GitLab