diff --git a/app/assets/stylesheets/admins.scss b/app/assets/stylesheets/admins.scss index 65036144..38c40afc 100644 --- a/app/assets/stylesheets/admins.scss +++ b/app/assets/stylesheets/admins.scss @@ -98,4 +98,4 @@ .admin-tabs { justify-content: space-around; -} +} \ No newline at end of file diff --git a/app/controllers/admins_controller.rb b/app/controllers/admins_controller.rb index d51aeca0..ee963ac3 100644 --- a/app/controllers/admins_controller.rb +++ b/app/controllers/admins_controller.rb @@ -56,12 +56,19 @@ class AdminsController < ApplicationController # GET /admins/server_recordings def server_recordings - server_rooms = rooms_list_for_recordings + @search = params[:search] || "" - @search, @order_column, @order_direction, recs = - all_recordings(server_rooms, params.permit(:search, :column, :direction), true, true) + if @search.present? + if @search.include? "@" + user_email = @search + else + room_uid = @search + end + else + @latest = true + end - @pagy, @recordings = pagy_array(recs) + @pagy, @recordings = pagy_array(recordings_to_show(user_email, room_uid)) end # GET /admins/rooms diff --git a/app/controllers/concerns/populator.rb b/app/controllers/concerns/populator.rb index b7865462..a8df30d6 100644 --- a/app/controllers/concerns/populator.rb +++ b/app/controllers/concerns/populator.rb @@ -56,12 +56,22 @@ module Populator end end - # Returns list of rooms needed to get the recordings on the server - def rooms_list_for_recordings - if Rails.configuration.loadbalanced_configuration - Room.includes(:owner).where(users: { provider: @user_domain }).pluck(:bbb_id) + # Returns the correct recordings based on the users inputs + def recordings_to_show(user = nil, room = nil) + if user.present? + # Find user and get his recordings + rooms = User.find_by(email: user)&.rooms&.pluck(:bbb_id) + return all_recordings(rooms) if user.present? + + [] # return no recs if room not found + elsif room.present? + # Find room and get its recordings + room = Room.find_by(uid: room)&.bbb_id + return all_recordings([room]) if room.present? + + [] else - Room.pluck(:bbb_id) + latest_recordings end end @@ -75,4 +85,36 @@ module Populator list.admins_search(@search).order(updated_at: :desc) end + + private + + # Returns exactly 1 page of the latest recordings + def latest_recordings + return_length = Rails.configuration.pagination_number + recordings = [] + counter = 0 + + # Manually paginate through the rooms + while recordings.length < return_length + rooms = if Rails.configuration.loadbalanced_configuration + Room.includes(:owner) + .where(users: { provider: @user_domain }) + .order(last_session: :desc) + .limit(return_length) + .offset(counter * return_length) + .pluck(:bbb_id) + else + Room.order(last_session: :desc) + .limit(return_length) + .offset(counter * return_length) + .pluck(:bbb_id) + end + + break if rooms.blank? + counter += 1 + recordings.push(*all_recordings(rooms)) + end + + recordings[0..return_length] + end end diff --git a/app/controllers/concerns/recorder.rb b/app/controllers/concerns/recorder.rb index 68607977..0365fb2d 100644 --- a/app/controllers/concerns/recorder.rb +++ b/app/controllers/concerns/recorder.rb @@ -37,7 +37,7 @@ module Recorder def all_recordings(room_bbb_ids, search_params = {}, ret_search_params = false, search_name = false) res = { recordings: [] } - until room_bbb_ids.empty? + until room_bbb_ids.empty? || res[:recordings].length > Rails.configuration.pagination_number # bbb.get_recordings returns an object # take only the array portion of the object that is returned full_res = get_multiple_recordings(room_bbb_ids.pop(Rails.configuration.pagination_number)) diff --git a/app/models/room.rb b/app/models/room.rb index 1d9abf5b..ec8f9d2e 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -51,7 +51,7 @@ class Room < ApplicationRecord # Rely on manual ordering if trying to sort by status return order_by_status(table, running_ids) if column == "status" - return table.order("COALESCE(rooms.last_session,rooms.created_at) DESC") if column == "created_at" + return table.order(Arel.sql("COALESCE(rooms.last_session,rooms.created_at) DESC")) if column == "created_at" return table.order(Arel.sql("rooms.#{column} #{direction}")) if table.column_names.include?(column) diff --git a/app/views/admins/components/_manage_users_table.html.erb b/app/views/admins/components/_manage_users_table.html.erb index f4d00db3..1fbfc3ca 100644 --- a/app/views/admins/components/_manage_users_table.html.erb +++ b/app/views/admins/components/_manage_users_table.html.erb @@ -90,6 +90,11 @@ + <% unless user.rooms.length.zero? %> + <%= link_to admin_recordings_path(search: user.email), class: "dropdown-item" do %> + <%= t("administrator.rooms.table.recordings") %> + <% end %> + <% end %> <%= button_to admin_ban_path(user_uid: user.uid), class: "dropdown-item", "data-disable": "" do %> <%= t("administrator.users.settings.ban") %> <% end %> diff --git a/app/views/admins/components/_recordings.html.erb b/app/views/admins/components/_recordings.html.erb index 8d890fef..6030b692 100644 --- a/app/views/admins/components/_recordings.html.erb +++ b/app/views/admins/components/_recordings.html.erb @@ -93,7 +93,7 @@ <% end %> - <% if !@recordings.empty?%> + <% if !@recordings.empty? && !@latest%>