2018-06-26 10:29:46 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-01 09:45:12 -04:00
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under the
|
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software
|
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-08-19 11:28:48 -04:00
|
|
|
require 'i18n/language/mapping'
|
|
|
|
|
2018-05-08 10:41:03 -04:00
|
|
|
module UsersHelper
|
2019-08-19 11:28:48 -04:00
|
|
|
include I18n::Language::Mapping
|
|
|
|
|
2019-05-07 09:21:04 -04:00
|
|
|
def recaptcha_enabled?
|
2019-05-07 11:18:15 -04:00
|
|
|
Rails.configuration.recaptcha_enabled
|
2019-05-07 09:21:04 -04:00
|
|
|
end
|
2019-07-31 11:53:32 -04:00
|
|
|
|
|
|
|
def disabled_roles(user)
|
2020-05-26 17:37:23 -04:00
|
|
|
current_user_role = current_user.role
|
2019-07-31 11:53:32 -04:00
|
|
|
|
|
|
|
# Admins are able to remove the admin role from other admins
|
|
|
|
# For all other roles they can only add/remove roles with a higher priority
|
|
|
|
disallowed_roles = if current_user_role.name == "admin"
|
|
|
|
Role.editable_roles(@user_domain).where("priority < #{current_user_role.priority}")
|
|
|
|
.pluck(:id)
|
|
|
|
else
|
|
|
|
Role.editable_roles(@user_domain).where("priority <= #{current_user_role.priority}")
|
|
|
|
.pluck(:id)
|
|
|
|
end
|
|
|
|
|
2020-05-26 17:37:23 -04:00
|
|
|
[user.role.id] + disallowed_roles
|
2019-07-31 11:53:32 -04:00
|
|
|
end
|
2019-08-19 11:28:48 -04:00
|
|
|
|
|
|
|
# Returns language selection options for user edit
|
|
|
|
def language_options
|
|
|
|
locales = I18n.available_locales
|
2021-02-26 17:34:07 -05:00
|
|
|
language_opts = [["<<<< #{t('language_default')} >>>>", "default"]]
|
2019-08-19 11:28:48 -04:00
|
|
|
locales.each do |locale|
|
|
|
|
language_mapping = I18n::Language::Mapping.language_mapping_list[locale.to_s.gsub("_", "-")]
|
|
|
|
language_opts.push([language_mapping["nativeName"], locale.to_s])
|
|
|
|
end
|
|
|
|
language_opts.sort
|
|
|
|
end
|
|
|
|
|
2020-05-26 17:37:23 -04:00
|
|
|
# Returns a list of roles that the user can have
|
|
|
|
def role_options
|
2020-06-02 11:12:33 -04:00
|
|
|
Role.editable_roles(@user_domain).where("priority >= ?", current_user.role.priority).by_priority
|
2020-05-26 17:37:23 -04:00
|
|
|
end
|
|
|
|
|
2019-08-19 11:28:48 -04:00
|
|
|
# Parses markdown for rendering.
|
|
|
|
def markdown(text)
|
|
|
|
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
|
|
|
|
no_intra_emphasis: true,
|
|
|
|
fenced_code_blocks: true,
|
|
|
|
disable_indented_code_blocks: true,
|
|
|
|
autolink: true,
|
|
|
|
tables: true,
|
|
|
|
underline: true,
|
|
|
|
highlight: true)
|
|
|
|
|
|
|
|
markdown.render(text).html_safe
|
|
|
|
end
|
2018-05-08 10:41:03 -04:00
|
|
|
end
|