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

ApplicationController.check_user_role()   A

Complexity

Conditions 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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