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
Push — v2.4-alpha ( b491cb...3e5a77 )
by Ahmad
04:54
created

RoomsController   D

Complexity

Total Complexity 59

Size/Duplication

Total Lines 245
Duplicated Lines 0 %

Importance

Changes 8
Bugs 3 Features 0
Metric Value
c 8
b 3
f 0
dl 0
loc 245
rs 4.08
wmc 59

How to fix   Complexity   

Complex Class

Complex classes like RoomsController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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, only: [:destroy, :start, :update_settings]
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 and redirect if it fails
47
    return redirect_to current_user.main_room, flash: { alert: I18n.t("room.create_room_error") } unless @room.save
48
49
    logger.info "Support: #{current_user.email} has created a new room #{@room.uid}."
50
51
    # Redirect to room is auto join was not turned on
52
    return redirect_to @room,
53
      flash: { success: I18n.t("room.create_room_success") } unless room_params[:auto_join] == "1"
54
55
    # Start the room if auto join was turned on
56
    start
57
  end
58
59
  # GET /:room_uid
60
  def show
61
    @anyone_can_start = JSON.parse(@room[:room_settings])["anyoneCanStart"]
62
    @room_running = room_running?(@room.bbb_id)
63
64
    # If its the current user's room
65
    if current_user && @room.owned_by?(current_user)
66
      if current_user.highest_priority_role.get_permission("can_create_rooms")
67
        # User is allowed to have rooms
68
        @search, @order_column, @order_direction, recs =
69
          recordings(@room.bbb_id, params.permit(:search, :column, :direction), true)
70
71
        @pagy, @recordings = pagy_array(recs)
72
      else
73
        # Render view for users that cant create rooms
74
        @recent_rooms = Room.where(id: cookies.encrypted["#{current_user.uid}_recently_joined_rooms"])
75
        render :cant_create_rooms
76
      end
77
    else
78
<<<<<<< HEAD
79
      return redirect_to root_path, flash: { alert: I18n.t("room.invalid_provider") } if incorrect_user_domain
80
81
      # Get users name
82
      @name = if current_user
83
        current_user.name
84
      elsif cookies.encrypted[:greenlight_name]
85
        cookies.encrypted[:greenlight_name]
86
      else
87
        ""
88
      end
89
90
      @search, @order_column, @order_direction, pub_recs =
91
        public_recordings(@room.bbb_id, params.permit(:search, :column, :direction), true)
92
93
      @pagy, @public_recordings = pagy_array(pub_recs)
94
95
      render :join
96
    end
97
  end
98
99
  # PATCH /:room_uid
100
  def update
101
    if params[:setting] == "rename_header"
102
      update_room_attributes("name")
103
    elsif params[:setting] == "rename_recording"
104
      update_recording(params[:record_id], "meta_name" => params[:record_name])
105
=======
106
      show_user_join
107
>>>>>>> GRN2-196: Fixed issues that scrutinizer is complaining about (#765)
108
    end
109
  end
110
111
  # POST /:room_uid
112
  def join
113
    return redirect_to root_path,
114
      flash: { alert: I18n.t("administrator.site_settings.authentication.user-info") } if auth_required
115
116
    unless @room.owned_by?(current_user)
117
      # Don't allow users to join unless they have a valid access code or the room doesn't have an access code
118
      if @room.access_code && [email protected]_code.empty? && @room.access_code != session[:access_code]
119
        return redirect_to room_path(room_uid: params[:room_uid]), flash: { alert: I18n.t("room.access_code_required") }
120
      end
121
122
      # Assign join name if passed.
123
      if params[@room.invite_path]
124
        @join_name = params[@room.invite_path][:join_name]
125
      elsif !params[:join_name]
126
        # Join name not passed.
127
        return redirect_to root_path
128
      end
129
    end
130
131
    # create or update cookie with join name
132
    cookies.encrypted[:greenlight_name] = @join_name unless cookies.encrypted[:greenlight_name] == @join_name
133
134
    save_recent_rooms
135
136
    logger.info "Support: #{current_user.present? ? current_user.email : @join_name} is joining room #{@room.uid}"
137
    join_room(default_meeting_options)
138
  end
139
140
  # DELETE /:room_uid
141
  def destroy
142
    # Don't delete the users home room.
143
    @room.destroy if @room.owned_by?(current_user) && @room != current_user.main_room
144
145
    redirect_to current_user.main_room
146
  end
147
148
  # POST /room/join
149
  def join_specific_room
150
    room_uid = params[:join_room][:url].split('/').last
151
152
    begin
153
      @room = Room.find_by!(uid: room_uid)
154
    rescue ActiveRecord::RecordNotFound
155
      return redirect_to current_user.main_room, alert: I18n.t("room.no_room.invalid_room_uid")
156
    end
157
158
    redirect_to room_path(@room)
159
  end
160
161
  # POST /:room_uid/start
162
  def start
163
    logger.info "Support: #{current_user.email} is starting room #{@room.uid}"
164
165
    # Join the user in and start the meeting.
166
    opts = default_meeting_options
167
    opts[:user_is_moderator] = true
168
169
    # Include the user's choices for the room settings
170
    room_settings = JSON.parse(@room[:room_settings])
171
    opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"]
172
    opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]
