From 8ff05643dc6687639a711df942727640e40bf1c5 Mon Sep 17 00:00:00 2001
From: farhatahmad <35435341+farhatahmad@users.noreply.github.com>
Date: Mon, 4 Feb 2019 11:21:42 -0500
Subject: [PATCH] Added a Recordings page where the user can see all recordings
(#352)
---
app/controllers/rooms_controller.rb | 40 ++++-------------
app/controllers/users_controller.rb | 23 ++++++++++
app/helpers/recordings_helper.rb | 45 +++++++++++++++++++
app/views/shared/_header.html.erb | 3 ++
.../shared/components/_recording_row.html.erb | 6 +--
app/views/users/recordings.html.erb | 21 +++++++++
config/routes.rb | 3 ++
spec/controllers/users_controller_spec.rb | 13 ++++++
8 files changed, 120 insertions(+), 34 deletions(-)
create mode 100644 app/helpers/recordings_helper.rb
create mode 100644 app/views/users/recordings.html.erb
diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb
index 5f20b2ed..bd4fd8a1 100644
--- a/app/controllers/rooms_controller.rb
+++ b/app/controllers/rooms_controller.rb
@@ -22,6 +22,7 @@ class RoomsController < ApplicationController
before_action :find_room, except: :create
before_action :verify_room_ownership, except: [:create, :show, :join, :logout]
+ include RecordingsHelper
META_LISTED = "gl-listed"
# POST /
@@ -43,7 +44,12 @@ class RoomsController < ApplicationController
# GET /:room_uid
def show
if current_user && @room.owned_by?(current_user)
- @recordings = @room.recordings
+ recs = @room.recordings
+ # Add the room id to each recording object
+ recs.each do |rec|
+ rec[:room_uid] = @room.uid
+ end
+ @recordings = recs
@is_running = @room.running?
else
render :join
@@ -137,38 +143,10 @@ class RoomsController < ApplicationController
def delete_recording
@room.delete_recording(params[:record_id])
- redirect_to current_user.main_room
+ # Redirects to the page that made the initial request
+ redirect_to request.referrer
end
- # Helper for converting BigBlueButton dates into the desired format.
- def recording_date(date)
- date.strftime("%B #{date.day.ordinalize}, %Y.")
- end
- helper_method :recording_date
-
- # Helper for converting BigBlueButton dates into a nice length string.
- def recording_length(playbacks)
- # Stats format currently doesn't support length.
- valid_playbacks = playbacks.reject { |p| p[:type] == "statistics" }
- return "0 min" if valid_playbacks.empty?
-
- len = valid_playbacks.first[:length]
- if len > 60
- "#{(len / 60).round} hrs"
- elsif len == 0
- "< 1 min"
- else
- "#{len} min"
- end
- end
- helper_method :recording_length
-
- # Prevents single images from erroring when not passed as an array.
- def safe_recording_images(images)
- Array.wrap(images)
- end
- helper_method :safe_recording_images
-
private
def update_room_attributes
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 3ed56ede..8b4da1e2 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -20,6 +20,8 @@ class UsersController < ApplicationController
before_action :find_user, only: [:edit, :update, :destroy]
before_action :ensure_unauthenticated, only: [:new, :create]
+ include RecordingsHelper
+
# POST /u
def create
# Verify that GreenLight is configured to allow user signup.
@@ -109,6 +111,27 @@ class UsersController < ApplicationController
redirect_to root_path
end
+ # GET /u/:user_uid/recordings
+ def recordings
+ if current_user && current_user.uid == params[:user_uid]
+ @recordings = []
+ current_user.rooms.each do |room|
+ # Check that current user is the room owner
+ next unless room.owner == current_user
+
+ recs = room.recordings
+ # Add the room id to each recording object
+ recs.each do |rec|
+ rec[:room_uid] = room.uid
+ end
+ # Adds an array to another array
+ @recordings.push(*recs)
+ end
+ else
+ redirect_to root_path
+ end
+ end
+
# GET | POST /terms
def terms
redirect_to '/404' unless Rails.configuration.terms
diff --git a/app/helpers/recordings_helper.rb b/app/helpers/recordings_helper.rb
new file mode 100644
index 00000000..1ae463e1
--- /dev/null
+++ b/app/helpers/recordings_helper.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
+#
+# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
+#
+# This program is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free Software
+# Foundation; either version 3.0 of the License, or (at your option) any later
+# version.
+#
+# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with BigBlueButton; if not, see