GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#709)
by
unknown
06:22 queued 36s
created

RoomsController.show()   A

Complexity

Conditions 4

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
dl 0
loc 31
rs 9.1359
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 RecordingsHelper
21
  include Pagy::Backend
22
  include Recorder
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
    redirect_to(root_path) && return unless current_user
36
37
    return redirect_to current_user.main_room, flash: { alert: I18n.t("room.room_limit") } if room_limit_exceeded
38
39
    @room = Room.new(name: room_params[:name], access_code: room_params[:access_code])
40
    @room.owner = current_user
41
    @room.room_settings = create_room_settings_string(room_params[:mute_on_join],
42
      room_params[:require_moderator_approval], room_params[:anyone_can_start])
43
44
    if @room.save
45
      if room_params[:auto_join] == "1"
46
        start
47
      else
48
        flash[:success] = I18n.t("room.create_room_success")
49
        redirect_to @room
50
      end
51
    else
52
      flash[:alert] = I18n.t("room.create_room_error")
53
      redirect_to current_user.main_room
54
    end
55
  end
56
57
  # GET /:room_uid
58
  def show
59
    @is_running = @room.running?
60
    @anyone_can_start = JSON.parse(@room[:room_settings])["anyoneCanStart"]
61
62
    if current_user && @room.owned_by?(current_user)
63
      if current_user.highest_priority_role.can_create_rooms
64
        @search, @order_column, @order_direction, recs =
65
          recordings(@room.bbb_id, @user_domain, params.permit(:search, :column, :direction), true)
66
67
        @pagy, @recordings = pagy_array(recs)
68
      else
69
        render :cant_create_rooms
70
      end
71
    else
72
      # Get users name
73
      @name = if current_user
74
        current_user.name
75
      elsif cookies.encrypted[:greenlight_name]
76
        cookies.encrypted[:greenlight_name]
77
      else
78
        ""
79
      end
80
81
      @search, @order_column, @order_direction, pub_recs =
82
        public_recordings(@room.bbb_id, @user_domain, params.permit(:search, :column, :direction), true)
83
84
      @pagy, @public_recordings = pagy_array(pub_recs)
85
86
      render :join
87
    end
88
  end
89
90
  # PATCH /:room_uid
91
  def update
92
    if params[:setting] == "rename_block"
93
      @room = Room.find_by!(uid: params[:room_block_uid])
94
      update_room_attributes("name")
95
    elsif params[:setting] == "rename_header"
96
      update_room_attributes("name")
97
    elsif params[:setting] == "rename_recording"
98
      @room.update_recording(params[:record_id], "meta_name" => params[:record_name])
99
    end
100
101
    if request.referrer
102
      redirect_to request.referrer
103
    else
104
      redirect_to room_path
105
    end
106
  end
107
108
  # POST /:room_uid
109
  def join
110
    return redirect_to root_path,
111
      flash: { alert: I18n.t("administrator.site_settings.authentication.user-info") } if auth_required
112
113
    opts = default_meeting_options
114
    unless @room.owned_by?(current_user)
115
      # Don't allow users to join unless they have a valid access code or the room doesn't
116
      # have an access code
117
      if @room.access_code && [email protected]_code.empty? && @room.access_code != session[:access_code]
118
        return redirect_to room_path(room_uid: params[:room_uid]), flash: { alert: I18n.t("room.access_code_required") }
119
      end
120
121
      # Assign join name if passed.
122
      if params[@room.invite_path]
123
        @join_name = params[@room.invite_path][:join_name]
124
      elsif !params[:join_name]
125
        # Join name not passed.
126
        return
127
      end
128
    end
129
130
    # create or update cookie with join name
131
    cookies.encrypted[:greenlight_name] = @join_name unless cookies.encrypted[:greenlight_name] == @join_name
132
133
    join_room(opts)
134
  end
135
136
  # DELETE /:room_uid
137
  def destroy
138
    # Don't delete the users home room.
139
    @room.destroy if @room.owned_by?(current_user) && @room != current_user.main_room
140
141
    redirect_to current_user.main_room
142
  end
143
144
  # POST room/join
145
  def join_specific_room
146
    parsed_url = params[:join_room][:url].split('/')
147
148
    room_uid = parsed_url[parsed_url.length - 1]
149
150
    begin
151
      @room = Room.find_by(uid: room_uid)
152
    rescue ActiveRecord::RecordNotFound
153
      flash[:alert] = I18n.t("room.no_room.invalid_room_uid")
154
      return redirect_to room_path(current_user.main_room)
155
    end
156
157
    if @room.nil?
158
      flash[:alert] = I18n.t("room.no_room.invalid_room_uid")
159
      return redirect_to room_path(current_user.main_room)
160
    end
161
162
    redirect_to room_path(@room)
163
  end
164
165
  # POST /:room_uid/start
166
  def start
167
    # Join the user in and start the meeting.
168
    opts = default_meeting_options
169
    opts[:user_is_moderator] = true
170
171
    # Include the user's choices for the room settings
172
    room_settings = JSON.parse(@room[:room_settings])
173
    opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"]
174
    opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]
175
176
    begin
177
      redirect_to @room.join_path(current_user.name, opts, current_user.uid)
178
    rescue BigBlueButton::BigBlueButtonException => e
179
      redirect_to room_path, alert: I18n.t(e.key.to_s.underscore, default: I18n.t("bigbluebutton_exception"))
180
    end
181
182
    # Notify users that the room has started.
