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 ( b4736b...c26988 )
by Ahmad
05:11 queued 01:01
created

AdminsController.clear_cache()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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