1
|
|
|
# frozen_string_literal: true |
2
|
|
|
|
3
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. |
4
|
|
|
# |
5
|
|
|
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below). |
6
|
|
|
# |
7
|
|
|
# This program is free software; you can redistribute it and/or modify it under the |
8
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software |
9
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later |
10
|
|
|
# version. |
11
|
|
|
# |
12
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY |
13
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
14
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU Lesser General Public License along |
17
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
class RoomsController < ApplicationController |
20
|
|
|
include Pagy::Backend |
21
|
|
|
include Recorder |
22
|
|
|
include Joiner |
23
|
|
|
|
24
|
|
|
before_action :validate_accepted_terms, unless: -> { !Rails.configuration.terms } |
25
|
|
|
before_action :validate_verified_email, except: [:show, :join], |
26
|
|
|
unless: -> { !Rails.configuration.enable_email_verification } |
27
|
|
|
before_action :find_room, except: [:create, :join_specific_room] |
28
|
|
|
before_action :verify_room_ownership, except: [:create, :show, :join, :logout, :login, :join_specific_room] |
29
|
|
|
before_action :verify_room_owner_verified, only: [:show, :join], |
30
|
|
|
unless: -> { !Rails.configuration.enable_email_verification } |
31
|
|
|
before_action :verify_user_not_admin, only: [:show] |
32
|
|
|
|
33
|
|
|
# POST / |
34
|
|
|
def create |
35
|
|
|
# Return to root if user is not signed in |
36
|
|
|
return redirect_to root_path unless current_user |
37
|
|
|
|
38
|
|
|
# Check if the user has not exceeded the room limit |
39
|
|
|
return redirect_to current_user.main_room, flash: { alert: I18n.t("room.room_limit") } if room_limit_exceeded |
40
|
|
|
|
41
|
|
|
# Create room |
42
|
|
|
@room = Room.new(name: room_params[:name], access_code: room_params[:access_code]) |
43
|
|
|
@room.owner = current_user |
44
|
|
|
@room.room_settings = create_room_settings_string(room_params) |
45
|
|
|
|
46
|
|
|
# Save the room |
47
|
|
|
if @room.save |
48
|
|
|
logger.info "Support: #{current_user.email} has created a new room #{@room.uid}." |
49
|
|
|
|
50
|
|
|
# Redirect to room is auto join was not turned on |
51
|
|
|
return redirect_to @room, |
52
|
|
|
flash: { success: I18n.t("room.create_room_success") } unless room_params[:auto_join] == "1" |
53
|
|
|
|
54
|
|
|
# Start the room if auto join was turned on |
55
|
|
|
start |
56
|
|
|
else |
57
|
|
|
redirect_to current_user.main_room, flash: { alert: I18n.t("room.create_room_error") } |
58
|
|
|
end |
59
|
|
|
end |
60
|
|
|
|
61
|
|
|
# GET /:room_uid |
62
|
|
|
def show |
63
|
|
|
@anyone_can_start = JSON.parse(@room[:room_settings])["anyoneCanStart"] |
64
|
|
|
@room_running = room_running?(@room.bbb_id) |
65
|
|
|
|
66
|
|
|
# If its the current user's room |
67
|
|
|
if current_user && @room.owned_by?(current_user) |
68
|
|
|
if current_user.highest_priority_role.can_create_rooms |
69
|
|
|
# User is allowed to have rooms |
70
|
|
|
@search, @order_column, @order_direction, recs = |
71
|
|
|
recordings(@room.bbb_id, params.permit(:search, :column, :direction), true) |
72
|
|
|
|
73
|
|
|
@pagy, @recordings = pagy_array(recs) |
74
|
|
|
else |
75
|
|
|
# Render view for users that cant create rooms |
76
|
|
|
@recent_rooms = Room.where(id: cookies.encrypted["#{current_user.uid}_recently_joined_rooms"]) |
77
|
|
|
render :cant_create_rooms |
78
|
|
|
end |
79
|
|
|
else |
80
|
|
|
show_user_join |
81
|
|
|
end |
82
|
|
|
end |
83
|
|
|
|
84
|
|
|
# PATCH /:room_uid |
85
|
|
|
def update |
86
|
|
|
if params[:setting] == "rename_header" |
87
|
|
|
update_room_attributes("name") |
88
|
|
|
elsif params[:setting] == "rename_recording" |
89
|
|
|
update_recording(params[:record_id], "meta_name" => params[:record_name]) |
90
|
|
|
end |
91
|
|
|
|
92
|
|
|
redirect_back fallback_location: room_path |
93
|
|
|
end |
94
|
|
|
|
95
|
|
|
# POST /:room_uid |
96
|
|
|
def join |
97
|
|
|
return redirect_to root_path, |
98
|
|
|
flash: { alert: I18n.t("administrator.site_settings.authentication.user-info") } if auth_required |
99
|
|
|
|
100
|
|
|
unless @room.owned_by?(current_user) |
101
|
|
|
# Don't allow users to join unless they have a valid access code or the room doesn't have an access code |
102
|
|
|
if @room.access_code && [email protected]_code.empty? && @room.access_code != session[:access_code] |
103
|
|
|
return redirect_to room_path(room_uid: params[:room_uid]), flash: { alert: I18n.t("room.access_code_required") } |
104
|
|
|
end |
105
|
|
|
|
106
|
|
|
# Join name not passed. |
107
|
|
|
return unless params[:join_name] |
108
|
|
|
|
109
|
|
|
# Assign join name if passed. |
110
|
|
|
@join_name = params[@room.invite_path][:join_name] if params[@room.invite_path] |
111
|
|
|
end |
112
|
|
|
|
113
|
|
|
# create or update cookie with join name |
114
|
|
|
cookies.encrypted[:greenlight_name] = @join_name unless cookies.encrypted[:greenlight_name] == @join_name |
115
|
|
|
|
116
|
|
|
save_recent_rooms |
117
|
|
|
|
118
|
|
|
logger.info "Support: #{current_user.present? ? current_user.email : @join_name} is joining room #{@room.uid}" |
119
|
|
|
join_room(default_meeting_options) |
120
|
|
|
end |
121
|
|
|
|
122
|
|
|
# DELETE /:room_uid |
123
|
|
|
def destroy |
124
|
|
|
# Don't delete the users home room. |
125
|
|
|
if @room.owned_by?(current_user) && @room != current_user.main_room |
126
|
|
|
@room.destroy |
127
|
|
|
delete_all_recordings(@room.bbb_id) |
128
|
|
|
end |
129
|
|
|
|
130
|
|
|
redirect_to current_user.main_room |
131
|
|
|
end |
132
|
|
|
|
133
|
|
|
# POST /room/join |
134
|
|
|
def join_specific_room |
135
|
|
|
room_uid = params[:join_room][:url].split('/').last |
136
|
|
|
|
137
|
|
|
begin |
138
|
|
|
@room = Room.find_by!(uid: room_uid) |
139
|
|
|
rescue ActiveRecord::RecordNotFound |
140
|
|
|
return redirect_to current_user.main_room, alert: I18n.t("room.no_room.invalid_room_uid") |
141
|
|
|
end |
142
|
|
|
|
143
|
|
|
redirect_to room_path(@room) |
144
|
|
|
end |
145
|
|
|
|
146
|
|
|
# POST /:room_uid/start |
147
|
|
|
def start |
148
|
|
|
logger.info "Support: #{current_user.email} is starting room #{@room.uid}" |
149
|
|
|
|
150
|
|
|
# Join the user in and start the meeting. |
151
|
|
|
opts = default_meeting_options |
152
|
|
|
opts[:user_is_moderator] = true |
153
|
|
|
|
154
|
|
|
# Include the user's choices for the room settings |
155
|
|
|
room_settings = JSON.parse(@room[:room_settings]) |
156
|
|
|
opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"] |
157
|
|
|
opts[:require_moderator_approval] = room_settings["requireModeratorApproval"] |
158
|
|
|
|
159
|
|
|
begin |
160
|
|
|
redirect_to join_path(@room, current_user.name, opts, current_user.uid) |
161
|
|
|
rescue BigBlueButton::BigBlueButtonException => e |
162
|
|
|
logger.error("Support: #{@room.uid} start failed: #{e}") |
163
|
|
|
|
164
|
|
|
redirect_to room_path, alert: I18n.t(e.key.to_s.underscore, default: I18n.t("bigbluebutton_exception")) |
165
|
|
|
end |
166
|
|
|
|
167
|
|
|
# Notify users that the room has started. |
168
|
|
|
# Delay 5 seconds to allow for server start, although the request will retry until it succeeds. |
169
|
|
|
NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room) |
170
|
|
|
end |
171
|
|
|
|
172
|
|
|
# POST /:room_uid/update_settings |
173
|
|
|
def update_settings |
174
|
|
|
begin |
175
|
|
|
raise "Room name can't be blank" if room_params[:name].empty? |
176
|
|
|
|
177
|
|
|
@room = Room.find_by!(uid: params[:room_uid]) |
178
|
|
|
# Update the rooms settings |
179
|
|
|
update_room_attributes("settings") |
180
|
|
|
# Update the rooms name if it has been changed |
181
|
|
|
update_room_attributes("name") if @room.name != room_params[:name] |
182
|
|
|
# Update the room's access code if it has changed |
183
|
|
|
update_room_attributes("access_code") if @room.access_code != room_params[:access_code] |
184
|
|
|
|
185
|
|
|
flash[:success] = I18n.t("room.update_settings_success") |
186
|
|
|
rescue => e |
187
|
|
|
logger.error "Support: Error in updating room settings: #{e}" |
188
|
|
|
flash[:alert] = I18n.t("room.update_settings_error") |
189
|
|
|
end |
190
|
|
|
|
191
|
|
|
redirect_to room_path |
192
|
|
|
end |
193
|
|
|
|
194
|
|
|
# GET /:room_uid/logout |
195
|
|
|
def logout |
196
|
|
|
logger.info "Support: #{current_user.present? ? current_user.email : 'Guest'} has left room #{@room.uid}" |
197
|
|
|
|
198
|
|
|
# Redirect the correct page. |
199
|
|
|
redirect_to @room |
200
|
|
|
end |
201
|
|
|
|
202
|
|
|
# POST /:room_uid/login |
203
|
|
|
def login |
204
|
|
|
session[:access_code] = room_params[:access_code] |
205
|
|
|
|
206
|
|
|
flash[:alert] = I18n.t("room.access_code_required") if session[:access_code] != @room.access_code |
207
|
|
|
|
208
|
|
|
redirect_to room_path(@room.uid) |
209
|
|
|
end |
210
|
|
|
|
211
|
|
|
private |
212
|
|
|
|
213
|
|
|
def update_room_attributes(update_type) |
214
|
|
|
if @room.owned_by?(current_user) && @room != current_user.main_room |
215
|
|
|
if update_type.eql? "name" |
216
|
|
|
@room.update_attributes(name: params[:room_name] || room_params[:name]) |
217
|
|
|
elsif update_type.eql? "settings" |
218
|
|
|
room_settings_string = create_room_settings_string(room_params) |
219
|
|
|
@room.update_attributes(room_settings: room_settings_string) |
220
|
|
|
elsif update_type.eql? "access_code" |
221
|
|
|
@room.update_attributes(access_code: room_params[:access_code]) |
222
|
|
|
end |
223
|
|
|
end |
224
|
|
|
end |
225
|
|
|
|
226
|
|
|
def create_room_settings_string(options) |
227
|
|
|
room_settings = {} |
228
|
|
|
room_settings["muteOnStart"] = options[:mute_on_join] == "1" |
229
|
|
|
|
230
|
|
|
room_settings["requireModeratorApproval"] = options[:require_moderator_approval] == "1" |
231
|
|
|
|
232
|
|
|
room_settings["anyoneCanStart"] = options[:anyone_can_start] == "1" |
233
|
|
|
|
234
|
|
|
room_settings["joinModerator"] = options[:all_join_moderator] == "1" |
235
|
|
|
|
236
|
|
|
room_settings.to_json |
237
|
|
|
end |
238
|
|
|
|
239
|
|
|
def room_params |
240
|
|
|
params.require(:room).permit(:name, :auto_join, :mute_on_join, :access_code, |
241
|
|
|
:require_moderator_approval, :anyone_can_start, :all_join_moderator) |
242
|
|
|
end |
243
|
|
|
|
244
|
|
|
# Find the room from the uid. |
245
|
|
|
def find_room |
246
|
|
|
@room = Room.find_by!(uid: params[:room_uid]) |
247
|
|
|
end |
248
|
|
|
|
249
|
|
|
# Ensure the user is logged into the room they are accessing. |
250
|
|
|
def verify_room_ownership |
251
|
|
|
bring_to_room unless @room.owned_by?(current_user) |
252
|
|
|
end |
253
|
|
|
|
254
|
|
|
# Redirects a user to their room. |
255
|
|
|
def bring_to_room |
256
|
|
|
if current_user |
257
|
|
|
# Redirect authenticated users to their room. |
258
|
|
|
redirect_to room_path(current_user.main_room) |
259
|
|
|
else |
260
|
|
|
# Redirect unauthenticated users to root. |
261
|
|
|
redirect_to root_path |
262
|
|
|
end |
263
|
|
|
end |
264
|
|
|
|
265
|
|
|
def validate_accepted_terms |
266
|
|
|
redirect_to terms_path if current_user && !current_user&.accepted_terms |
267
|
|
|
end |
268
|
|
|
|
269
|
|
|
def validate_verified_email |
270
|
|
|
redirect_to account_activation_path(current_user) if current_user && !current_user&.activated? |
271
|
|
|
end |
272
|
|
|
|
273
|
|
|
def verify_room_owner_verified |
274
|
|
|
unless @room.owner.activated? |
275
|
|
|
flash[:alert] = t("room.unavailable") |
276
|
|
|
|
277
|
|
|
if current_user && [email protected]_by?(current_user) |
278
|
|
|
redirect_to current_user.main_room |
279
|
|
|
else |
280
|
|
|
redirect_to root_path |
281
|
|
|
end |
282
|
|
|
end |
283
|
|
|
end |
284
|
|
|
|
285
|
|
|
def verify_user_not_admin |
286
|
|
|
redirect_to admins_path if current_user&.has_role?(:super_admin) |
287
|
|
|
end |
288
|
|
|
|
289
|
|
|
def auth_required |
290
|
|
|
@settings.get_value("Room Authentication") == "true" && current_user.nil? |
291
|
|
|
end |
292
|
|
|
|
293
|
|
|
def room_limit_exceeded |
294
|
|
|
limit = @settings.get_value("Room Limit").to_i |
295
|
|
|
|
296
|
|
|
# Does not apply to admin or users that aren't signed in |
297
|
|
|
# 15+ option is used as unlimited |
298
|
|
|
return false if current_user&.has_role?(:admin) || limit == 15 |
299
|
|
|
|
300
|
|
|
current_user.rooms.length >= limit |
301
|
|
|
end |
302
|
|
|
helper_method :room_limit_exceeded |
303
|
|
|
end |
304
|
|
|
|