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 (#520)
by Ahmad
03:26
created

AdminsController.find_setting()   A

Complexity

Conditions 1

Size

Total Lines 3

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 3
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 Emailer
22
23
  manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve]
24
  site_settings = [:branding, :coloring, :registration_method]
25
26
  authorize_resource class: false
27
  before_action :find_user, only: manage_users
28
  before_action :verify_admin_of_user, only: manage_users
29
  before_action :find_setting, only: site_settings
30
31
  # GET /admins
32
  def index
33
    @search = params[:search] || ""
34
    @order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at"
35
    @order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC"
36
37
    @pagy, @users = pagy(user_list)
38
  end
39
40
  # MANAGE USERS
41
42
  # GET /admins/edit/:user_uid
43
  def edit_user
44
    render "admins/index", locals: { setting_id: "account" }
45
  end
46
47
  # POST /admins/promote/:user_uid
48
  def promote
49
    @user.add_role :admin
50
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.promoted") }
51
  end
52
53
  # POST /admins/demote/:user_uid
54
  def demote
55
    @user.remove_role :admin
56
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.demoted") }
57
  end
58
59
  # POST /admins/ban/:user_uid
60
  def ban_user
61
    @user.remove_role :pending if @user.has_role? :pending
62
    @user.add_role :denied
63
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.banned") }
64
  end
65
66
  # POST /admins/unban/:user_uid
67
  def unban_user
68
    @user.remove_role :denied
69
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.unbanned") }
70
  end
71
72
  # POST /admins/approve/:user_uid
73
  def approve
74
    @user.remove_role :pending
75
76
    send_user_approved_email(@user)
77
78
    redirect_to admins_path, flash: { success: I18n.t("administrator.flash.approved") }
79
  end
80
81
  # POST /admins/invite
82
  def invite
83
    email = params[:invite_user][:email]
84
85
    begin
86
      invitation = create_or_update_invite(email)
87
88
      send_invitation_email(current_user.name, email, invitation.invite_token)
89
    rescue => e
90
      logger.error "Error in email delivery: #{e}"
91
      flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error"))
92
    else
93
      flash[:success] = I18n.t("administrator.flash.invite", email: email)
94
    end
95
96
    redirect_to admins_path
97
  end
98
99
  # SITE SETTINGS
100
101
  # POST /admins/branding
102
  def branding
103
    @settings.update_value("Branding Image", params[:url])
104
    redirect_to admins_path
105
  end
106
107
  # POST /admins/color
108
  def coloring
109
    @settings.update_value("Primary Color", params[:color])
110
    redirect_to admins_path
111
  end
112
113
  # POST /admins/registration_method/:method
114
  def registration_method
115
    new_method = Rails.configuration.registration_methods[params[:method].to_sym]
116
117
    # Only allow change to Join by Invitation if user has emails enabled
118
    if !Rails.configuration.enable_email_verification && new_method == Rails.configuration.registration_methods[:invite]
119
      redirect_to admins_path,
120
        flash: { alert: I18n.t("administrator.flash.invite_email_verification") }
121
    else
122
      @settings.update_value("Registration Method", new_method)
123
      redirect_to admins_path,
124
        flash: { success: I18n.t("administrator.flash.registration_method_updated") }
125
    end
126
  end
127
128
  private
129
130
  def find_user
131
    @user = User.find_by!(uid: params[:user_uid])
132
  end
133
134
  def find_setting
135
    @settings = Setting.find_or_create_by!(provider: user_settings_provider)
136
  end
137
138
  def verify_admin_of_user
139
    redirect_to admins_path,
140
      flash: { alert: I18n.t("administrator.flash.unauthorized") } unless current_user.admin_of?(@user)
141
  end
142
143
  # Gets the list of users based on your configuration
144
  def user_list
145
    if Rails.configuration.loadbalanced_configuration
146
      User.without_role(:super_admin)
147
          .where(provider: user_settings_provider)
148
          .where.not(id: current_user.id)
149
          .admins_search(@search)
150
          .admins_order(@order_column, @order_direction)
151
    else
152
      User.where.not(id: current_user.id)
153
          .admins_search(@search)
154
          .admins_order(@order_column, @order_direction)
155
    end
156
  end
157
158
  # Creates the invite if it doesn't exist, or updates the updated_at time if it does
159
  def create_or_update_invite(email)
160
    invite = Invitation.find_by(email: email, provider: @user_domain)
161
162
    # Invite already exists
163
    if invite.present?
164
      # Updates updated_at to now
165
      invite.touch
166
    else
167
      # Creates invite
168
      invite = Invitation.create(email: email, provider: @user_domain)
169
    end
170
171
    invite
172
  end
173
end
174