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 (#848)
by Ahmad
03:48
created

RoomsController.room_limit_exceeded()   A

Complexity

Conditions 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
dl 0
loc 9
rs 9.95
c 0
b 0
f 0
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]
29
  before_action :verify_room_ownership_or_admin, only: [:start, :update_settings]
30
  before_action :verify_room_owner_verified, only: [:show, :join],
31
                unless: -> { !Rails.configuration.enable_email_verification }
32
  before_action :verify_user_not_admin, only: [:show]
33
34
  # POST /
35
  def create
36
    # Return to root if user is not signed in
37
    return redirect_to root_path unless current_user
38
39
    # Check if the user has not exceeded the room limit
40
    return redirect_to current_user.main_room, flash: { alert: I18n.t("room.room_limit") } if room_limit_exceeded
41
42
    # Create room
43
    @room = Room.new(name: room_params[:name], access_code: room_params[:access_code])
44
    @room.owner = current_user
45
    @room.room_settings = create_room_settings_string(room_params)
46
47
    # Save the room and redirect if it fails
48
    return redirect_to current_user.main_room, flash: { alert: I18n.t("room.create_room_error") } unless @room.save
49
50
    logger.info "Support: #{current_user.email} has created a new room #{@room.uid}."
51
52
    # Redirect to room is auto join was not turned on
53
    return redirect_to @room,
54
      flash: { success: I18n.t("room.create_room_success") } unless room_params[:auto_join] == "1"
55
56
    # Start the room if auto join was turned on
57
    start
58
  end
59
60
  # GET /:room_uid
61
  def show
62
    @anyone_can_start = JSON.parse(@room[:room_settings])["anyoneCanStart"]
63
    @room_running = room_running?(@room.bbb_id)
64
65
    # If its the current user's room
66
    if current_user && @room.owned_by?(current_user)
67
      if current_user.highest_priority_role.get_permission("can_create_rooms")
68
        # User is allowed to have rooms
69
        @search, @order_column, @order_direction, recs =
70
          recordings(@room.bbb_id, params.permit(:search, :column, :direction), true)
71
72
        @pagy, @recordings = pagy_array(recs)
73
      else
74
        # Render view for users that cant create rooms
75
        @recent_rooms = Room.where(id: cookies.encrypted["#{current_user.uid}_recently_joined_rooms"])
76
        render :cant_create_rooms
77
      end
78
    else
79
      return redirect_to root_path, flash: { alert: I18n.t("room.invalid_provider") } if incorrect_user_domain
80
81
      show_user_join
82
    end
83
  end
84
85
  # POST /:room_uid
86
  def join
87
    return redirect_to root_path,
88
      flash: { alert: I18n.t("administrator.site_settings.authentication.user-info") } if auth_required
89
90
    unless @room.owned_by?(current_user)
91
      # Don't allow users to join unless they have a valid access code or the room doesn't have an access code
92
      if @room.access_code && [email protected]_code.empty? && @room.access_code != session[:access_code]
93
        return redirect_to room_path(room_uid: params[:room_uid]), flash: { alert: I18n.t("room.access_code_required") }
94
      end
95
96
      # Assign join name if passed.
97
      if params[@room.invite_path]
98
        @join_name = params[@room.invite_path][:join_name]
99
      elsif !params[:join_name]
100
        # Join name not passed.
101
        return redirect_to root_path
102
      end
103
    end
104
105
    # create or update cookie with join name
106
    cookies.encrypted[:greenlight_name] = @join_name unless cookies.encrypted[:greenlight_name] == @join_name
107
108
    save_recent_rooms
109
110
    logger.info "Support: #{current_user.present? ? current_user.email : @join_name} is joining room #{@room.uid}"
111
    join_room(default_meeting_options)
112
  end
113
114
  # DELETE /:room_uid
115
  def destroy
116
    # Don't delete the users home room.
117
    @room.destroy if @room.owned_by?(current_user) && @room != current_user.main_room
118
119
    redirect_to current_user.main_room
120
  end
121
122
  # POST /room/join
123
  def join_specific_room
124
    room_uid = params[:join_room][:url].split('/').last
125
126
    begin
127
      @room = Room.find_by!(uid: room_uid)
128
    rescue ActiveRecord::RecordNotFound
129
      return redirect_to current_user.main_room, alert: I18n.t("room.no_room.invalid_room_uid")
130
    end
131
132
    redirect_to room_path(@room)
133
  end
134
135
  # POST /:room_uid/start
136
  def start
137
    logger.info "Support: #{current_user.email} is starting room #{@room.uid}"
