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