diff --git a/config/initializers/bigbluebutton_rails.rb b/config/initializers/bigbluebutton_rails.rb index 19a407c50..5f196c541 100644 --- a/config/initializers/bigbluebutton_rails.rb +++ b/config/initializers/bigbluebutton_rails.rb @@ -37,7 +37,20 @@ record: ability.can?(:record_meeting, room) } end - + + config.get_join_options = Proc.new do |room, user| + if user.present? + # Add custom metadata join calls + include Mconf::LocaleControllerModule + opts = { + # FIXME: remove after team Live update bbb to version 2.4 + "userdata-mconf_custom_language": Mconf::LocaleControllerModule.get_user_locale(user), + "userdata-bbb_override_default_locale": Mconf::LocaleControllerModule.get_user_locale(user), + } + opts + end + end + end Rails.application.config.to_prepare do diff --git a/lib/mconf/locale_controller_module.rb b/lib/mconf/locale_controller_module.rb index 09a1b4192..d982acece 100644 --- a/lib/mconf/locale_controller_module.rb +++ b/lib/mconf/locale_controller_module.rb @@ -24,7 +24,7 @@ def get_user_locale(user, use_session=true) user.locale.to_sym # session locale - elsif use_session and session_has_locale?(session) + elsif use_session && defined?(session) && session_has_locale?(session) session[:locale] # site locale diff --git a/spec/lib/bigbluebutton_rails.rb b/spec/lib/bigbluebutton_rails.rb index 6b20e108a..bc521cdf9 100644 --- a/spec/lib/bigbluebutton_rails.rb +++ b/spec/lib/bigbluebutton_rails.rb @@ -81,6 +81,37 @@ end end + describe "#get_join_options" do + let(:target) { BigbluebuttonRails.configuration } + let(:room) { FactoryGirl.create(:bigbluebutton_room) } + + it { target.should respond_to(:get_join_options) } + it { target.get_create_options.should be_a(Proc) } + + context 'sets locale userdata' do + context 'when user has logged in' do + ["en", "pt-br"].each do |user_locale| + context "and its locale is set to #{user_locale.upcase}" do + let(:user) { FactoryGirl.create(:user, locale: user_locale) } + let(:join_options) { target.get_join_options.call(room, user, {}) } + let(:locale) { Mconf::LocaleControllerModule.get_user_locale(user) } + # FIXME: remove after team Live update bbb to version 2.4 + it { expect(join_options[:"userdata-mconf_custom_language"]).to eql(locale) } + it { expect(join_options[:"userdata-bbb_override_default_locale"]).to eql(locale) } + end + end + end + + context 'when user has not logged in' do + let(:join_options) { target.get_join_options.call(room, nil, {}) } + let(:locale) { Mconf::LocaleControllerModule.get_user_locale(nil) } + # FIXME: remove after team Live update bbb to version 2.4 + it { expect(join_options).to eql(nil) } + it { expect(join_options).to eql(nil) } + end + end + end + describe "#select_server" do let(:target) { BigbluebuttonRails.configuration } let(:room) { FactoryGirl.create(:bigbluebutton_room) }