diff --git a/app/controllers/concerns/bbb_helper.rb b/app/controllers/concerns/bbb_helper.rb index 402796c2..bc7a4080 100644 --- a/app/controllers/concerns/bbb_helper.rb +++ b/app/controllers/concerns/bbb_helper.rb @@ -115,7 +115,7 @@ def meeting_running? # Fetches all recordings for a room. def recordings - res = Rails.cache.fetch("#{@chosen_room.handler}/#{RECORDINGS_KEY}", expires_in: 30.minutes) if Rails.configuration.cache_enabled + res = Rails.cache.fetch("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) if Rails.configuration.cache_enabled res ||= bbb.get_recordings(meetingID: @chosen_room.handler) recordings_formatted(res) end @@ -152,25 +152,25 @@ def server_running? # Deletes a recording. def delete_recording(record_id) - Rails.cache.delete("#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled + Rails.cache.delete("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled bbb.delete_recordings(record_id) end # Publishes a recording. def publish_recording(record_id) - Rails.cache.delete("#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled + Rails.cache.delete("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled bbb.publish_recordings(record_id, true) end # Unpublishes a recording. def unpublish_recording(record_id) - Rails.cache.delete("#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled + Rails.cache.delete("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled bbb.publish_recordings(record_id, false) end # Updates a recording. def update_recording(record_id, meta) - Rails.cache.delete("#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled + Rails.cache.delete("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}") if Rails.configuration.cache_enabled meta[:recordID] = record_id bbb.send_api_request('updateRecordings', meta) end @@ -196,7 +196,7 @@ def meeting_start_time end def bigbluebutton_moderator_roles - roles_params = bbb_moderator_roles_params(@room.tenant) + roles_params = tenant_setting(@room.tenant, 'bigbluebutton_moderator_roles')&.split(',') roles_params.presence || Rails.configuration.bigbluebutton_moderator_roles.split(',') end diff --git a/app/controllers/concerns/broker_helper.rb b/app/controllers/concerns/broker_helper.rb index 207215d0..82e7fcac 100644 --- a/app/controllers/concerns/broker_helper.rb +++ b/app/controllers/concerns/broker_helper.rb @@ -18,39 +18,22 @@ module BrokerHelper include OmniauthHelper - # Fetch tenant settings from the broker - def tenant_settings(options = {}) - tenant = options[:tenant] || @room&.tenant || '' - bbbltibroker_url = omniauth_bbbltibroker_url("/api/v1/tenants/#{tenant}") - get_response = RestClient.get(bbbltibroker_url, 'Authorization' => "Bearer #{omniauth_client_token(omniauth_bbbltibroker_url)}") - - JSON.parse(get_response) + # Fetch tenant object from the broker + def broker_tenant_info(tenant) + # tenant ||= @room&.tenant || '' + Rails.cache.fetch("rooms/tenant/#{tenant}", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) do + bbbltibroker_url = omniauth_bbbltibroker_url("/api/v1/tenants/#{tenant}") + get_response = RestClient.get(bbbltibroker_url, 'Authorization' => "Bearer #{omniauth_client_token(omniauth_bbbltibroker_url)}") + + JSON.parse(get_response) + end rescue StandardError => e Rails.logger.error("Could not fetch tenant credentials from broker. Error message: #{e}") nil end - # Fetch the params to use when creating the room handler - def handler_params(tenant) - tenant_settings(tenant: tenant)&.[]('settings')&.[]('handler_params')&.split(',') - end - - # See whether shared rooms have been enabled in tenant settings. They are disabled by default. - def shared_rooms_enabled(tenant) - Rails.cache.fetch("rooms/tenant_settings/shared_rooms_enabled/#{tenant}", expires_in: 1.hour) do - tenant_settings(tenant: tenant)&.[]('settings')&.[]('enable_shared_rooms') == 'true' || false - end - end - - def hide_build_tag(tenant) - tenant_settings(tenant: tenant)&.[]('settings')&.[]('hide_build_tag') == 'true' || false - end - - def bbb_moderator_roles_params(tenant) - tenant_settings(tenant: tenant)&.[]('settings')&.[]('bigbluebutton_moderator_roles')&.split(',') - end - - def room_setting_defaults(tenant) - tenant_settings(tenant: tenant)&.dig('settings', 'room_setting_defaults') + def tenant_setting(tenant, setting) + tenant_settings = broker_tenant_info(tenant)&.[]('settings') + tenant_settings&.[](setting) end end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index dc336191..7c56a8c9 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -251,7 +251,7 @@ def individual_recording end helper_method :recording_date, :recording_length, :meeting_running?, :bigbluebutton_moderator_roles, - :bigbluebutton_recording_public_formats, :meeting_info, :bigbluebutton_recording_enabled, :server_running?, :shared_rooms_enabled, :hide_build_tag + :bigbluebutton_recording_public_formats, :meeting_info, :bigbluebutton_recording_enabled, :server_running? private @@ -293,7 +293,8 @@ def set_room # If the room is using a shared code, then use the shared room's recordings and bbb link def set_chosen_room - @shared_rooms_enabled = shared_rooms_enabled(@room&.tenant) + # See whether shared rooms have been enabled in tenant settings. They are disabled by default. + @shared_rooms_enabled = tenant_setting(@room&.tenant, 'enable_shared_rooms') == 'true' @shared_room = Room.find_by(code: @room.shared_code, tenant: @room.tenant) if @shared_rooms_enabled && @room&.use_shared_code use_shared_room = @shared_rooms_enabled && @room&.use_shared_code && Room.where(code: @room.shared_code, tenant: @room.tenant).exists? @@ -497,7 +498,7 @@ def room_handler(launch_params, tenant) input = "rooms#{tenant}" # use resource_link_id as the default param if nothing was specified in the broker settings - room_handler_params = handler_params(tenant).presence || ['resource_link_id'] + room_handler_params = tenant_setting(tenant, 'handler_params')&.split(',').presence || ['resource_link_id'] room_handler_params.each do |param| param_val = launch_params[param] diff --git a/app/helpers/rooms_helper.rb b/app/helpers/rooms_helper.rb index c220e324..b28dae58 100644 --- a/app/helpers/rooms_helper.rb +++ b/app/helpers/rooms_helper.rb @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License along # with BigBlueButton; if not, see . module RoomsHelper + include BrokerHelper + def autoclose_url 'javascript:window.close();' end @@ -41,4 +43,8 @@ def add_zero_maybe(num) num end + + def hide_build_tag? + tenant_setting(@room.tenant, 'hide_build_tag') == 'true' + end end diff --git a/app/models/room.rb b/app/models/room.rb index a6093476..c1bd2fb0 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -86,7 +86,7 @@ def delete_settings def initialize_setting_defaults # get the key value pair from the broker using the room_setting_defaults function - room_settings = room_setting_defaults(tenant) + room_settings = tenant_setting(tenant, 'room_setting_defaults') # Define default values defaults = { diff --git a/app/views/shared/_footer.html.erb b/app/views/shared/_footer.html.erb index 11a8760a..39582c21 100644 --- a/app/views/shared/_footer.html.erb +++ b/app/views/shared/_footer.html.erb @@ -14,7 +14,7 @@ %>