diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 5f20b2ed77e5f669fc912ac75b1a75012b2a963b..bd4fd8a12d71e1105b28c8bf4f1ff7ef966c3d7d 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,37 +143,9 @@ class RoomsController < ApplicationController def delete_recording @room.delete_recording(params[:record_id]) - redirect_to current_user.main_room - 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) + # Redirects to the page that made the initial request + redirect_to request.referrer end - helper_method :safe_recording_images private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3ed56ede389cc83ca53468d3e8a1cf4187b4b4d4..8b4da1e27710b7e8d4df6a42342b57962eb8f4bc 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 0000000000000000000000000000000000000000..1ae463e14910d609d81d9817ea5d6132c30abff6 --- /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 <http://www.gnu.org/licenses/>. + +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 200100f132f88eb8565cecc45ddf704d2d4b6783..236ef3904adb576baf9bf5966c24ca80de1da901 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 %> <i class="dropdown-icon fas fa-home"></i> <%= t("header.dropdown.home") %> <% end %> + <%= link_to get_user_recordings_path(current_user), class: "dropdown-item" do %> + <i class="dropdown-icon fas fa-video"></i> <%= t("room.recordings") %> + <% end %> <%= link_to edit_user_path(current_user), class: "dropdown-item" do %> <i class="dropdown-icon fas fa-cog"></i> <%= 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 eed8afd542645136f1e9ef6cd4457a0bd412e9bd..ddfa1315c6d36371852484496e57085087d25471 100644 --- a/app/views/shared/components/_recording_row.html.erb +++ b/app/views/shared/components/_recording_row.html.erb @@ -53,10 +53,10 @@ <button class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown"><i class="dropdown-icon fas fa-link px-2"></i> <%= t("recording.visibility.unlisted") %></button> <% end %> <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> - <%= button_to update_recording_path(@room, record_id: recording[:recordID], state: "public"), class: "dropdown-item" do %> + <%= button_to update_recording_path(room_uid: recording[:room_uid], record_id: recording[:recordID], state: "public"), class: "dropdown-item" do %> <i class="dropdown-icon fas fa-globe"></i> <%= t("recording.visibility.public") %> <% end %> - <%= button_to update_recording_path(@room, record_id: recording[:recordID], state: "unlisted"), class: "dropdown-item" do %> + <%= button_to update_recording_path(room_uid: recording[:room_uid], record_id: recording[:recordID], state: "unlisted"), class: "dropdown-item" do %> <i class="dropdown-icon fas fa-link"></i> <%= t("recording.visibility.unlisted") %> <% end %> </div> @@ -78,7 +78,7 @@ <a class="dropdown-item email-link" data-pres-link="<%= p[:url] %>"><i class="dropdown-icon far fa-envelope"></i> <%= t("recording.email") %></a> <div class="dropdown-divider"></div> <% 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 %> <i class="dropdown-icon far fa-trash-alt"></i> <%= t("delete") %> <% end %> </div> diff --git a/app/views/users/recordings.html.erb b/app/views/users/recordings.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..f66442bd652d4ab191ab366db0e787e38900fe3f --- /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 <http://www.gnu.org/licenses/>. +%> + +<% +# 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 ad63dc2c7a0342e8be4a2744da5c0df668480873..b6846ed36b239a51c43907b2638e369fef947eeb 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 3d507d386da62cae7a2f7b3bbea3fa7c5ae57ba0..e29f990bff6a0d74793160c8847072cf27401128 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