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
04:17
created

RoomsController.update()   A

Complexity

Conditions 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
c 0
b 0
f 0
dl 0
loc 16
rs 9.1333
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
    room_uid = params[:join_room][:url].split('/').last
147
148
    begin
149
      @room = Room.find_by(uid: room_uid)
150
    rescue ActiveRecord::RecordNotFound
151
      return redirect_to current_user.main_room, alert: I18n.t("room.no_room.invalid_room_uid")
152
    end
153
154
    return redirect_to current_user.main_room, alert: I18n.t("room.no_room.invalid_room_uid") if @room.nil?
155
156
    redirect_to room_path(@room)
157
  end
158
159
  # POST /:room_uid/start
160
  def start
161
    # Join the user in and start the meeting.
162
    opts = default_meeting_options
163
    opts[:user_is_moderator] = true
164
165
    # Include the user's choices for the room settings
166
    room_settings = JSON.parse(@room[:room_settings])
167
    opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"]
168
    opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]
169
170
    begin
171
      redirect_to @room.join_path(current_user.name, opts, current_user.uid)
172
    rescue BigBlueButton::BigBlueButtonException => e
173
      redirect_to room_path, alert: I18n.t(e.key.to_s.underscore, default: I18n.t("bigbluebutton_exception"))
174
    end
175
176
    # Notify users that the room has started.
177
    # Delay 5 seconds to allow for server start, although the request will retry until it succeeds.
178
    NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
179
  end
180
181
  # POST /:room_uid/update_settings
182
  def update_settings
183
    begin
184
      raise "Room name can't be blank" if room_params[:name].empty?
185
186
      @room = Room.find_by!(uid: params[:room_uid])
187
      # Update the rooms settings
188
      update_room_attributes("settings")
189
      # Update the rooms name if it has been changed
190
      update_room_attributes("name") if @room.name != room_params[:name]
191
      # Update the room's access code if it has changed
192
      update_room_attributes("access_code") if @room.access_code != room_params[:access_code]
193
    rescue StandardError
194
      flash[:alert] = I18n.t("room.update_settings_error")
195
    else
196
      flash[:success] = I18n.t("room.update_settings_success")
197
    end
198
    redirect_to room_path
199
  end
200
201
  # GET /:room_uid/logout
202
  def logout
203
    # Redirect the correct page.
204
    redirect_to @room
205
  end
206
207
  # POST /:room_uid/login
208
  def login
209
    session[:access_code] = room_params[:access_code]
210
211
    flash[:alert] = I18n.t("room.access_code_required") if session[:access_code] != @room.access_code
212
213
    redirect_to room_path(@room.uid)
214
  end
215
216
  private
217
218
  def update_room_attributes(update_type)
219
    if @room.owned_by?(current_user) && @room != current_user.main_room
220
      if update_type.eql? "name"
221
        @room.update_attributes(name: params[:room_name] || room_params[:name])
222
      elsif update_type.eql? "settings"
223
        room_settings_string = create_room_settings_string(room_params[:mute_on_join],
224
          room_params[:require_moderator_approval], room_params[:anyone_can_start])
225
        @room.update_attributes(room_settings: room_settings_string)
226
      elsif update_type.eql? "access_code"
227
        @room.update_attributes(access_code: room_params[:access_code])
228
      end
229
    end
230
  end
231
232
  def create_room_settings_string(mute_res, require_approval_res, start_res)
233
    room_settings = {}
234
    room_settings["muteOnStart"] = mute_res == "1"
235
236
    room_settings["requireModeratorApproval"] = require_approval_res == "1"
237
238
    room_settings["anyoneCanStart"] = start_res == "1"
239
240
    room_settings.to_json
241
  end
242
243
  def room_params
244
    params.require(:room).permit(:name, :auto_join, :mute_on_join, :access_code,
245
      :require_moderator_approval, :anyone_can_start)
246
  end
247
248
  # Find the room from the uid.
249
  def find_room
250
    @room = Room.find_by!(uid: params[:room_uid])
251
  end
252
253
  # Ensure the user is logged into the room they are accessing.
254
  def verify_room_ownership
255
    bring_to_room unless @room.owned_by?(current_user)
256
  end
257
258
  # Redirects a user to their room.
259
  def bring_to_room
260
    if current_user
261
      # Redirect authenticated users to their room.
262
      redirect_to room_path(current_user.main_room)
263
    else
264
      # Redirect unauthenticated users to root.
265
      redirect_to root_path
266
    end
267
  end
268
269
  def validate_accepted_terms
270
    if current_user
271
      redirect_to terms_path unless current_user.accepted_terms
272
    end
273
  end
274
275
  def validate_verified_email
276
    if current_user
277
      redirect_to account_activation_path(current_user) unless current_user.activated?
278
    end
279
  end
280
281
  def verify_room_owner_verified
282
    unless @room.owner.activated?
283
      flash[:alert] = t("room.unavailable")
284
285
      if current_user && [email protected]_by?(current_user)
286
        redirect_to current_user.main_room
287
      else
288
        redirect_to root_path
289
      end
290
    end
291
  end
292
293
  def verify_user_not_admin
294
    redirect_to admins_path if current_user && current_user&.has_role?(:super_admin)
295
  end
296
297 View Code Duplication
  def auth_required
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
298
    Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Authentication") == "true" &&
299
      current_user.nil?
300
  end
301
302 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...
303
    limit = Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
304
305
    # Does not apply to admin
306
    # 15+ option is used as unlimited
307
    return false if current_user&.has_role?(:admin) || limit == 15
308
309
    current_user.rooms.count >= limit
310
  end
311
312
  def join_room(opts)
313
    room_settings = JSON.parse(@room[:room_settings])
314
315
    if @room.running? || @room.owned_by?(current_user) || room_settings["anyoneCanStart"]
316
317
      # Determine if the user needs to join as a moderator.
318
      opts[:user_is_moderator] = @room.owned_by?(current_user) ||
319
                                 (room_settings["anyoneCanStart"] && [email protected]?)
320
321
      opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]
322
323
      if current_user
324
        redirect_to @room.join_path(current_user.name, opts, current_user.uid)
325
      else
326
        join_name = params[:join_name] || params[@room.invite_path][:join_name]
327
        redirect_to @room.join_path(join_name, opts)
328
      end
329
    else
330
      search_params = params[@room.invite_path] || params
331
      @search, @order_column, @order_direction, pub_recs =
332
        public_recordings(@room.bbb_id, @user_domain, search_params.permit(:search, :column, :direction), true)
333
334
      @pagy, @public_recordings = pagy_array(pub_recs)
335
336
      # They need to wait until the meeting begins.
337
      render :wait
338
    end
339
  end
340
end
341