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

Pass the request to get_create_options and get_join_options #177

Open
wants to merge 1 commit into
base: release-3.0
Choose a base branch
from
Open
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 Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PATH
bigbluebutton_rails (3.0.1)
activerecord-import (~> 1.0)
bigbluebutton-api-ruby (~> 1.6)
browser (~> 0.8.0)
browser (~> 2.0.0)
rails (>= 4.0.0)
resque (~> 1.25.1)
resque-scheduler (~> 3.0)
Expand Down Expand Up @@ -45,7 +45,7 @@ GEM
awesome_print (1.2.0)
bigbluebutton-api-ruby (1.7.0)
xml-simple (~> 1.1)
browser (0.8.0)
browser (2.0.3)
builder (3.2.2)
capybara (2.2.1)
mime-types (>= 1.16)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bigbluebutton/api/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def join
options = options.map{ |k,v| { k.gsub(/^meta[-_]/, 'userdata-') => v } }.reduce(:merge)
end

@url = @room.parameterized_join_url(@user_name, @user_role, nil, options)
@url = @room.parameterized_join_url(@user_name, @user_role, nil, options, request)
end

protected
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bigbluebutton/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def join_internal(username, role, id)
end

# room created and running, try to join it
url = @room.parameterized_join_url(username, role, id, {}, bigbluebutton_user)
url = @room.parameterized_join_url(username, role, id, {}, bigbluebutton_user, request)

unless url.nil?

Expand Down
14 changes: 8 additions & 6 deletions app/models/bigbluebutton_room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ def send_end
# * <tt>moderator_api_password</tt>
#
# Triggers API call: <tt>create</tt>.
def send_create(user=nil)
def send_create(user = nil, request = nil)
self.meetingid = unique_meetingid() if self.meetingid.blank?
self.moderator_api_password = internal_password() if self.moderator_api_password.blank?
self.attendee_api_password = internal_password() if self.attendee_api_password.blank?
self.save unless self.new_record?

# Get the user options to use when creating the meeting
user_opts = BigbluebuttonRails.configuration.get_create_options.call(self, user)
user_opts = BigbluebuttonRails.configuration.get_create_options.call(self, user, request)
user_opts = {} if user_opts.blank?

server, response = internal_create_meeting(user, user_opts)
Expand Down Expand Up @@ -264,7 +264,7 @@ def join_url(username, role, key=nil, options={})
r
end

def parameterized_join_url(username, role, id, options={}, user=nil)
def parameterized_join_url(username, role, id, options = {}, user = nil, request = nil)
opts = options.clone

# gets the token with the configurations for this user/room
Expand All @@ -278,7 +278,9 @@ def parameterized_join_url(username, role, id, options={}, user=nil)
opts.merge!({ userID: id }) unless id.blank? || options[:userID].present?

# Get options passed by the application, if any
user_opts = BigbluebuttonRails.configuration.get_join_options.call(self, user, { username: username, role: role })
user_opts = BigbluebuttonRails.configuration.get_join_options.call(
self, user || { username: username, role: role }, request
)
user_opts = {} if user_opts.blank?
opts.merge!(user_opts)

Expand Down Expand Up @@ -330,11 +332,11 @@ def to_param
# The create logic.
# Will create the meeting in this room unless it is already running.
# Returns true if the meeting was created.
def create_meeting(user=nil, request=nil)
def create_meeting(user = nil, request = nil)
fetch_is_running?
unless is_running?
add_domain_to_logout_url(request.protocol, request.host_with_port) unless request.nil?
send_create(user)
send_create(user, request)
true
else
false
Expand Down
2 changes: 1 addition & 1 deletion bigbluebutton_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Gem::Specification.new do |s|
s.add_dependency("bigbluebutton-api-ruby", "~> 1.6")
s.add_dependency("resque", "~> 1.25.1")
s.add_dependency("resque-scheduler", "~> 3.0")
s.add_dependency("browser", "~> 0.8.0")
s.add_dependency("browser", "~> 2.0.0")
s.add_dependency("activerecord-import", "~> 1.0")
end
7 changes: 4 additions & 3 deletions lib/bigbluebutton_rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ def initialize

