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
Push — master ( 670efe...8b2c47 )
by Jesus
03:50
created

ApplicationController.maintenance_mode?   A

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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