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 ( acb141...84c1dc )
by Ahmad
04:48
created

RoomsController.room_params()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
rs 10
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.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
      show_user_join
79
    end
80
  end
81
82
  # POST /:room_uid
83
  def join
84
    return redirect_to root_path,
85
      flash: { alert: I18n.t("administrator.site_settings.authentication.user-info") } if auth_required
86
87
    unless @room.owned_by?(current_user)
88
      # Don't allow users to join unless they have a valid access code or the room doesn't have an access code
89
      if @room.access_code && [email protected]_code.empty? && @room.access_code != session[:access_code]
90
        return redirect_to room_path(room_uid: params[:room_uid]), flash: { alert: I18n.t("room.access_code_required") }
91
      end
92
93
      # Assign join name if passed.
94
      if params[@room.invite_path]
95
        @join_name = params[@room.invite_path][:join_name]
96
      elsif !params[:join_name]
97
        # Join name not passed.
98
        return redirect_to root_path
99
      end
100
    end
101
102
    # create or update cookie with join name
103
    cookies.encrypted[:greenlight_name] = @join_name unless cookies.encrypted[:greenlight_name] == @join_name
104
105
    save_recent_rooms
106
107
    logger.info "Support: #{current_user.present? ? current_user.email : @join_name} is joining room #{@room.uid}"
108
    join_room(default_meeting_options)
109
  end
110
111
  # DELETE /:room_uid
112
  def destroy
113
    # Don't delete the users home room.
114
    if @room.owned_by?(current_user) && @room != current_user.main_room
115
      @room.destroy
116
      delete_all_recordings(@room.bbb_id)
117
    end
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"] if 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
      raise "Room name can't be blank" if room_params[:name].empty?
165
      raise "Unauthorized Request" if [email protected]_by?(current_user) || @room == current_user.main_room
166
167
      # Update the rooms settings
168
      if room_params
169
        room_settings_string = create_room_settings_string(room_params)
170
        @room.update_attributes(room_settings: room_settings_string)
171
      end
172
173
      # Update the rooms name if it has been changed
174
      @room.update_attributes(name: params[:room_name] || room_params[:name]) if @room.name != room_params[:name]
175
      # Update the room's access code if it has changed
176
      @room.update_attributes(access_code: room_params[:access_code]) if @room.access_code != room_params[:access_code]
177
178
      flash[:success] = I18n.t("room.update_settings_success")
179
    rescue => e
180
      logger.error "Support: Error in updating room settings: #{e}"
181
      flash[:alert] = I18n.t("room.update_settings_error")
182
    end
183
184
    redirect_to room_path
185
  end
186
187
  # GET /:room_uid/logout
188
  def logout
189
    logger.info "Support: #{current_user.present? ? current_user.email : 'Guest'} has left room #{@room.uid}"
190
191
    # Redirect the correct page.
192
    redirect_to @room
193
  end
194
195
  # POST /:room_uid/login
196
  def login
197
    session[:access_code] = room_params[:access_code]
198
199
    flash[:alert] = I18n.t("room.access_code_required") if session[:access_code] != @room.access_code
200
201
    redirect_to room_path(@room.uid)
202
  end
203
204
  private
205
206
  def create_room_settings_string(options)
207
    room_settings = {}
208
    room_settings["muteOnStart"] = options[:mute_on_join] == "1"
209
210
    room_settings["requireModeratorApproval"] = options[:require_moderator_approval] == "1"
211
212
    room_settings["anyoneCanStart"] = options[:anyone_can_start] == "1"
213
214
    room_settings["joinModerator"] = options[:all_join_moderator] == "1"
215
216
    room_settings.to_json
217
  end
218
219
  def room_params
220
    params.require(:room).permit(:name, :auto_join, :mute_on_join, :access_code,
221
      :require_moderator_approval, :anyone_can_start, :all_join_moderator)
222
  end
223
224
  # Find the room from the uid.
225
  def find_room
226
    @room = Room.find_by!(uid: params[:room_uid])
227
  end
228
229
  # Ensure the user is logged into the room they are accessing.
230
  def verify_room_ownership
231
    return redirect_to root_path unless @room.owned_by?(current_user)
232
  end
233
234
  def validate_accepted_terms
235
    redirect_to terms_path if current_user && !current_user&.accepted_terms
236
  end
237
238
  def validate_verified_email
239
    redirect_to account_activation_path(current_user) if current_user && !current_user&.activated?
240
  end
241
242
  def verify_room_owner_verified
243
    unless @room.owner.activated?
244
      flash[:alert] = t("room.unavailable")
245
      redirect_to root_path
246
    end
247
  end
248
249
  def verify_user_not_admin
250
    redirect_to admins_path if current_user&.has_role?(:super_admin)
251
  end
252
253
  def auth_required
254
    @settings.get_value("Room Authentication") == "true" && current_user.nil?
255
  end
256
257
  def room_limit_exceeded
258
    limit = @settings.get_value("Room Limit").to_i
259
260
    # Does not apply to admin or users that aren't signed in
261
    # 15+ option is used as unlimited
262
    return false if current_user&.has_role?(:admin) || limit == 15
263
264
    current_user.rooms.length >= limit
265
  end
266
  helper_method :room_limit_exceeded
267
end
268