Skip to content

Commit

Permalink
LTI-208: fetch record settings for legacy rooms from external app (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfederico authored Feb 16, 2023
1 parent 73d0f95 commit 4fdbd9f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
68 changes: 41 additions & 27 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

require 'bbb_app_rooms/user'
require 'json'
require 'uri'
require 'bbb_app_rooms/user'
require 'net/http'

class RoomsController < ApplicationController
# Include libraries.
Expand Down Expand Up @@ -257,13 +259,15 @@ def set_launch

# Continue through happy path.
@tenant = session_params['tenant']
resource_handler = Digest::SHA1.hexdigest("rooms#{@tenant}#{launch_params['resource_link_id']}")
to_new_room_params = launch_params_to_new_room_params(launch_params)
@room = Room.find_by(handler: resource_handler, tenant: @tenant)
handler = Digest::SHA1.hexdigest("rooms#{@tenant}#{launch_params['resource_link_id']}")
new_room_params = launch_params_to_new_room_params(launch_params)
@room = Room.find_by(handler: handler, tenant: @tenant)
if @room
@room.update(to_new_room_params)
@room.update(new_room_params)
else
@room = Room.create(to_new_room_params)
# Overrides with fetched parameters if legacy api is enabled
new_room_params = fetch_new_room_params(new_room_params) if Rails.configuration.handler_legacy_api_enabled
@room = Room.create(new_room_params)
end

user_params = launch_params_to_new_user_params(launch_params)
Expand All @@ -286,32 +290,42 @@ def room_params
)
end

def new_room_params(name, description, recording, wait_moderator, all_moderators, hide_name, hide_description, handler_legacy, settings)
def launch_params_to_new_room_params(launch_params)
params.permit.merge(
name: name,
description: description,
name: launch_params['resource_link_title'] || t('default.room.room'),
description: launch_params['resource_link_description'] || '',
welcome: '',
recording: recording || true,
wait_moderator: wait_moderator || false,
all_moderators: all_moderators || false,
hide_name: hide_name || false,
hide_description: hide_description || false,
handler_legacy: handler_legacy,
settings: settings || {}
recording: launch_params['custom_params'].key?('custom_record') ? launch_params['custom_params']['custom_record'] : true,
wait_moderator: message_has_custom?(launch_params, 'wait_moderator') || false,
all_moderators: message_has_custom?(launch_params, 'all_moderators') || false,
hide_name: message_has_custom?(launch_params, 'hide_name') || false,
hide_description: message_has_custom?(launch_params, 'hide_description') || false,
handler_legacy: launch_params['custom_params'].key?('custom_handler_legacy') ? launch_params['custom_params']['custom_handler_legacy'] : nil,
settings: message_has_custom?(launch_params, 'settings') || {}
)
end

def launch_params_to_new_room_params(launch_params)
name = launch_params['resource_link_title'] || t('default.room.room')
description = launch_params['resource_link_description'] || ''
record = launch_params['custom_params'].key?('custom_record') ? launch_params['custom_params']['custom_record'] : true
wait_moderator = message_has_custom?(launch_params, 'wait_moderator')
all_moderators = message_has_custom?(launch_params, 'all_moderators')
hide_name = message_has_custom?(launch_params, 'hide_name')
hide_description = message_has_custom?(launch_params, 'hide_description')
handler_legacy = launch_params['custom_params'].key?('custom_handler_legacy') ? launch_params['custom_params']['custom_handler_legacy'] : nil
settings = message_has_custom?(launch_params, 'settings')
new_room_params(name, description, record, wait_moderator, all_moderators, hide_name, hide_description, handler_legacy, settings)
def fetch_new_room_params(new_room_params)
handler_legacy = new_room_params.key?('handler_legacy') ? new_room_params['handler_legacy'] : nil
handler_legacy_api_url = "#{Rails.configuration.handler_legacy_api_endpoint}rooms/#{handler_legacy}"
checksum = Digest::SHA256.hexdigest(handler_legacy_api_url + Rails.configuration.handler_legacy_api_secret)
uri = URI("#{handler_legacy_api_url}?checksum=#{checksum}")
res = Net::HTTP.get_response(uri)
return new_room_params unless res.is_a?(Net::HTTPSuccess)

room = JSON.parse(res.body)
params.permit.merge(
name: room['name'],
description: room['description'],
welcome: room['welcome'],
recording: room['recording'],
wait_moderator: room['wait_moderator'],
handler_legacy: handler_legacy,
settings: {
waitForModerator: room['wait_moderator'],
record: room['recording'],
}
)
end

def launch_params_to_new_user_params(launch_params)
Expand Down
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,9 @@ class Application < Rails::Application
checksum_env_var = ENV['BIGBLUEBUTTON_CHECKSUM_ALGORITHM']
null_or_invalid = checksum_env_var.nil? || !valid_sha_versions.include?(checksum_env_var.downcase)
config.checksum_algorithm = null_or_invalid ? 'sha1' : checksum_env_var.downcase

config.handler_legacy_api_endpoint = ENV['HANDLER_LEGACY_API_ENDPOINT']
config.handler_legacy_api_secret = ENV['HANDLER_LEGACY_API_SECRET']
config.handler_legacy_api_enabled = (config.handler_legacy_api_endpoint && config.handler_legacy_api_secret)
end
end
8 changes: 6 additions & 2 deletions dotenv
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,9 @@ RAILS_SERVE_STATIC_FILES=true
# LOG_LEVEL=warn

## SHA algorithm to use for checksum. sha1 is default
## BIGBLUEBUTTON_CHECKSUM_ALGORITHM: "SHA1|SHA256|SHA512"
# BIGBLUEBUTTON_CHECKSUM_ALGORITHM='sha256'
## BIGBLUEBUTTON_CHECKSUM_ALGORITHM: "SHA1|SHA256|SHA512"
# BIGBLUEBUTTON_CHECKSUM_ALGORITHM='sha256'

## Define endpoint for fetching data for rooms based on legacy_handler
# HANDLER_LEGACY_API_ENDPOINT=
# HANDLER_LEGACY_API_SECRET=

0 comments on commit 4fdbd9f

Please sign in to comment.