Skip to content

Commit

Permalink
LTI-321: Pull Default Room Setting Values From Broker (feat) (#299)
Browse files Browse the repository at this point in the history
* LTI-321: Pull Default Room Setting Values From Broker

* LTI-321: Fixed errors

* LTI-321: Updated initialize_setting_defaults to make the code cleaner

* LTI-321: Fixed errors presented by rubocop

* LTI-321: Fixed Rspec errors

* LTI-321: Fixed default settings not appearing if room_setting_defaults is not applied

* LTI-321: Fixed Rubocop offense

---------

Co-authored-by: ahmed-abdou1 <[email protected]>
  • Loading branch information
jfederico and ahmed-abdou1 authored Apr 11, 2024
1 parent 54aaf58 commit 1811a8e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
4 changes: 4 additions & 0 deletions app/controllers/concerns/broker_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ def hide_build_tag(tenant)
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')
end
end
54 changes: 40 additions & 14 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Room < ApplicationRecord

attr_accessor :can_grade

include BrokerHelper

RECORDING_SETTINGS = [:record, :autoStartRecording, :allowStartStopRecording].freeze
CODE_LENGTH = 10

Expand Down Expand Up @@ -84,20 +86,44 @@ def delete_settings
end

def initialize_setting_defaults
self.lockSettingsDisableCam = '0' unless lockSettingsDisableCam_changed?
self.lockSettingsDisableMic = '0' unless lockSettingsDisableMic_changed?
self.lockSettingsDisablePrivateChat = '0' unless lockSettingsDisablePrivateChat_changed?
self.lockSettingsDisablePublicChat = '0' unless lockSettingsDisablePublicChat_changed?
self.lockSettingsDisableNote = '0' unless lockSettingsDisableNote_changed?
self.autoStartRecording = '0' unless autoStartRecording_changed?
self.allowStartStopRecording = '1' unless allowStartStopRecording_changed?

# these settings existed as their own column in the db
# therefore we take the value in that column if it already exists
# this is done to ensure previous values are not overwritten.
self.waitForModerator = wait_moderator.nil? ? '1' : bool_to_binary(wait_moderator) unless waitForModerator_changed?
self.allModerators = all_moderators.nil? ? '0' : bool_to_binary(all_moderators) unless allModerators_changed?
self.record = record.nil? ? '1' : bool_to_binary(record) unless record_changed?
# get the key value pair from the broker using the room_setting_defaults function
room_settings = room_setting_defaults(tenant)

# Define default values
defaults = {
lockSettingsDisableCam: '0',
lockSettingsDisableMic: '0',
lockSettingsDisablePrivateChat: '0',
lockSettingsDisablePublicChat: '0',
lockSettingsDisableNote: '0',
autoStartRecording: '0',
allowStartStopRecording: '1',
waitForModerator: '1',
allModerators: '0',
record: '1',
}

if room_settings.blank?
# If room_settings is not present or null, assign defaults directly
defaults.each do |key, value|
send("#{key}=", value) unless send("#{key}_changed?")
end
else
# Parse the values using the parse_defaults function
parsed_defaults = parse_defaults(room_settings)

# Iterate over default values and set them using send method
defaults.each do |key, value|
send("#{key}=", parsed_defaults.fetch(key, value)) unless send("#{key}_changed?")
end
end
end

def parse_defaults(defaults_str)
defaults_str.gsub(/[{}]/, '').split(',').map do |pair|
key, value = pair.split(':')
[key.strip.to_sym, value.strip]
end.to_h
end

def bool_to_binary(value)
Expand Down

0 comments on commit 1811a8e

Please sign in to comment.