Passed
Push — master ( 33ca92...23b088 )
by Ahmad
10:28
created

Ability   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 11

1 Method

Rating   Name   Duplication   Size   Complexity  
C initialize() 0 29 11
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
class Ability
20
  include CanCan::Ability
21
22
  def initialize(user)
23
    if !user
24
      cannot :manage, AdminsController
25
    elsif user.has_role? :super_admin
26
      can :manage, :all
27
    else
28
      highest_role = user.role
29
      if highest_role.get_permission("can_edit_site_settings")
30
        can [:site_settings, :room_configuration, :update_settings,
31
             :update_room_configuration, :coloring, :registration_method, :log_level], :admin
32
      end
33
34
      if highest_role.get_permission("can_edit_roles")
35
        can [:roles, :new_role, :change_role_order, :update_role, :delete_role], :admin
36
      end
37
38
      if highest_role.get_permission("can_manage_users")
39
        can [:index, :edit_user, :promote, :demote, :ban_user, :unban_user,
40
             :approve, :invite, :reset, :undelete, :merge_user], :admin
41
      end
42
43
      can [:server_recordings, :server_rooms], :admin if highest_role.get_permission("can_manage_rooms_recordings")
44
45
      if !highest_role.get_permission("can_edit_site_settings") && !highest_role.get_permission("can_edit_roles") &&
46
         !highest_role.get_permission("can_manage_users") && !highest_role.get_permission("can_manage_rooms_recordings")
47
        cannot :manage, AdminsController
48
      end
49
    end
50
  end
51
end
52