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.
Passed
Pull Request — master (#675)
by Ahmad
03:53
created

ApplicationController.check_admin_password()   A

Complexity

Conditions 4

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
c 0
b 0
f 0
dl 0
loc 8
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
require 'bigbluebutton_api'
20
21
class ApplicationController < ActionController::Base
22
  include ApplicationHelper
23
  include SessionsHelper
24
  include ThemingHelper
25
26
  # Force SSL for loadbalancer configurations.
27
  before_action :redirect_to_https
28
29
  before_action :maintenance_mode?
30
  before_action :set_user_domain
31
  before_action :migration_error?
32
  before_action :set_locale
33
  before_action :check_admin_password
34
  before_action :check_user_role
35
36
  # Manually handle BigBlueButton errors
37
  rescue_from BigBlueButton::BigBlueButtonException, with: :handle_bigbluebutton_error
38
39
  protect_from_forgery with: :exception
40
41
  MEETING_NAME_LIMIT = 90
42
  USER_NAME_LIMIT = 32
43
44
  # Show an information page when migration fails and there is a version error.
45
  def migration_error?
46
    render :migration_error unless ENV["DB_MIGRATE_FAILED"].blank?
47
  end
48
49
  def maintenance_mode?
50
    if ENV["MAINTENANCE_MODE"].present?
51
      @user_domain = "greenlight"
52
53
      render "errors/greenlight_error", status: 503, formats: :html,
54
        locals: {
55
          status_code: 503,
56
          message: I18n.t("errors.maintenance.message"),
57
          help: I18n.t("errors.maintenance.help"),
58
        }
59
    end
60
  end
61
62
  # Sets the appropriate locale.
63
  def set_locale
64
    update_locale(current_user)
65
  end
66
67
  def update_locale(user)
68
    locale = if user && user.language != 'default'
69
      user.language
70
    else
71
      http_accept_language.language_region_compatible_from(I18n.available_locales)
72
    end
73
    I18n.locale = locale.tr('-', '_') unless locale.nil?
74
  end
75
76
  def meeting_name_limit
77
    MEETING_NAME_LIMIT
78
  end
79
  helper_method :meeting_name_limit
80
81
  def user_name_limit
82
    USER_NAME_LIMIT
83
  end
84
  helper_method :user_name_limit
85
86
  # Relative root helper (when deploying to subdirectory).
87
  def relative_root
88
    Rails.configuration.relative_url_root || ""
89
  end
90
  helper_method :relative_root
91
92
  # Determines if the BigBlueButton endpoint is configured (or set to default).
93
  def bigbluebutton_endpoint_default?
94
    return false if Rails.configuration.loadbalanced_configuration
95
    Rails.configuration.bigbluebutton_endpoint_default == Rails.configuration.bigbluebutton_endpoint
96
  end
97
  helper_method :bigbluebutton_endpoint_default?
98
99
  def recording_thumbnails?
100
    Rails.configuration.recording_thumbnails
101
  end
102
  helper_method :recording_thumbnails?
103
104
  def allow_greenlight_users?
105
    allow_greenlight_accounts?
106
  end
107
  helper_method :allow_greenlight_users?
108
109
  # Determines if a form field needs the is-invalid class.
110
  def form_is_invalid?(obj, key)
111
    'is-invalid' unless obj.errors.messages[key].empty?
112
  end
113
  helper_method :form_is_invalid?
114
115
  # Default, unconfigured meeting options.
116
  def default_meeting_options
117
    invite_msg = I18n.t("invite_message")
118
    {
119
      user_is_moderator: false,
120
      meeting_logout_url: request.base_url + logout_room_path(@room),
121
      meeting_recorded: true,
122
      moderator_message: "#{invite_msg}\n\n#{request.base_url + room_path(@room)}",
123
    }
124
  end
125
126
  # Manually deal with 401 errors
127
  rescue_from CanCan::AccessDenied do |_exception|
128
    render "errors/greenlight_error"
129
  end
130
131
  # Checks to make sure that the admin has changed his password from the default
132
  def check_admin_password
133
    if current_user&.has_role?(:admin) && current_user&.greenlight_account? &&
134
       current_user&.authenticate(Rails.configuration.admin_password_default)
135
136
      flash.now[:alert] = I18n.t("default_admin",
137
        edit_link: edit_user_path(user_uid: current_user.uid) + "?setting=password").html_safe
138
    end
139
  end
140
141
  def redirect_to_https
142
    if Rails.configuration.loadbalanced_configuration && request.headers["X-Forwarded-Proto"] == "http"
143
      redirect_to protocol: "https://"
144
    end
145
  end
146
147
  def set_user_domain
148
    if Rails.env.test? || !Rails.configuration.loadbalanced_configuration
149
      @user_domain = "greenlight"
150
    else
151
      @user_domain = parse_user_domain(request.host)
152
153
      # Checks to see if the user exists
154
      begin
155
        retrieve_provider_info(@user_domain, 'api2', 'getUserGreenlightCredentials')
156
      rescue => e
157
        # Use the default site settings
158
        @user_domain = "greenlight"
159
160
        if e.message.eql? "No user with that id exists"
161
          render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_not_found.message"),
162
            help: I18n.t("errors.not_found.user_not_found.help") }
163
        elsif e.message.eql? "Provider not included."
164
          render "errors/greenlight_error", locals: { message: I18n.t("errors.not_found.user_missing.message"),
165
            help: I18n.t("errors.not_found.user_missing.help") }
166
        elsif e.message.eql? "That user has no configured provider."
167
          render "errors/greenlight_error", locals: { status_code: 501,
168
            message: I18n.t("errors.no_provider.message"),
169
            help: I18n.t("errors.no_provider.help") }
170
        else
171
          render "errors/greenlight_error", locals: { status_code: 500, message: I18n.t("errors.internal.message"),
172
            help: I18n.t("errors.internal.help"), display_back: true }
173
        end
174
      end
175
    end
176
  end
177
  helper_method :set_user_domain
178
179
  # Checks if the user is banned and logs him out if he is
180
  def check_user_role
181
    if current_user&.has_role? :denied
182
      session.delete(:user_id)
183
      redirect_to root_path, flash: { alert: I18n.t("registration.banned.fail") }
184
    elsif current_user&.has_role? :pending
185
      session.delete(:user_id)
186
      redirect_to root_path, flash: { alert: I18n.t("registration.approval.fail") }
187
    end
188
  end
189
  helper_method :check_user_role
190
191
  # Manually Handle BigBlueButton errors
192
  def handle_bigbluebutton_error
193
    render "errors/bigbluebutton_error"
194
  end
195
end
196