Passed
Push — master ( ec4722...b2f2e7 )
by Jesus
04:39 queued 15s
created

ApplicationHelper.markdown()   A

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 12
rs 9.8
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]
50
  end
51
52
  # Return the fallback translations available in the client side through javascript
53
  def fallback_translations
54
    @fallback_translations ||= I18n.backend.send(:translations)
55
    @fallback_translations[I18n.default_locale]
56
  end
57
58
  # Returns the page that the logo redirects to when clicked on
59
  def home_page
60
    return root_path unless current_user
61
    return admins_path if current_user.has_role? :super_admin
62
    current_user.main_room
63
  end
64
65
  # Returns the action method of the current page
66
  def active_page
67
    route = Rails.application.routes.recognize_path(request.env['PATH_INFO'])
68
69
    route[:action]
70
  end
71
72
  def role_colour(role)
73
    role.colour || Rails.configuration.primary_color_default
74
  end
75
76
  def translated_role_name(role)
77
    if role.name == "denied"
78
      I18n.t("roles.banned")
79
    elsif role.name == "pending"
80
      I18n.t("roles.pending")
81
    elsif role.name == "admin"
82
      I18n.t("roles.admin")
83
    elsif role.name == "user"
84
      I18n.t("roles.user")
85
    else
86
      role.name
87
    end
88
  end
89
90
  def can_reset_password
91
    # Check if admin is editting user and user is a greenlight account
92
    Rails.configuration.enable_email_verification &&
93
      Rails.application.routes.recognize_path(request.env['PATH_INFO'])[:action] == "edit_user" &&
94
      @user.greenlight_account?
95
  end
96
97
  def google_analytics_url
98
    "https://www.googletagmanager.com/gtag/js?id=#{ENV['GOOGLE_ANALYTICS_TRACKING_ID']}"
99
  end
100
101
  def valid_url?(input)
102
    uri = URI.parse(input)
103
    !uri.host.nil?
104
  rescue URI::InvalidURIError
105
    false
106
  end
107
end
108