app/controllers/bigbluebutton/rooms_controller.rb in bigbluebutton_rails-0.0.2 vs app/controllers/bigbluebutton/rooms_controller.rb in bigbluebutton_rails-0.0.3
- old
+ new
@@ -24,45 +24,61 @@
end
def create
@room = BigbluebuttonRoom.new(params[:bigbluebutton_room])
@room.server = @server
-
- # TODO Generate a random meeting_id everytime a room is created
- if !params[:bigbluebutton_room].has_key?(:meeting_id) or
- params[:bigbluebutton_room][:meeting_id].blank?
- @room.meeting_id = @room.name
+
+ # TODO Generate a random meetingid everytime a room is created
+ if !params[:bigbluebutton_room].has_key?(:meetingid) or
+ params[:bigbluebutton_room][:meetingid].blank?
+ @room.meetingid = @room.name
end
respond_with @room do |format|
if @room.save
format.html {
message = t('bigbluebutton_rails.rooms.notice.create.success')
- redirect_to(bigbluebutton_server_room_path(@server, @room), :notice => message)
+ params[:redir_url] ||= bigbluebutton_server_room_path(@server, @room)
+ redirect_to params[:redir_url], :notice => message
}
else
- format.html { render :action => "new" }
+ format.html {
+ unless params[:redir_url].blank?
+ message = t('bigbluebutton_rails.rooms.notice.create.failure')
+ redirect_to params[:redir_url], :error => message
+ else
+ render :action => "new"
+ end
+ }
end
end
end
def update
@room = BigbluebuttonRoom.find(params[:id])
- if !params[:bigbluebutton_room].has_key?(:meeting_id) or
- params[:bigbluebutton_room][:meeting_id].blank?
- params[:bigbluebutton_room][:meeting_id] = params[:bigbluebutton_room][:name]
+ if !params[:bigbluebutton_room].has_key?(:meetingid) or
+ params[:bigbluebutton_room][:meetingid].blank?
+ params[:bigbluebutton_room][:meetingid] = params[:bigbluebutton_room][:name]
end
respond_with @room do |format|
if @room.update_attributes(params[:bigbluebutton_room])
format.html {
message = t('bigbluebutton_rails.rooms.notice.update.success')
- redirect_to(bigbluebutton_server_room_path(@server, @room), :notice => message)
+ params[:redir_url] ||= bigbluebutton_server_room_path(@server, @room)
+ redirect_to params[:redir_url], :notice => message
}
else
- format.html { render :action => "edit" }
+ format.html {
+ unless params[:redir_url].blank?
+ message = t('bigbluebutton_rails.rooms.notice.update.failure')
+ redirect_to params[:redir_url], :error => message
+ else
+ render :action => "edit"
+ end
+ }
end
end
end
def destroy
@@ -77,57 +93,68 @@
flash[:error] = e.to_s
# TODO Better error message: "Room destroyed in DB, but not in BBB..."
end
@room.destroy
- redirect_to(bigbluebutton_server_rooms_url)
+ params[:redir_url] ||= bigbluebutton_server_rooms_url
+ redirect_to params[:redir_url]
end
+ # Used to join public rooms with a logged user.
def join
@room = BigbluebuttonRoom.find(params[:id])
+
+ # anonymous users or users without a role join through #invite
role = bigbluebutton_role(@room)
+ if bigbluebutton_user.nil? or role.nil?
+ redirect_to :action => :invite
+ else
+ join_internal(bigbluebutton_user.name, role, :join)
+ end
- begin
- @room.fetch_is_running?
+ end
- # if the current user is a moderator, create the room (if needed)
- # and join it
- if role == :moderator
- @room.send_create unless @room.is_running?
- join_url = @room.join_url(bigbluebutton_user.name, role)
- redirect_to(join_url)
+ # Used to join private rooms or to invited anonymous users (not logged)
+ def invite
+ @room = BigbluebuttonRoom.find(params[:id])
- # normal user only joins if the conference is running
- # if it's not, wait for a moderator to create the conference
+ respond_with @room do |format|
+
+ # if there's already a logged user with a role in the room, join through #join
+ unless bigbluebutton_user.nil? or bigbluebutton_role(@room).nil?
+ format.html { redirect_to :action => :join }
else
- if @room.is_running?
- join_url = @room.join_url(bigbluebutton_user.name, role)
- redirect_to(join_url)
- else
- render :action => :join_wait
- end
+ format.html
end
- rescue BigBlueButton::BigBlueButtonException => e
- flash[:error] = e.to_s
- redirect_to request.referer
end
-
end
- def join_wait
+ # Authenticates an user using name and password passed in the params from #invite
+ def auth
+ @room = BigbluebuttonRoom.find(params[:id])
+
+ # if there's a user logged, use his name instead of the name in the params
+ name = bigbluebutton_user.nil? ? params[:user][:name] : bigbluebutton_user.name
+ role = @room.user_role(params[:user])
+
+ unless role.nil? or name.nil?
+ join_internal(name, role, :invite)
+ else
+ flash[:error] = t('bigbluebutton_rails.rooms.error.auth.failure')
+ render :action => "invite", :status => :unauthorized
+ end
end
def running
@room = BigbluebuttonRoom.find(params[:id])
begin
@room.fetch_is_running?
rescue BigBlueButton::BigBlueButtonException => e
flash[:error] = e.to_s
render :json => { running: "false", error: "#{e.to_s}" }
- #redirect_to request.referer
else
render :json => { running: "#{@room.is_running?}" }
end
end
@@ -157,9 +184,39 @@
def find_server
if params.has_key?(:server_id)
@server = BigbluebuttonServer.find(params[:server_id])
else
@server = BigbluebuttonServer.first
+ end
+ end
+
+ def join_internal(username, role, wait_action)
+
+ begin
+ @room.fetch_is_running?
+
+ # if the current user is a moderator, create the room (if needed)
+ # and join it
+ if role == :moderator
+ @room.send_create unless @room.is_running?
+ join_url = @room.join_url(username, role)
+ redirect_to(join_url)
+
+ # normal user only joins if the conference is running
+ # if it's not, wait for a moderator to create the conference
+ else
+ if @room.is_running?
+ join_url = @room.join_url(username, role)
+ redirect_to(join_url)
+ else
+ flash[:error] = t('bigbluebutton_rails.rooms.error.not_running')
+ render :action => wait_action
+ end
+ end
+
+ rescue BigBlueButton::BigBlueButtonException => e
+ flash[:error] = e.to_s
+ redirect_to request.referer
end
end
end