138
139
    # Join the user in and start the meeting.
140
    opts = default_meeting_options
141
    opts[:user_is_moderator] = true
142
143
    # Include the user's choices for the room settings
144
    room_settings = JSON.parse(@room[:room_settings])
145
    opts[:mute_on_start] = room_settings["muteOnStart"]
146
    opts[:require_moderator_approval] = room_settings["requireModeratorApproval"]
147
148
    begin
149
      redirect_to join_path(@room, current_user.name, opts, current_user.uid)
150
    rescue BigBlueButton::BigBlueButtonException => e
151
      logger.error("Support: #{@room.uid} start failed: #{e}")
152
153
      redirect_to room_path, alert: I18n.t(e.key.to_s.underscore, default: I18n.t("bigbluebutton_exception"))
154
    end
155
156
    # Notify users that the room has started.
157
    # Delay 5 seconds to allow for server start, although the request will retry until it succeeds.
158
    NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
159
  end
160
161
  # POST /:room_uid/update_settings
162
  def update_settings
163
    begin
164
      options = params[:room].nil? ? params : params[:room]
165
      raise "Room name can't be blank" if options[:name].blank?
166
      raise "Unauthorized Request" if @room == current_user.main_room
167
168
      # Update the rooms values
169
      room_settings_string = create_room_settings_string(options)
170
171
      @room.update_attributes(
172
        name: options[:name],
173
        room_settings: room_settings_string,
174
        access_code: options[:access_code]
175
      )
176
177
      flash[:success] = I18n.t("room.update_settings_success")
178
    rescue => e
179
      logger.error "Support: Error in updating room settings: #{e}"
180
      flash[:alert] = I18n.t("room.update_settings_error")
181
    end
182
183
    redirect_back fallback_location: room_path(@room)
184
  end
185
186
  # GET /:room_uid/logout
187
  def logout
188
    logger.info "Support: #{current_user.present? ? current_user.email : 'Guest'} has left room #{@room.uid}"
189
190
    # Redirect the correct page.
191
    redirect_to @room
192
  end
193
194
  # POST /:room_uid/login
195
  def login
196
    session[:access_code] = room_params[:access_code]
197
198
    flash[:alert] = I18n.t("room.access_code_required") if session[:access_code] != @room.access_code
199
200
    redirect_to room_path(@room.uid)
201
  end
202
203
  private
204
205
  def create_room_settings_string(options)
206
    room_settings = {
207
      "muteOnStart": options[:mute_on_join] == "1",
208
      "requireModeratorApproval": options[:require_moderator_approval] == "1",
209
      "anyoneCanStart": options[:anyone_can_start] == "1",
210
      "joinModerator": options[:all_join_moderator] == "1",
211
    }
212
213
    room_settings.to_json
214
  end
215
216
  def room_params
217
    params.require(:room).permit(:name, :auto_join, :mute_on_join, :access_code,
218
      :require_moderator_approval, :anyone_can_start, :all_join_moderator)
219
  end
220
221
  # Find the room from the uid.
222
  def find_room
223
    @room = Room.find_by!(uid: params[:room_uid])
224
  end
225
226
  # Ensure the user is logged into the room they are accessing.
227
  def verify_room_ownership
228
    return redirect_to root_path unless @room.owned_by?(current_user)
229
  end
230
231
  # Ensure the user either owns the room or is an admin of the room owner
232
  def verify_room_ownership_or_admin
233
    return redirect_to root_path if [email protected]_by?(current_user) && !current_user.admin_of?(@room.owner)
234
  end
235
236
  def validate_accepted_terms
237
    redirect_to terms_path if current_user && !current_user&.accepted_terms
238
  end
239
240
  def validate_verified_email
241
    redirect_to account_activation_path(current_user) if current_user && !current_user&.activated?
242
  end
243
244
  def verify_room_owner_verified
245
    unless @room.owner.activated?
246
      flash[:alert] = t("room.unavailable")
247
      redirect_to root_path
248
    end
249
  end
250
251
  def verify_user_not_admin
252
    redirect_to admins_path if current_user&.has_role?(:super_admin)
253
  end
254
255
  def auth_required
256
    @settings.get_value("Room Authentication") == "true" && current_user.nil?
257
  end
258
259
  def room_limit_exceeded
260
    limit = @settings.get_value("Room Limit").to_i
261
262
    # Does not apply to admin or users that aren't signed in
263
    # 15+ option is used as unlimited
264
    return false if current_user&.has_role?(:admin) || limit == 15
265
266
    current_user.rooms.length >= limit
267
  end
268
  helper_method :room_limit_exceeded
269
end
270