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:27
created

AdminsController.create_or_update_invite()   A

Complexity

Conditions 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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