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

AdminsController.room_is_running()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 3
rs 10
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 AdminsController < ApplicationController
20
  include Pagy::Backend
21
  include Themer
22
  include Emailer
23
  include Recorder
24
  include Rolify
25
26
  manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve, :reset]
27
  manage_deleted_users = [:undelete]
28
  authorize_resource class: false
29
  before_action :find_user, only: manage_users
30
  before_action :find_deleted_user, only: manage_deleted_users
31
  before_action :verify_admin_of_user, only: [manage_users, manage_deleted_users]
32
33
  # GET /admins
34
  def index
35
    # Initializa the data manipulation variables
36
    @search = params[:search] || ""
37
    @order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at"
38
    @order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC"
39
40
    @role = params[:role] ? Role.find_by(name: params[:role], provider: @user_domain) : nil
41
    @tab = params[:tab] || "active"
42
43
    @pagy, @users = pagy(user_list)
44
  end
45
46
  # GET /admins/site_settings
47
  def site_settings
48
  end
49
50
  # GET /admins/server_recordings
51
  def server_recordings
52
    server_rooms = if Rails.configuration.loadbalanced_configuration
53
      Room.includes(:owner).where(users: { provider: @user_domain }).pluck(:bbb_id)
54
    else
55
      Room.pluck(:bbb_id)
56
    end
57
58
    @search, @order_column, @order_direction, recs =
59
      all_recordings(server_rooms, params.permit(:search, :column, :direction), true, true)
60
61
    @pagy, @recordings = pagy_array(recs)
62
  end
63
64
  # GET /admins/rooms
65
  def server_rooms
66
    @search = params[:search] || ""
67
    @order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at"
68
    @order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC"
69
70
    server_rooms = if Rails.configuration.loadbalanced_configuration
71
      Room.includes(:owner).where(users: { provider: @user_domain }).admins_search(@search).admins_order(@order_column, @order_direction)
72
    else
73
      Room.all.admins_search(@search).admins_order(@order_column, @order_direction)
74
    end
75
76
    @pagy, @rooms = pagy_array(server_rooms)
77
  end
78
79
  # MANAGE USERS
80
81
  # GET /admins/edit/:user_uid
82
  def edit_user
83
  end
84
85
  # POST /admins/ban/:user_uid
86
  def ban_user
87
    @user.roles = []
88
    @user.add_role :denied
89
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.banned") }
90
  end
91
92
  # POST /admins/unban/:user_uid
93
  def unban_user
94
    @user.remove_role :denied
95
    @user.add_role :user
96
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.unbanned") }
97
  end
98
99
  # POST /admins/approve/:user_uid
100
  def approve
101
    @user.remove_role :pending
102
103
    send_user_approved_email(@user)
104
105
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.approved") }
106
  end
107
108
  # POST /admins/approve/:user_uid
109
  def undelete
110
    # Undelete the user and all of his rooms
111
    @user.undelete!
112
    @user.rooms.deleted.each(&:undelete!)
113
114
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.restored") }
115
  end
116
117
  # POST /admins/invite
118
  def invite
119
    emails = params[:invite_user][:email].split(",")
120
121
    emails.each do |email|
122
      invitation = create_or_update_invite(email)
123
124
      send_invitation_email(current_user.name, email, invitation.invite_token)
125
    end
126
127
    redirect_to admins_path
128
  end
129
130
  # GET /admins/reset
131
  def reset
132
    @user.create_reset_digest
133
134
    send_password_reset_email(@user)
135
136
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.reset_password") }
137
  end
138
  # SITE SETTINGS
139
140
  # POST /admins/update_settings
141
  def update_settings
142
    @settings.update_value(params[:setting], params[:value])
143
144
    flash_message = I18n.t("administrator.flash.settings")
145
146
    if params[:value] == "Default Recording Visibility"
147
      flash_message += ". " + I18n.t("administrator.site_settings.recording_visibility.warning")
148
    end
149
150
    redirect_to admin_site_settings_path, flash: { success: flash_message }
151
  end
152
153
  # POST /admins/color
154
  def coloring
155
    @settings.update_value("Primary Color", params[:value])
156
    @settings.update_value("Primary Color Lighten", color_lighten(params[:value]))
157
    @settings.update_value("Primary Color Darken", color_darken(params[:value]))
158
    redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") }
159
  end
160
161
  # POST /admins/registration_method/:method
162
  def registration_method
163
    new_method = Rails.configuration.registration_methods[params[:value].to_sym]
164
165
    # Only allow change to Join by Invitation if user has emails enabled
166
    if !Rails.configuration.enable_email_verification && new_method == Rails.configuration.registration_methods[:invite]