173
174
    begin
175
      redirect_to join_path(@room, current_user.name, opts, current_user.uid)
176
    rescue BigBlueButton::BigBlueButtonException => e
177
      logger.error("Support: #{@room.uid} start failed: #{e}")
178
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
      options = params[:room].nil? ? params : params[:room]
191
      raise "Room name can't be blank" if options[:name].blank?
192
      raise "Unauthorized Request" if [email protected]_by?(current_user) || @room == current_user.main_room
193
194
      # Update the rooms settings
195
      room_settings_string = create_room_settings_string(options)
196
      @room.update_attributes(room_settings: room_settings_string) if @room.room_settings != room_settings_string
197
198
      # Update the rooms name if it has been changed
199
      @room.update_attributes(name: options[:name]) if @room.name != options[:name]
200
      # Update the room's access code if it has changed
201
      @room.update_attributes(access_code: options[:access_code]) if @room.access_code != options[:access_code]
202
203
      flash[:success] = I18n.t("room.update_settings_success")
204
    rescue => e
205
      logger.error "Support: Error in updating room settings: #{e}"
206
      flash[:alert] = I18n.t("room.update_settings_error")
207
    end
208
209
    redirect_to room_path
210
  end
211
212
  # GET /:room_uid/logout
213
  def logout
214
    logger.info "Support: #{current_user.present? ? current_user.email : 'Guest'} has left room #{@room.uid}"
215
216
    # Redirect the correct page.
217
    redirect_to @room
218
  end
219
220
  # POST /:room_uid/login
221
  def login
222
    session[:access_code] = room_params[:access_code]
223
224
    flash[:alert] = I18n.t("room.access_code_required") if session[:access_code] != @room.access_code
225
226
    redirect_to room_path(@room.uid)
227
  end
228
229
  private
230
231
  def create_room_settings_string(options)
232
    room_settings = {}
233
    room_settings["muteOnStart"] = options[:mute_on_join] == "1"
234
235
    room_settings["requireModeratorApproval"] = options[:require_moderator_approval] == "1"
236
237
    room_settings["anyoneCanStart"] = options[:anyone_can_start] == "1"
238
239
    room_settings["joinModerator"] = options[:all_join_moderator] == "1"
240
241
    room_settings.to_json
242
  end
243
244
  def room_params
245
    params.require(:room).permit(:name, :auto_join, :mute_on_join, :access_code,
246
      :require_moderator_approval, :anyone_can_start, :all_join_moderator)
247
  end
248
249
  # Find the room from the uid.
250
  def find_room
251
    @room = Room.find_by!(uid: params[:room_uid])
252
  end
253
254
  # Ensure the user is logged into the room they are accessing.
255
  def verify_room_ownership
256
    return redirect_to root_path unless @room.owned_by?(current_user)
257
  end
258
259
  def validate_accepted_terms
260
    redirect_to terms_path if current_user && !current_user&.accepted_terms
261
  end
262
263
  def validate_verified_email
264
    redirect_to account_activation_path(current_user) if current_user && !current_user&.activated?
265
  end
266
267
  def verify_room_owner_verified
268
    unless @room.owner.activated?
269
      flash[:alert] = t("room.unavailable")
270
      redirect_to root_path
271
    end
272
  end
273
274
  def verify_user_not_admin
275
    redirect_to admins_path if current_user&.has_role?(:super_admin)
276
  end
277
278
  def auth_required
279
    @settings.get_value("Room Authentication") == "true" && current_user.nil?
280
  end
281
282
  def room_limit_exceeded
283
    limit = @settings.get_value("Room Limit").to_i
284
285
    # Does not apply to admin or users that aren't signed in
286
    # 15+ option is used as unlimited
287
    return false if current_user&.has_role?(:admin) || limit == 15
288
289
    current_user.rooms.length >= limit
290
  end
291
  helper_method :room_limit_exceeded
292
end
293