This repository has been archived on 2021-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
greenlight/app/controllers/rooms_controller.rb

195 lines
5.3 KiB
Ruby
Raw Normal View History

2018-06-26 10:29:46 -04:00
# frozen_string_literal: true
2018-05-07 16:06:01 -04:00
2018-08-01 09:45:12 -04:00
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
#
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
#
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 3.0 of the License, or (at your option) any later
# version.
#
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
2018-06-26 10:29:46 -04:00
class RoomsController < ApplicationController
before_action :validate_accepted_terms, unless: -> { !Rails.configuration.terms }
before_action :validate_verified_email, unless: -> { !Rails.configuration.enable_email_verification }
2018-05-29 15:28:29 -04:00
before_action :find_room, except: :create
2018-06-13 13:27:29 -04:00
before_action :verify_room_ownership, except: [:create, :show, :join, :logout]
2018-05-29 15:28:29 -04:00
2018-06-12 14:36:35 -04:00
META_LISTED = "gl-listed"
# POST /
2018-05-29 15:28:29 -04:00
def create
2018-06-13 16:33:23 -04:00
redirect_to root_path unless current_user
2018-06-26 10:29:46 -04:00
2018-06-13 13:27:29 -04:00
@room = Room.new(name: room_params[:name])
@room.owner = current_user
2018-05-29 15:28:29 -04:00
2018-06-13 13:27:29 -04:00
if @room.save
2018-05-29 16:51:18 -04:00
if room_params[:auto_join] == "1"
2018-06-13 13:27:29 -04:00
start
2018-05-29 16:51:18 -04:00
else
2018-06-13 13:27:29 -04:00
redirect_to @room
2018-05-29 16:51:18 -04:00
end
2018-05-29 15:28:29 -04:00
end
end
# GET /:room_uid
2018-05-23 16:13:24 -04:00
def show
2018-06-07 15:52:42 -04:00
if current_user && @room.owned_by?(current_user)
@recordings = @room.recordings
2018-06-26 10:29:46 -04:00
@is_running = @room.running?
2018-05-15 11:43:59 -04:00
else
2018-06-07 15:52:42 -04:00
render :join
2018-05-15 11:43:59 -04:00
end
end
# POST /:room_uid
2018-05-29 17:08:38 -04:00
def join
opts = default_meeting_options
2018-06-01 17:28:39 -04:00
2018-06-26 16:20:04 -04:00
unless @room.owned_by?(current_user)
# Assign join name if passed.
if params[@room.invite_path]
@join_name = params[@room.invite_path][:join_name]
elsif !params[:join_name]
# Join name not passed.
return
end
2018-06-07 15:52:42 -04:00
end
2018-06-26 10:29:46 -04:00
if @room.running?
2018-06-26 16:20:04 -04:00
# Determine if the user needs to join as a moderator.
opts[:user_is_moderator] = @room.owned_by?(current_user)
2018-06-07 15:52:42 -04:00
if current_user
2018-06-11 13:05:54 -04:00
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
else
2018-06-13 13:27:29 -04:00
join_name = params[:join_name] || params[@room.invite_path][:join_name]
2018-06-07 15:52:42 -04:00
redirect_to @room.join_path(join_name, opts)
2018-06-04 15:58:59 -04:00
end
else
# They need to wait until the meeting begins.
2018-06-07 15:52:42 -04:00
render :wait
2018-05-29 17:08:38 -04:00
end
end
# DELETE /:room_uid
2018-05-29 16:51:18 -04:00
def destroy
2018-06-01 17:28:39 -04:00
# Don't delete the users home room.
2018-07-04 15:20:12 -04:00
@room.destroy if @room.owned_by?(current_user) && @room != current_user.main_room
2018-05-29 16:51:18 -04:00
2018-05-31 15:04:18 -04:00
redirect_to current_user.main_room
2018-05-29 16:51:18 -04:00
end
# POST /:room_uid/start
2018-05-15 11:43:59 -04:00
def start
# Join the user in and start the meeting.
opts = default_meeting_options
opts[:user_is_moderator] = true
2018-06-11 13:05:54 -04:00
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
2018-05-14 14:28:18 -04:00
2018-06-07 15:52:42 -04:00
# Notify users that the room has started.
# Delay 5 seconds to allow for server start, although the request will retry until it succeeds.
NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
2018-05-14 14:28:18 -04:00
end
# GET /:room_uid/logout
2018-05-15 11:43:59 -04:00
def logout
2018-06-08 16:59:09 -04:00
# Redirect the correct page.
redirect_to @room
2018-05-15 11:43:59 -04:00
end
# POST /:room_uid/:record_id
2018-06-11 17:32:08 -04:00
def update_recording
2018-06-12 14:36:35 -04:00
meta = {
2018-06-26 10:29:46 -04:00
"meta_#{META_LISTED}" => (params[:state] == "public"),
2018-06-12 14:36:35 -04:00
}
2018-06-12 17:28:02 -04:00
2018-06-12 14:36:35 -04:00
res = @room.update_recording(params[:record_id], meta)
redirect_to @room if res[:updated]
2018-06-11 17:32:08 -04:00
end
# DELETE /:room_uid/:record_id
2018-06-01 11:55:52 -04:00
def delete_recording
@room.delete_recording(params[:record_id])
redirect_to current_user.main_room
end
# Helper for converting BigBlueButton dates into the desired format.
def recording_date(date)
date.strftime("%B #{date.day.ordinalize}, %Y.")
end
helper_method :recording_date
# Helper for converting BigBlueButton dates into a nice length string.
def recording_length(playbacks)
# Stats format currently doesn't support length.
2018-08-20 14:53:14 -04:00
valid_playbacks = playbacks.reject { |p| p[:type] == "statistics" }
return "0 min" if valid_playbacks.empty?
2018-08-20 14:53:14 -04:00
len = valid_playbacks.first[:length]
2018-06-01 11:55:52 -04:00
if len > 60
2018-07-30 11:48:11 -04:00
"#{(len / 60).round} hrs"
2018-06-26 10:29:46 -04:00
elsif len == 0
"< 1 min"
2018-06-01 11:55:52 -04:00
else
2018-06-26 10:29:46 -04:00
"#{len} min"
2018-06-01 11:55:52 -04:00
end
end
helper_method :recording_length
# Prevents single images from erroring when not passed as an array.
def safe_recording_images(images)
Array.wrap(images)
end
helper_method :safe_recording_images
2018-05-14 14:28:18 -04:00
private
2018-05-29 15:28:29 -04:00
def room_params
params.require(:room).permit(:name, :auto_join)
end
2018-05-14 14:28:18 -04:00
# Find the room from the uid.
def find_room
2018-06-08 16:59:09 -04:00
@room = Room.find_by!(uid: params[:room_uid])
2018-05-14 14:28:18 -04:00
end
2018-05-15 11:43:59 -04:00
# Ensure the user is logged into the room they are accessing.
def verify_room_ownership
2018-06-26 10:29:46 -04:00
bring_to_room unless @room.owned_by?(current_user)
2018-05-15 11:43:59 -04:00
end
# Redirects a user to their room.
def bring_to_room
if current_user
# Redirect authenticated users to their room.
2018-06-28 16:55:56 -04:00
redirect_to room_path(current_user.main_room)
2018-05-15 11:43:59 -04:00
else
# Redirect unauthenticated users to root.
redirect_to root_path
end
2018-05-07 16:06:01 -04:00
end
def validate_accepted_terms
if current_user
redirect_to terms_path unless current_user.accepted_terms
end
end
def validate_verified_email
if current_user
redirect_to resend_path unless current_user.email_verified
end
end
2018-05-22 16:58:11 -04:00
end