167
      redirect_to admin_site_settings_path,
168
        flash: { alert: I18n.t("administrator.flash.invite_email_verification") }
169
    else
170
      @settings.update_value("Registration Method", new_method)
171
      redirect_to admin_site_settings_path,
172
        flash: { success: I18n.t("administrator.flash.registration_method_updated") }
173
    end
174
  end
175
176
  # ROLES
177
178
  # GET /admins/roles
179
  def roles
180
    @roles = all_roles(params[:selected_role])
181
  end
182
183
  # POST /admins/role
184
  # This method creates a new role scoped to the users provider
185
  def new_role
186
    new_role = create_role(params[:role][:name])
187
188
    return redirect_to admin_roles_path, flash: { alert: I18n.t("administrator.roles.invalid_create") } if new_role.nil?
189
190
    redirect_to admin_roles_path(selected_role: new_role.id)
191
  end
192
193
  # PATCH /admin/roles/order
194
  # This updates the priority of a site's roles
195
  # Note: A lower priority role will always get used before a higher priority one
196
  def change_role_order
197
    unless update_priority(params[:role])
198
      redirect_to admin_roles_path, flash: { alert: I18n.t("administrator.roles.invalid_order") }
199
    end
200
  end
201
202
  # POST /admin/role/:role_id
203
  # This method updates the permissions assigned to a role
204
  def update_role
205
    role = Role.find(params[:role_id])
206
    flash[:alert] = I18n.t("administrator.roles.invalid_update") unless update_permissions(role)
207
    redirect_to admin_roles_path(selected_role: role.id)
208
  end
209
210
  # DELETE admins/role/:role_id
211
  # This deletes a role
212
  def delete_role
213
    role = Role.find(params[:role_id])
214
215
    # Make sure no users are assigned to the role and the role isn't a reserved role
216
    # before deleting
217
    if role.users.count.positive?
218
      flash[:alert] = I18n.t("administrator.roles.role_has_users", user_count: role.users.count)
219
      return redirect_to admin_roles_path(selected_role: role.id)
220
    elsif Role::RESERVED_ROLE_NAMES.include?(role) || role.provider != @user_domain ||
221
          role.priority <= current_user.highest_priority_role.priority
222
      return redirect_to admin_roles_path(selected_role: role.id)
223
    else
224
      role.role_permissions.delete_all
225
      role.delete
226
    end
227
228
    redirect_to admin_roles_path
229
  end
230
231
  private
232
233
  def find_user
234
    @user = User.where(uid: params[:user_uid]).includes(:roles).first
235
  end
236
237
  def find_deleted_user
238
    @user = User.deleted.where(uid: params[:user_uid]).includes(:roles).first
239
  end
240
241
  # Verifies that admin is an administrator of the user in the action
242
  def verify_admin_of_user
243
    redirect_to admins_path,
244
      flash: { alert: I18n.t("administrator.flash.unauthorized") } unless current_user.admin_of?(@user)
245
  end
246
247
  # Gets the list of users based on your configuration
248
  def user_list
249
    current_role = @role
250
251
    initial_user = case @tab
252
      when "active"
253
        User.without_role(:pending).without_role(:denied)
254
      when "deleted"
255
        User.deleted
256
      else
257
        User
258
    end
259
260
    current_role = Role.find_by(name: @tab, provider: @user_domain) if @tab == "pending" || @tab == "denied"
261
262
    initial_list = if current_user.has_role? :super_admin
263
      initial_user.where.not(id: current_user.id)
264
    else
265
      initial_user.without_role(:super_admin).where.not(id: current_user.id)
266
    end
267
268
    if Rails.configuration.loadbalanced_configuration
269
      initial_list.where(provider: @user_domain)
270
                  .admins_search(@search, current_role)
271
                  .admins_order(@order_column, @order_direction)
272
    else
273
      initial_list.admins_search(@search, current_role)
274
                  .admins_order(@order_column, @order_direction)
275
    end
276
  end
277
278
  # Creates the invite if it doesn't exist, or updates the updated_at time if it does
279
  def create_or_update_invite(email)
280
    invite = Invitation.find_by(email: email, provider: @user_domain)
281
282
    # Invite already exists
283
    if invite.present?
284
      # Updates updated_at to now
285
      invite.touch
286
    else
287
      # Creates invite
288
      invite = Invitation.create(email: email, provider: @user_domain)
289
    end
290
291
    invite
292
  end
293
294
  # Get the room status to display in the Server Rooms table
295
  def room_is_running(id)
296
    room_running?(id)
297
  end
298
  helper_method :room_is_running
299
end
300