# Define this method to return extra parameters to be passed to a `create` call.
# `user` is the user creating the meeting, if any.
@get_create_options = Proc.new{ |room, user| nil }
@get_create_options = Proc.new{ |room, user, request = nil| nil }

# Define this method to return extra parameters to be passed to a `join` call.
# `user` is the user joining the meeting, if any.
@get_join_options = Proc.new{ |room, user| nil }
# `user` is the user joining the meeting. If there's no user signed in, it will
# be a hash with the name and role set for the user joining.
@get_join_options = Proc.new{ |room, user, request = nil| nil }

# Selects a server to be used by `room` whenever it needs to make API calls.
# By default, if no servers are available an exception is raised.
Expand Down
2 changes: 1 addition & 1 deletion lib/bigbluebutton_rails/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module BigbluebuttonRails
# Returns whether the current client should use the mobile client
# or the desktop client.
def self.use_mobile_client?(browser)
browser.mobile? || browser.tablet?
browser.device.mobile? || browser.device.tablet?
end

# Just a wrapper around the Rails method to convert values to boolean
Expand Down
19 changes: 14 additions & 5 deletions spec/controllers/bigbluebutton/api/rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@

context "attendee in a public room" do
before {
room.should_receive(:parameterized_join_url).with('User 1', :attendee, nil, {}).and_return(expected_url)
room.should_receive(:parameterized_join_url)
.with('User 1', :attendee, nil, {}, controller.request).and_return(expected_url)
}
before(:each) { post :join, id: room.to_param, format: :json, name: 'User 1' }
it { JSON.parse(response.body)['data']['id'].should eql(expected_url) }
Expand All @@ -379,7 +380,9 @@
context "attendee in a private room" do
before {
room.update_attributes(private: true)
room.should_receive(:parameterized_join_url).with('User 1', :attendee, nil, {}).and_return(expected_url)
room.should_receive(:parameterized_join_url).with(
'User 1', :attendee, nil, {}, controller.request
).and_return(expected_url)
}
before(:each) { post :join, id: room.to_param, format: :json, name: 'User 1', key: room.attendee_key }
it { JSON.parse(response.body)['data']['id'].should eql(expected_url) }
Expand All @@ -388,7 +391,9 @@
context "moderator in a private room" do
before {
room.update_attributes(private: true)
room.should_receive(:parameterized_join_url).with('User 1', :moderator, nil, {}).and_return(expected_url)
room.should_receive(:parameterized_join_url).with(
'User 1', :moderator, nil, {}, controller.request
).and_return(expected_url)
}
before(:each) { post :join, id: room.to_param, format: :json, name: 'User 1', key: room.moderator_key }
it { JSON.parse(response.body)['data']['id'].should eql(expected_url) }
Expand All @@ -399,7 +404,9 @@
{ 'userdata-param-1' => 1, 'userdata-param_2' => 'string-2' }
}
before {
room.should_receive(:parameterized_join_url).with('User 1', :attendee, nil, expected_meta).and_return(expected_url)
room.should_receive(:parameterized_join_url).with(
'User 1', :attendee, nil, expected_meta, controller.request
).and_return(expected_url)
}
before(:each) {
post :join, id: room.to_param, format: :json, name: 'User 1', key: room.moderator_key,
Expand Down Expand Up @@ -489,7 +496,9 @@
}

before {
room.should_receive(:parameterized_join_url).with('User 1', :guest, nil, {}).and_return(expected_url)
room.should_receive(:parameterized_join_url).with(
'User 1', :guest, nil, {}, controller.request
).and_return(expected_url)
}
before(:each) { post :join, id: room.to_param, format: :json, name: 'User 1' }
it { JSON.parse(response.body)['data']['id'].should eql(expected_url) }
Expand Down
14 changes: 7 additions & 7 deletions spec/lib/bigbluebutton_rails/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@

context 'for a mobile device' do
before do
@browser.stub(:mobile?).and_return(true)
@browser.stub(:tablet?).and_return(false)
@browser.stub_chain(:device, :mobile?).and_return(true)
@browser.stub_chain(:device, :tablet?).and_return(false)
end
it { BigbluebuttonRails.use_mobile_client?(@browser).should be(true) }
end

