diff --git a/app/controllers/api/v1/rooms_configurations_controller.rb b/app/controllers/api/v1/rooms_configurations_controller.rb index c36d20a49eaad09ce5f52938759e5843d3704a73..66524eb4a8fde0b004b9dc8cc4eb536c3c1f7bfb 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 817730f94746af9d19b3da6a8a47daa9f97534f9..e4b4beeee3b60337cbccb6f7b3481d233e2e803b 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 8de3b18b546a18516b01eadc58ded41aa35ebe4e..8071cd2074c01bb68465baf9c5434ab782bcb081 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 21fa2aaf3d8e66a39dc60b19263c6044b5aa41b3..3b14be58c9d6a64a62898f92ee210453d96a50dd 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 0000000000000000000000000000000000000000..6a4c0388382b6123d3fc933d63b4edb38d07bd30 --- /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 31b3881f023a54198f2f3b2469885b8bf54b3a85..6851e54b9cded8c125d75ae7780bdd4c941cc02d 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 4aab1b6eb43592c4ca52354739b34de9ba4b7e31..9d38dd8cb60ed881f713dbbc4e8c0b0fd35b6d28 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