Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LTI-279: use params from broker for room handler if specified #251

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading