Passed
Push — master ( 6bc43d...2da2ee )
by Ahmad
07:04
created

Populator.manage_users_list()   B

Complexity

Conditions 7

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
dl 0
loc 29
rs 7.784
c 0
b 0
f 0
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 Populator
20
  extend ActiveSupport::Concern
21
22
  # Returns a list of users that are in the same context of the current user
23
  def manage_users_list
24
    current_role = @role
25
26
    initial_user = case @tab
27
      when "active"
28
        User.includes(:roles).without_role(:pending).without_role(:denied)
29
      when "deleted"
30
        User.includes(:roles).deleted
31
      else
32
        User.includes(:roles)
33
    end
34
35
    current_role = Role.find_by(name: @tab, provider: @user_domain) if @tab == "pending" || @tab == "denied"
36
37
    initial_list = if current_user.has_role? :super_admin
38
      initial_user.where.not(id: current_user.id)
39
    else
40
      initial_user.without_role(:super_admin).where.not(id: current_user.id)
41
    end
42
43
    if Rails.configuration.loadbalanced_configuration
44
      initial_list.where(provider: @user_domain)
45
                  .admins_search(@search, current_role)
46
                  .admins_order(@order_column, @order_direction)
47
    else
48
      initial_list.admins_search(@search, current_role)
49
                  .admins_order(@order_column, @order_direction)
50
    end
51
  end
52
53
  # Returns a list of rooms that are in the same context of the current user
54
  def server_rooms_list
55
    if Rails.configuration.loadbalanced_configuration
56
      Room.includes(:owner).where(users: { provider: @user_domain })
57
          .admins_search(@search)
58
          .admins_order(@order_column, @order_direction)
59
    else
60
      Room.includes(:owner).all.admins_search(@search).admins_order(@order_column, @order_direction)
61
    end
62
  end
63
64
  # Returns list of rooms needed to get the recordings on the server
65
  def rooms_list_for_recordings
66
    if Rails.configuration.loadbalanced_configuration
67
      Room.includes(:owner).where(users: { provider: @user_domain }).pluck(:bbb_id)
68
    else
69
      Room.pluck(:bbb_id)
70
    end
71
  end
72
73
  # Returns a list of users that are in the same context of the current user
74
  def shared_user_list
75
    roles_can_appear = []
76
    Role.where(provider: @user_domain).each do |role|
77
      roles_can_appear << role.name if role.get_permission("can_appear_in_share_list") && role.priority >= 0
78
    end
79
80
    initial_list = User.where.not(uid: current_user.uid)
81
                       .without_role(:pending)
82
                       .without_role(:denied)
83
                       .with_highest_priority_role(roles_can_appear)
84
85
    return initial_list unless Rails.configuration.loadbalanced_configuration
86
    initial_list.where(provider: @user_domain)
87
  end
88
89
  # Returns a list of users that can merged into another user
90
  def merge_user_list
91
    initial_list = User.where.not(uid: current_user.uid).without_role(:super_admin)
92
93
    return initial_list unless Rails.configuration.loadbalanced_configuration
94
    initial_list.where(provider: @user_domain)
95
  end
96
end
97