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 'i18n/language/mapping' |
20
|
|
|
|
21
|
|
|
module UsersHelper |
22
|
|
|
include I18n::Language::Mapping |
23
|
|
|
|
24
|
|
|
def recaptcha_enabled? |
25
|
|
|
Rails.configuration.recaptcha_enabled |
26
|
|
|
end |
27
|
|
|
|
28
|
|
|
def disabled_roles(user) |
29
|
|
|
current_user_role = current_user.highest_priority_role |
30
|
|
|
|
31
|
|
|
# Admins are able to remove the admin role from other admins |
32
|
|
|
# For all other roles they can only add/remove roles with a higher priority |
33
|
|
|
disallowed_roles = if current_user_role.name == "admin" |
34
|
|
|
Role.editable_roles(@user_domain).where("priority < #{current_user_role.priority}") |
35
|
|
|
.pluck(:id) |
36
|
|
|
else |
37
|
|
|
Role.editable_roles(@user_domain).where("priority <= #{current_user_role.priority}") |
38
|
|
|
.pluck(:id) |
39
|
|
|
end |
40
|
|
|
|
41
|
|
|
user.roles.by_priority.pluck(:id) | disallowed_roles |
42
|
|
|
end |
43
|
|
|
|
44
|
|
|
# Returns language selection options for user edit |
45
|
|
|
def language_options |
46
|
|
|
locales = I18n.available_locales |
47
|
|
|
language_opts = [['<<<< ' + t("language_default") + ' >>>>', "default"]] |
48
|
|
|
locales.each do |locale| |
49
|
|
|
language_mapping = I18n::Language::Mapping.language_mapping_list[locale.to_s.gsub("_", "-")] |
50
|
|
|
language_opts.push([language_mapping["nativeName"], locale.to_s]) |
51
|
|
|
end |
52
|
|
|
language_opts.sort |
53
|
|
|
end |
54
|
|
|
|
55
|
|
|
# Parses markdown for rendering. |
56
|
|
|
def markdown(text) |
57
|
|
|
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, |
58
|
|
|
no_intra_emphasis: true, |
59
|
|
|
fenced_code_blocks: true, |
60
|
|
|
disable_indented_code_blocks: true, |
61
|
|
|
autolink: true, |
62
|
|
|
tables: true, |
63
|
|
|
underline: true, |
64
|
|
|
highlight: true) |
65
|
|
|
|
66
|
|
|
markdown.render(text).html_safe |
67
|
|
|
end |
68
|
|
|
end |
69
|
|
|
|