Passed
Push — master ( 02b342...4fc171 )
by Jesus
04:50
created

UsersHelper.disabled_roles()   A

Complexity

Conditions 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 15
rs 9.65
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
module UsersHelper
20
  def recaptcha_enabled?
21
    Rails.configuration.recaptcha_enabled
22
  end
23
24
  def disabled_roles(user)
25
    current_user_role = current_user.highest_priority_role
26
27
    # Admins are able to remove the admin role from other admins
28
    # For all other roles they can only add/remove roles with a higher priority
29
    disallowed_roles = if current_user_role.name == "admin"
30
                          Role.editable_roles(@user_domain).where("priority < #{current_user_role.priority}")
31
                              .pluck(:id)
32
                        else
33
                          Role.editable_roles(@user_domain).where("priority <= #{current_user_role.priority}")
34
                              .pluck(:id)
35
                       end
36
37
    user.roles.by_priority.pluck(:id) | disallowed_roles
38
  end
39
end
40