183
    # Delay 5 seconds to allow for server start, although the request will retry until it succeeds.
184
    NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
185
  end
186
187
  # POST /:room_uid/update_settings
188
  def update_settings
189
    begin
190
      raise "Room name can't be blank" if room_params[:name].empty?
191
192
      @room = Room.find_by!(uid: params[:room_uid])
193
      # Update the rooms settings
194
      update_room_attributes("settings")
195
      # Update the rooms name if it has been changed
196
      update_room_attributes("name") if @room.name != room_params[:name]
197
      # Update the room's access code if it has changed
198
      update_room_attributes("access_code") if @room.access_code != room_params[:access_code]
199
    rescue StandardError
200
      flash[:alert] = I18n.t("room.update_settings_error")
201
    else
202
      flash[:success] = I18n.t("room.update_settings_success")
203
    end
204
    redirect_to room_path
205
  end
206
207
  # GET /:room_uid/logout
208
  def logout
209
    # Redirect the correct page.
210
    redirect_to @room
211
  end
212
213
  # POST /:room_uid/login
214
  def login
215
    session[:access_code] = room_params[:access_code]
216
217
    flash[:alert] = I18n.t("room.access_code_required") if session[:access_code] != @room.access_code
218
219
    redirect_to room_path(@room.uid)
220
  end
221
222
  private
223
224
  def update_room_attributes(update_type)
225
    if @room.owned_by?(current_user) && @room != current_user.main_room
226
      if update_type.eql? "name"
227
        @room.update_attributes(name: params[:room_name] || room_params[:name])
228
      elsif update_type.eql? "settings"
229
        room_settings_string = create_room_settings_string(room_params[:mute_on_join],
230
          room_params[:require_moderator_approval], room_params[:anyone_can_start])
231
        @room.update_attributes(room_settings: room_settings_string)
232
      elsif update_type.eql? "access_code"
233
        @room.update_attributes(access_code: room_params[:access_code])
234
      end
235
    end
236
  end
237
238
  def create_room_settings_string(mute_res, require_approval_res, start_res)
239
    room_settings = {}
240
    room_settings["muteOnStart"] = mute_res == "1"
241
242
    room_settings["requireModeratorApproval"] = require_approval_res == "1"
243
244
    room_settings["anyoneCanStart"] = start_res == "1"
245
246
    room_settings.to_json
247
  end
248
249
  def room_params
250
    params.require(:room).permit(:name, :auto_join, :mute_on_join, :access_code,
251
      :require_moderator_approval, :anyone_can_start)
252
  end
253
254
  # Find the room from the uid.
255
  def find_room
256
    @room = Room.find_by!(uid: params[:room_uid])
257
  end
258
259
  # Ensure the user is logged into the room they are accessing.
260
  def verify_room_ownership
261
    bring_to_room unless @room.owned_by?(current_user)
262
  end
263
264
  # Redirects a user to their room.
265
  def bring_to_room
266
    if current_user
267
      # Redirect authenticated users to their room.
268
      redirect_to room_path(current_user.main_room)
269
    else
270
      # Redirect unauthenticated users to root.
271
      redirect_to root_path
272
    end
273
  end
274
275
  def validate_accepted_terms
276
    if current_user
277
      redirect_to terms_path unless current_user.accepted_terms
278
    end
279
  end
280
281
  def validate_verified_email
282
    if current_user
283
      redirect_to account_activation_path(current_user) unless current_user.activated?
284
    end
285
  end
286
287
  def verify_room_owner_verified
288
    unless @room.owner.activated?
289
      flash[:alert] = t("room.unavailable")
290
291
      if current_user && [email protected]_by?(current_user)
292
        redirect_to current_user.main_room
293
      else
294
        redirect_to root_path
295
      end
296
    end
297
  end
298
299
  def verify_user_not_admin
300
    redirect_to admins_path if current_user && current_user&.has_role?(:super_admin)
301
  end
302
303 View Code Duplication
  def auth_required
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
304
    Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true" &&
305
      current_user.nil?
306
  end
307
308 View Code Duplication
  def room_limit_exceeded
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
309
    limit = Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
310
311
    # Does not apply to admin
312
    # 15+ option is used as unlimited
313
    return false if current_user&.has_role?(:admin) || limit == 15
314
315
    current_user.rooms.count >= limit
316
  end
317
318
  def join_room(opts)
319
    room_settings = JSON.parse(@room[:room_settings])
320
321
    if @room.running? || @room.owned_by?(current_user) || room_settings["anyoneCanStart"]
322
323
      # Determine if the user needs to join as a moderator.
324
      opts[:user_is_moderator] = @room.owned_by?(current_user) ||
325
                                 (room_settings["anyoneCanStart"] && [email protected]?)
326
327
      opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]
328
329
      if current_user
330
        redirect_to @room.join_path(current_user.name, opts, current_user.uid)
331
      else
332
        join_name = params[:join_name] || params[@room.invite_path][:join_name]
333
        redirect_to @room.join_path(join_name, opts)
334
      end
335
    else
336
      search_params = params[@room.invite_path] || params
337
      @search, @order_column, @order_direction, pub_recs =
338
        public_recordings(@room.bbb_id, @user_domain, search_params.permit(:search, :column, :direction), true)
339
340
      @pagy, @public_recordings = pagy_array(pub_recs)
341
342
      # They need to wait until the meeting begins.
343
      render :wait
344
    end
345
  end
346
end
347