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 (#515)
by Ahmad
03:37
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
22
  before_action :validate_accepted_terms, unless: -> { !Rails.configuration.terms }
23
  before_action :validate_verified_email, except: [:show, :join],
24
                unless: -> { !Rails.configuration.enable_email_verification }
25
  before_action :find_room, except: :create
26
  before_action :verify_room_ownership, except: [:create, :show, :join, :logout]
27
  before_action :verify_room_owner_verified, only: [:show, :join],
28
                unless: -> { !Rails.configuration.enable_email_verification }
29
  before_action :verify_user_not_admin, only: [:show]
30
31
  # POST /
32
  def create
33
    redirect_to(root_path) && return unless current_user
34
35
    @room = Room.new(name: room_params[:name])
36
    @room.owner = current_user
37
    @room.room_settings = create_room_settings_string(room_params[:mute_on_join], room_params[:client])
38
39
    if @room.save
40
      if room_params[:auto_join] == "1"
41
        start
42
      else
43
        flash[:success] = I18n.t("room.create_room_success")
44
        redirect_to @room
45
      end
46
    else
47
      flash[:alert] = I18n.t("room.create_room_error")
48
      redirect_to current_user.main_room
49
    end
50
  end
51
52
  # GET /:room_uid
53
  def show
54
    if current_user && @room.owned_by?(current_user)
55
      recs = @room.recordings
56
57
      @recordings = recs
58
      @is_running = @room.running?
59
    else
60
      # Get users name
61
      @name = if current_user
62
        current_user.name
63
      elsif cookies.encrypted[:greenlight_name]
64
        cookies.encrypted[:greenlight_name]
65
      else
66
        ""
67
      end
68
69
      render :join
70
    end
71
  end
72
73
  # PATCH /:room_uid
74
  def update
75
    if params[:setting] == "rename_block"
76
      @room = Room.find_by!(uid: params[:room_block_uid])
77
      update_room_attributes("name")
78
    elsif params[:setting] == "rename_header"
79
      update_room_attributes("name")
80
    elsif params[:setting] == "rename_recording"
81
      @room.update_recording(params[:record_id], "meta_name" => params[:record_name])
82
    end
83
84
    if request.referrer
85
      redirect_to request.referrer
86
    else
87
      redirect_to room_path
88
    end
89
  end
90
91
  # POST /:room_uid
92
  def join
93
    opts = default_meeting_options
94
    unless @room.owned_by?(current_user)
95
      # Assign join name if passed.
96
      if params[@room.invite_path]
97
        @join_name = params[@room.invite_path][:join_name]
98
      elsif !params[:join_name]
99
        # Join name not passed.
100
        return
101
      end
102
    end
103
104
    # create or update cookie with join name
105
    cookies.encrypted[:greenlight_name] = @join_name unless cookies.encrypted[:greenlight_name] == @join_name
106
107
    if @room.running? || @room.owned_by?(current_user)
108
      # Determine if the user needs to join as a moderator.
109
      opts[:user_is_moderator] = @room.owned_by?(current_user)
110
111
      # Check if the user has specified which client to use
112
      room_settings = JSON.parse(@room[:room_settings])
113
      opts[:join_via_html5] = room_settings["joinViaHtml5"] if room_settings["joinViaHtml5"]
114
115
      if current_user
116
        redirect_to @room.join_path(current_user.name, opts, current_user.uid)
117
      else
118
        join_name = params[:join_name] || params[@room.invite_path][:join_name]
119
        redirect_to @room.join_path(join_name, opts)
120
      end
121
    else
122
      # They need to wait until the meeting begins.
123
      render :wait
124
    end
125
  end
126
127
  # DELETE /:room_uid
128
  def destroy
129
    # Don't delete the users home room.
130
    @room.destroy if @room.owned_by?(current_user) && @room != current_user.main_room
131
132
    redirect_to current_user.main_room
133
  end
134
135
  # POST /:room_uid/start
136
  def start
137
    # Join the user in and start the meeting.
138
    opts = default_meeting_options
139
    opts[:user_is_moderator] = true
140
141
    # Include the user's choices for the room settings
142
    room_settings = JSON.parse(@room[:room_settings])
143
    opts[:mute_on_start] = room_settings["muteOnStart"] if room_settings["muteOnStart"]
144
    opts[:join_via_html5] = room_settings["joinViaHtml5"] if room_settings["joinViaHtml5"]
145
146
    begin
147
      redirect_to @room.join_path(current_user.name, opts, current_user.uid)
148
    rescue BigBlueButton::BigBlueButtonException => e
149
      redirect_to room_path, alert: I18n.t(e.key.to_s.underscore, default: I18n.t("bigbluebutton_exception"))
150
    end
151
152
    # Notify users that the room has started.
153
    # Delay 5 seconds to allow for server start, although the request will retry until it succeeds.
154
    NotifyUserWaitingJob.set(wait: 5.seconds).perform_later(@room)
155
  end
156
157
  # POST /:room_uid/update_settings
158
  def update_settings
159
    begin
160
      raise "Room name can't be blank" if room_params[:name].empty?
161
162
      @room = Room.find_by!(uid: params[:room_uid])
163
      # Update the rooms settings
164
      update_room_attributes("settings")
165
      # Update the rooms name if it has been changed
166
      update_room_attributes("name") if @room.name != room_params[:name]
167
    rescue StandardError
168
      flash[:alert] = I18n.t("room.update_settings_error")
169
    else
170
      flash[:success] = I18n.t("room.update_settings_success")
171
    end
172
    redirect_to room_path
173
  end
174
175
  # GET /:room_uid/logout
176
  def logout
177
    # Redirect the correct page.
178
    redirect_to @room
179
  end
180
181
  private
182
183
  def update_room_attributes(update_type)
184
    if @room.owned_by?(current_user) && @room != current_user.main_room
185
      if update_type.eql? "name"
186
        @room.update_attributes(name: params[:room_name] || room_params[:name])
187
      elsif update_type.eql? "settings"
188
        room_settings_string = create_room_settings_string(room_params[:mute_on_join], room_params[:client])
189
        @room.update_attributes(room_settings: room_settings_string)
190
      end
191
    end
192
  end
193
194
  def create_room_settings_string(mute_res, client_res)
195
    room_settings = {}
196
    room_settings["muteOnStart"] = mute_res == "1"
197
198
    if client_res.eql? "html5"
199
      room_settings["joinViaHtml5"] = true
200
    elsif client_res.eql? "flash"
201
      room_settings["joinViaHtml5"] = false
202
    end
203
204
    room_settings.to_json
205
  end
206
207
  def room_params
208
    params.require(:room).permit(:name, :auto_join, :mute_on_join, :client)
209
  end
210
211
  # Find the room from the uid.
212
  def find_room
213
    @room = Room.find_by!(uid: params[:room_uid])
214
  end
215
216
  # Ensure the user is logged into the room they are accessing.
217
  def verify_room_ownership
218
    bring_to_room unless @room.owned_by?(current_user)
219
  end
220
221
  # Redirects a user to their room.
222
  def bring_to_room
223
    if current_user
224
      # Redirect authenticated users to their room.
225
      redirect_to room_path(current_user.main_room)
226
    else
227
      # Redirect unauthenticated users to root.
228
      redirect_to root_path
229
    end
230
  end
231
232
  def validate_accepted_terms
233
    if current_user
234
      redirect_to terms_path unless current_user.accepted_terms
235
    end
236
  end
237
238
  def validate_verified_email
239
    if current_user
240
      redirect_to account_activation_path(current_user) unless current_user.activated?
241
    end
242
  end
243
244
  def verify_room_owner_verified
245
    unless @room.owner.activated?
246
      flash[:alert] = t("room.unavailable")
247
248
      if current_user && [email protected]_by?(current_user)
249
        redirect_to current_user.main_room
250
      else
251
        redirect_to root_path
252
      end
253
    end
254
  end
255
256
  def verify_user_not_admin
257
    redirect_to admins_path if current_user && current_user&.has_role?(:super_admin)
258
  end
259
end
260