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 — master ( ce2c9c...5a8758 )
by Jesus
15s queued 10s
created

AdminsController.room_limit()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
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
24
  manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve]
25
  site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken,
26
                   :registration_method, :room_authentication, :room_limit]
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
  before_action :find_setting, only: site_settings
32
33
  # GET /admins
34
  def index
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
    @role = params[:role] || ""
39
40
    @pagy, @users = pagy(user_list)
41
  end
42
43
  # MANAGE USERS
44
45
  # GET /admins/edit/:user_uid
46
  def edit_user
47
    render "admins/index", locals: { setting_id: "account" }
48
  end
49
50
  # POST /admins/promote/:user_uid
51
  def promote
52
    @user.add_role :admin
53
54
    send_user_promoted_email(@user)
55
56
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.promoted") }
57
  end
58
59
  # POST /admins/demote/:user_uid
60
  def demote
61
    @user.remove_role :admin
62
63
    send_user_demoted_email(@user)
64
65
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.demoted") }
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
    begin
96
      invitation = create_or_update_invite(email)
97
98
      send_invitation_email(current_user.name, email, invitation.invite_token)
99
    rescue => e
100
      logger.error "Error in email delivery: #{e}"
101
      flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error"))
102
    else
103
      flash[:success] = I18n.t("administrator.flash.invite", email: email)
104
    end
105
106
    redirect_to admins_path
107
  end
108
109
  # SITE SETTINGS
110
111
  # POST /admins/branding
112
  def branding
113
    @settings.update_value("Branding Image", params[:url])
114
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
115
  end
116
117
  # POST /admins/color
118
  def coloring
119
    @settings.update_value("Primary Color", params[:color])
120
    @settings.update_value("Primary Color Lighten", color_lighten(params[:color]))
121
    @settings.update_value("Primary Color Darken", color_darken(params[:color]))
122
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
123
  end
124
125 View Code Duplication
  def coloring_lighten
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
126
    @settings.update_value("Primary Color Lighten", params[:color])
127
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
128
  end
129
130 View Code Duplication
  def coloring_darken
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
131
    @settings.update_value("Primary Color Darken", params[:color])
132
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
133
  end
134
135
  # POST /admins/room_authentication
136
  def room_authentication
137
    @settings.update_value("Room Authentication", params[:value])
138
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
139
  end
140
141
  # POST /admins/registration_method/:method
142
  def registration_method
143
    new_method = Rails.configuration.registration_methods[params[:method].to_sym]
144
145
    # Only allow change to Join by Invitation if user has emails enabled
146
    if !Rails.configuration.enable_email_verification && new_method == Rails.configuration.registration_methods[:invite]
147
      redirect_to admins_path,
148
        flash: { alert: I18n.t("administrator.flash.invite_email_verification") }
149
    else
150
      @settings.update_value("Registration Method", new_method)
151
      redirect_to admins_path,
152
        flash: { success: I18n.t("administrator.flash.registration_method_updated") }
153
    end
154
  end
155
156
  # POST /admins/room_limit
157
  def room_limit
158
    @settings.update_value("Room Limit", params[:limit])
159
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") }
160
  end
161
162
  private
163
164
  def find_user
165
    @user = User.find_by!(uid: params[:user_uid])
166
  end
167
168
  def find_setting
169
    @settings = Setting.find_or_create_by!(provider: user_settings_provider)
170
  end
171
172
  def verify_admin_of_user
173
    redirect_to admins_path,
174
      flash: { alert: I18n.t("administrator.flash.unauthorized") } unless current_user.admin_of?(@user)
175
  end
176
177
  # Gets the list of users based on your configuration
178
  def user_list
179
    initial_list = if current_user.has_role? :super_admin
180
      User.where.not(id: current_user.id)
181
    else
182
      User.without_role(:super_admin).where.not(id: current_user.id)
183
    end
184
185
    list = @role.present? ? initial_list.with_role(@role.to_sym) : initial_list
186
187
    if Rails.configuration.loadbalanced_configuration
188
      list.where(provider: user_settings_provider)
189
          .admins_search(@search)
190
          .admins_order(@order_column, @order_direction)
191
    else
192
      list.admins_search(@search)
193
          .admins_order(@order_column, @order_direction)
194
    end
195
  end
196
197
  # Creates the invite if it doesn't exist, or updates the updated_at time if it does
198
  def create_or_update_invite(email)
199
    invite = Invitation.find_by(email: email, provider: @user_domain)
200
201
    # Invite already exists
202
    if invite.present?
203
      # Updates updated_at to now
204
      invite.touch
205
    else
206
      # Creates invite
207
      invite = Invitation.create(email: email, provider: @user_domain)
208
    end
209
210
    invite
211
  end
212
end
213