Skip to content

Commit

Permalink
LTI-279: use params from broker for room handler if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariam05 committed Oct 30, 2023
1 parent 4c36281 commit c70d5db
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concerns/bbb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ def wait_for_mod?
# Return the number of participants in a meeting for the current room.
def participant_count
info = meeting_info
return info[:participantCount] if info[:returncode] == 'SUCCESS'
info[:participantCount] if info[:returncode] == 'SUCCESS'
end

# Return the meeting start time for the current room.
def meeting_start_time
info = meeting_info
return info[:startTime] if info[:returncode] == 'SUCCESS'
info[:startTime] if info[:returncode] == 'SUCCESS'
end

def bigbluebutton_moderator_roles
Expand Down
39 changes: 39 additions & 0 deletions app/controllers/concerns/broker_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
# Copyright (c) 2018 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.
# BigBlueButton 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 BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

module BrokerHelper
extend ActiveSupport::Concern

include OmniauthHelper

# Fetch tenant settings from the broker
def tenant_settings(options = {})
tenant = options[:tenant] || @room&.tenant || ''
Rails.cache.fetch("rooms/tenant_settings/#{tenant}", expires_in: 1.hour) 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
end
18 changes: 17 additions & 1 deletion app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RoomsController < ApplicationController
# Include concerns.
include BbbHelper
include OmniauthHelper
include BrokerHelper

before_action :print_parameters if Rails.configuration.developer_mode_enabled
before_action :authenticate_user!, except: %i[meeting_close], raise: false
Expand Down Expand Up @@ -296,7 +297,7 @@ def set_launch
end

def launch_room(launch_params, tenant)
handler = Digest::SHA1.hexdigest("rooms#{tenant}#{launch_params['resource_link_id']}")
handler = room_handler(launch_params, tenant)
handler_legacy = launch_params['custom_params']['custom_handler_legacy'].presence

## Any launch.
Expand Down Expand Up @@ -427,4 +428,19 @@ def set_current_locale

response.set_header('Content-Language', I18n.locale)
end

# Generate room handler based on the settings pulled from the broker
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.each do |param|
param_val = launch_params[param]
input += param_val.to_s if param_val
end

Digest::SHA1.hexdigest(input)
end
end

0 comments on commit c70d5db

Please sign in to comment.