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 'bbb_api' |
20
|
|
|
require 'uri' |
21
|
|
|
|
22
|
|
|
module ApplicationHelper |
23
|
|
|
# Determines which providers can show a login button in the login modal. |
24
|
|
|
def iconset_providers |
25
|
|
|
providers = configured_providers & [:google, :twitter, :office365, :ldap] |
26
|
|
|
|
27
|
|
|
providers.delete(:twitter) if session[:old_twitter_user_id] |
28
|
|
|
|
29
|
|
|
providers |
30
|
|
|
end |
31
|
|
|
|
32
|
|
|
# Generates the login URL for a specific provider. |
33
|
|
|
def omniauth_login_url(provider) |
34
|
|
|
if provider == :ldap |
35
|
|
|
ldap_signin_path |
36
|
|
|
else |
37
|
|
|
"#{Rails.configuration.relative_url_root}/auth/#{provider}" |
38
|
|
|
end |
39
|
|
|
end |
40
|
|
|
|
41
|
|
|
# Determines if a form field needs the is-invalid class. |
42
|
|
|
def form_is_invalid?(obj, key) |
43
|
|
|
'is-invalid' unless obj.errors.messages[key].empty? |
44
|
|
|
end |
45
|
|
|
|
46
|
|
|
# Return all the translations available in the client side through javascript |
47
|
|
|
def current_translations |
48
|
|
|
@translations ||= I18n.backend.send(:translations) |
49
|
|
|
@translations[I18n.locale].with_indifferent_access[:javascript] || {} |
50
|
|
|
end |
51
|
|
|
|
52
|
|
|
# Returns the page that the logo redirects to when clicked on |
53
|
|
|
def home_page |
54
|
|
|
return root_path unless current_user |
55
|
|
|
return admins_path if current_user.has_role? :super_admin |
56
|
|
|
current_user.main_room |
57
|
|
|
end |
58
|
|
|
|
59
|
|
|
# Returns the action method of the current page |
60
|
|
|
def active_page |
61
|
|
|
route = Rails.application.routes.recognize_path(request.env['PATH_INFO']) |
62
|
|
|
|
63
|
|
|
route[:action] |
64
|
|
|
end |
65
|
|
|
|
66
|
|
|
def role_colour(role) |
67
|
|
|
role.colour || Rails.configuration.primary_color_default |
68
|
|
|
end |
69
|
|
|
|
70
|
|
|
def translated_role_name(role) |
71
|
|
|
if role.name == "denied" |
72
|
|
|
I18n.t("roles.banned") |
73
|
|
|
elsif role.name == "pending" |
74
|
|
|
I18n.t("roles.pending") |
75
|
|
|
elsif role.name == "admin" |
76
|
|
|
I18n.t("roles.admin") |
77
|
|
|
elsif role.name == "user" |
78
|
|
|
I18n.t("roles.user") |
79
|
|
|
else |
80
|
|
|
role.name |
81
|
|
|
end |
82
|
|
|
end |
83
|
|
|
|
84
|
|
|
def can_reset_password |
85
|
|
|
# Check if admin is editting user and user is a greenlight account |
86
|
|
|
Rails.configuration.enable_email_verification && |
87
|
|
|
Rails.application.routes.recognize_path(request.env['PATH_INFO'])[:action] == "edit_user" && |
88
|
|
|
@user.greenlight_account? |
89
|
|
|
end |
90
|
|
|
|
91
|
|
|
def google_analytics_url |
92
|
|
|
"https://www.googletagmanager.com/gtag/js?id=#{ENV['GOOGLE_ANALYTICS_TRACKING_ID']}" |
93
|
|
|
end |
94
|
|
|
|
95
|
|
|
def valid_url?(input) |
96
|
|
|
uri = URI.parse(input) |
97
|
|
|
!uri.host.nil? |
98
|
|
|
rescue URI::InvalidURIError |
99
|
|
|
false |
100
|
|
|
end |
101
|
|
|
end |
102
|
|
|
|