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 . + +module RecordingsHelper + # Helper for converting BigBlueButton dates into the desired format. + def recording_date(date) + date.strftime("%B #{date.day.ordinalize}, %Y.") + end + + # 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 + + # Prevents single images from erroring when not passed as an array. + def safe_recording_images(images) + Array.wrap(images) + end +end diff --git a/app/views/shared/_header.html.erb b/app/views/shared/_header.html.erb index 200100f1..236ef390 100755 --- a/app/views/shared/_header.html.erb +++ b/app/views/shared/_header.html.erb @@ -40,6 +40,9 @@ <%= link_to current_user.main_room, class: "dropdown-item" do %> <%= t("header.dropdown.home") %> <% end %> + <%= link_to get_user_recordings_path(current_user), class: "dropdown-item" do %> + <%= t("room.recordings") %> + <% end %> <%= link_to edit_user_path(current_user), class: "dropdown-item" do %> <%= t("header.dropdown.settings") %> <% end %> diff --git a/app/views/shared/components/_recording_row.html.erb b/app/views/shared/components/_recording_row.html.erb index eed8afd5..ddfa1315 100644 --- a/app/views/shared/components/_recording_row.html.erb +++ b/app/views/shared/components/_recording_row.html.erb @@ -53,10 +53,10 @@ <% end %> @@ -78,7 +78,7 @@ <%= t("recording.email") %> <% end %> - <%= button_to delete_recording_path(@room, record_id: recording[:recordID]), method: :delete, class: "dropdown-item" do %> + <%= button_to delete_recording_path(room_uid: recording[:room_uid], record_id: recording[:recordID]), method: :delete, class: "dropdown-item" do %> <%= t("delete") %> <% end %> diff --git a/app/views/users/recordings.html.erb b/app/views/users/recordings.html.erb new file mode 100644 index 00000000..f66442bd --- /dev/null +++ b/app/views/users/recordings.html.erb @@ -0,0 +1,21 @@ +<% +# 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 . +%> + +<% +# shared/sessions is a partial, meaning it can't be rendered through the controller +# without losing all css +%> + +<%= render "shared/sessions", recordings: @recordings, only_public: false %> diff --git a/config/routes.rb b/config/routes.rb index ad63dc2c..b6846ed3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -52,6 +52,9 @@ Rails.application.routes.draw do get '/:user_uid/edit', to: 'users#edit', as: :edit_user patch '/:user_uid/edit', to: 'users#update', as: :update_user delete '/:user_uid', to: 'users#destroy', as: :delete_user + + # All user recordings + get '/:user_uid/recordings', to: 'users#recordings', as: :get_user_recordings end # Handles Omniauth authentication. diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 3d507d38..e29f990b 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -231,4 +231,17 @@ describe UsersController, type: :controller do expect(response).to render_template(:verify) end end + + describe "GET #recordings" do + before do + @user1 = create(:user) + @user2 = create(:user) + end + + it "redirects to root if the incorrect user tries to access the page" do + get :recordings, params: { current_user: @user2, user_uid: @user1.uid } + + expect(response).to redirect_to(root_path) + end + end end