Passed
Push — master ( 23b088...27bc68 )
by Ahmad
06:31
created

Populator.recordings_to_show()   A

Complexity

Conditions 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 17
rs 9.0833
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
    initial_list = case @tab
25
      when "active"
26
        User.without_role([:pending, :denied])
27
      when "deleted"
28
        User.deleted
29
      when "pending"
30
        User.with_role(:pending)
31
      when "denied"
32
        User.with_role(:denied)
33
      else
34
        User.all
35
    end
36
37
    initial_list = initial_list.with_role(@role.name) if @role.present?
38
39
    initial_list = initial_list.without_role(:super_admin)
40
41
    initial_list = initial_list.where(provider: @user_domain) if Rails.configuration.loadbalanced_configuration
42
43
    initial_list.where.not(id: current_user.id)
44
                .admins_search(@search)
45
                .admins_order(@order_column, @order_direction)
46
  end
47
48
  # Returns a list of rooms that are in the same context of the current user
49
  def server_rooms_list
50
    if Rails.configuration.loadbalanced_configuration
51
      Room.includes(:owner).where(users: { provider: @user_domain })
52
          .admins_search(@search)
53
          .admins_order(@order_column, @order_direction, @running_room_bbb_ids)
54
    else
55
      Room.includes(:owner).admins_search(@search).admins_order(@order_column, @order_direction, @running_room_bbb_ids)
56
    end
57
  end
58
59
  # Returns the correct recordings based on the users inputs
60
  def recordings_to_show(user = nil, room = nil)
61
    if user.present?
62
      # Find user and get his recordings
63
      rooms = User.find_by(email: user)&.rooms&.pluck(:bbb_id)
64
      return all_recordings(rooms) if user.present?
65
66
      [] # return no recs if room not found
67
    elsif room.present?
68
      # Find room and get its recordings
69
      room = Room.find_by(uid: room)&.bbb_id
70
      return all_recordings([room]) if room.present?
71
72
      []
73
    else
74
      latest_recordings
75
    end
76
  end
77
78
  # Returns a list off all current invitations
79
  def invited_users_list
80
    list = if Rails.configuration.loadbalanced_configuration
81
      Invitation.where(provider: @user_domain)
82
    else
83
      Invitation.all
84
    end
85
86
    list.admins_search(@search).order(updated_at: :desc)
87
  end
88
89
  private
90
91
  # Returns exactly 1 page of the latest recordings
92
  def latest_recordings
93
    return_length = Rails.configuration.pagination_number
94
    recordings = []
95
    counter = 0
96
97
    # Manually paginate through the rooms
98
    while recordings.length < return_length
99
      rooms = if Rails.configuration.loadbalanced_configuration
100
        Room.includes(:owner)
101
            .where(users: { provider: @user_domain })
102
            .order(last_session: :desc)
103
            .limit(return_length)
104
            .offset(counter * return_length)
105
            .pluck(:bbb_id)
106
      else
107
        Room.order(last_session: :desc)
108
            .limit(return_length)
109
            .offset(counter * return_length)
110
            .pluck(:bbb_id)
111
      end
112
113
      break if rooms.blank?
114
      counter += 1
115
      recordings.push(*all_recordings(rooms))
116
    end
117
118
    recordings[0..return_length]
119
  end
120
end
121