context 'for a tablet' do
before do
@browser.stub(:mobile?).and_return(false)
@browser.stub(:tablet?).and_return(true)
@browser.stub_chain(:device, :mobile?).and_return(false)
@browser.stub_chain(:device, :tablet?).and_return(true)
end
it { BigbluebuttonRails.use_mobile_client?(@browser).should be(true) }
end

context 'not a mobile device nor tablet' do
before do
@browser.stub(:mobile?).and_return(false)
@browser.stub(:tablet?).and_return(false)
@browser.stub_chain(:device, :mobile?).and_return(false)
@browser.stub_chain(:device, :tablet?).and_return(false)
end
it { BigbluebuttonRails.use_mobile_client?(@browser).should be(false) }
end

# some user-agents where errors happened in the past
context 'user-agents' do
it {
browser = Browser.new(ua: 'Mozilla/5.0 (iPad; CPU OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4', accept_language: 'en-us')
browser = Browser.new('Mozilla/5.0 (iPad; CPU OS 8_1_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B466 Safari/600.1.4')
BigbluebuttonRails.use_mobile_client?(browser).should be(true)
}
end
Expand Down
27 changes: 15 additions & 12 deletions spec/models/bigbluebutton_room_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,7 @@
let(:username) { Forgery(:name).full_name }
let(:role) { :attendee }
let(:id) { 'fake-user-id' }
let(:request) { double(ActionDispatch::Request) }

context "sets a config token" do
context "when it exists" do
Expand Down Expand Up @@ -1139,23 +1140,23 @@
let(:user) { 'any user' }
before {
proc = double(Proc)
proc.should_receive(:call).with(room, user, {username: username, role: role} )
proc.should_receive(:call).with(room, user, request)
BigbluebuttonRails.configuration.should_receive(:get_join_options).and_return(proc)
room.stub(:fetch_new_token).and_return(nil)
room.stub(:join_url)
}
it { room.parameterized_join_url(username, role, nil, {}, user) }
it { room.parameterized_join_url(username, role, nil, {}, user, request) }
end

context "if the user is not passed in the arguments" do
before {
proc = double(Proc)
proc.should_receive(:call).with(room, nil, {username: username, role: role} )
proc.should_receive(:call).with(room, {username: username, role: role}, request)
BigbluebuttonRails.configuration.should_receive(:get_join_options).and_return(proc)
room.stub(:fetch_new_token).and_return(nil)
room.stub(:join_url)
}
it { room.parameterized_join_url(username, role, nil, {}, nil) }
it { room.parameterized_join_url(username, role, nil, {}, nil, request) }
end
end
end
Expand Down Expand Up @@ -1408,7 +1409,12 @@
describe "#create_meeting" do
let(:room) { FactoryGirl.create(:bigbluebutton_room) }
let(:user) { FactoryGirl.build(:user) }
before { room.should_receive(:fetch_is_running?) }
let(:request) { double(ActionDispatch::Request) }
before {
request.stub(:protocol).and_return("HTTP://")
request.stub(:host_with_port).and_return("test.com:80")
room.should_receive(:fetch_is_running?)
}

context "when the conference is running" do
before {
Expand All @@ -1421,28 +1427,25 @@
context "when the conference is not running" do
before {
room.should_receive(:is_running?).and_return(false)
room.should_receive(:send_create).with(user)
room.should_receive(:send_create).with(user, request)
}
subject { room.create_meeting(user) }
subject { room.create_meeting(user, request) }
it { should be(true) }
end

# use to call end before creating a meeting in previous versions
context "when the conference is not running doesn't call end" do
before {
room.should_receive(:is_running?).and_return(false)
room.should_receive(:send_create).with(user)
room.should_receive(:send_create).with(user, request)
room.should_not_receive(:send_end)
}
subject { room.create_meeting(user) }
subject { room.create_meeting(user, request) }
it { should be(true) }
end

context "when the parameter 'request' is informed" do
let(:request) { double(ActionDispatch::Request) }
before {
request.stub(:protocol).and_return("HTTP://")
request.stub(:host_with_port).and_return("test.com:80")
room.should_receive(:add_domain_to_logout_url).with("HTTP://", "test.com:80")
room.should_receive(:is_running?).and_return(false)
room.should_receive(:send_create)
Expand Down