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 (#496)
by Jesus
03:28
created

ApplicationController.check_if_unbanned()   A

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 6
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 SessionsHelper
23
  include ThemingHelper
24
25
  before_action :migration_error?
26
  before_action :set_locale
27
  before_action :check_admin_password
28
  before_action :set_user_domain
29
  before_action :check_if_unbanned
30
31
  # Force SSL for loadbalancer configurations.
32
  before_action :redirect_to_https
33
34
  protect_from_forgery with: :exception
35
36
  MEETING_NAME_LIMIT = 90
37
  USER_NAME_LIMIT = 32
38
39
  # Show an information page when migration fails and there is a version error.
40
  def migration_error?
41
    render :migration_error unless ENV["DB_MIGRATE_FAILED"].blank?
42
  end
43
44
  # Sets the appropriate locale.
45
  def set_locale
46
    update_locale(current_user)
47
  end
48
49
  def update_locale(user)
50
    locale = if user && user.language != 'default'
51
      user.language
52
    else
53
      http_accept_language.language_region_compatible_from(I18n.available_locales)
54
    end
55
    I18n.locale = locale.tr('-', '_') unless locale.nil?
56
  end
57
58
  def meeting_name_limit
59
    MEETING_NAME_LIMIT
60
  end
61
  helper_method :meeting_name_limit
62
63
  def user_name_limit
64
    USER_NAME_LIMIT
65
  end
66
  helper_method :user_name_limit
67
68
  # Relative root helper (when deploying to subdirectory).
69
  def relative_root
70
    Rails.configuration.relative_url_root || ""
71
  end
72
  helper_method :relative_root
73
74
  # Determines if the BigBlueButton endpoint is configured (or set to default).
75
  def bigbluebutton_endpoint_default?
76
    return false if Rails.configuration.loadbalanced_configuration
77
    Rails.configuration.bigbluebutton_endpoint_default == Rails.configuration.bigbluebutton_endpoint
78
  end
79
  helper_method :bigbluebutton_endpoint_default?
80
81
  def recording_thumbnails?
82
    Rails.configuration.recording_thumbnails
83
  end
84
  helper_method :recording_thumbnails?
85
86
  def allow_greenlight_users?
87
    Rails.configuration.greenlight_accounts
88
  end
89
  helper_method :allow_greenlight_users?
90
91
  # Determines if a form field needs the is-invalid class.
92
  def form_is_invalid?(obj, key)
93
    'is-invalid' unless obj.errors.messages[key].empty?
94
  end
95
  helper_method :form_is_invalid?
96
97
  # Default, unconfigured meeting options.
98
  def default_meeting_options
99
    invite_msg = I18n.t("invite_message")
100
    {
101
      user_is_moderator: false,
102
      meeting_logout_url: request.base_url + logout_room_path(@room),
103
      meeting_recorded: true,
104
      moderator_message: "#{invite_msg}\n\n#{request.base_url + room_path(@room)}",
105
    }
106
  end
107
108
  # Manually deal with 401 errors
109
  rescue_from CanCan::AccessDenied do |_exception|
110
    render "errors/not_found"
111
  end
112
113
  # Checks to make sure that the admin has changed his password from the default
114
  def check_admin_password
115
    if current_user&.has_role?(:admin) && current_user&.greenlight_account? &&
116
       current_user&.authenticate(Rails.configuration.admin_password_default)
117
118
      flash.now[:alert] = I18n.t("default_admin",
119
        edit_link: edit_user_path(user_uid: current_user.uid) + "?setting=password").html_safe
120
    end
121
  end
122
123
  def redirect_to_https
124
    if Rails.configuration.loadbalanced_configuration && request.headers["X-Forwarded-Proto"] == "http"
125
      redirect_to protocol: "https://"
126
    end
127
  end
128
129
  def set_user_domain
130
    @user_domain = if Rails.env.test? || !Rails.configuration.loadbalanced_configuration
131
      "greenlight"
132
    else
133
      parse_user_domain(request.host)
134
    end
135
  end
136
  helper_method :set_user_domain
137
138
  # Checks if the user is banned and logs him out if he is
139
  def check_if_unbanned
140
    if current_user&.has_role?(:denied)
141
      session.delete(:user_id)
142
      redirect_to unauthorized_path
143
    end
144
  end
145
  helper_method :check_if_unbanned
146
end
147