From dbcbacd94670f2aafb572ab8f3d5fc7fa74f6aae Mon Sep 17 00:00:00 2001 From: Mariam A Date: Thu, 15 Sep 2022 12:02:59 -0400 Subject: [PATCH] LTI-150: do not use cache for protected recordings (#146) Everytime a request to a protected recording is made, make an API call to retrieve the recording. Co-authored-by: Jesus Federico --- app/controllers/concerns/bbb_helper.rb | 19 +++ app/controllers/rooms_controller.rb | 16 +++ .../shared/components/_recording_row.html.erb | 111 ++++++++++++------ config/routes.rb | 1 + 4 files changed, 113 insertions(+), 34 deletions(-) diff --git a/app/controllers/concerns/bbb_helper.rb b/app/controllers/concerns/bbb_helper.rb index dab3b642..7cf29723 100644 --- a/app/controllers/concerns/bbb_helper.rb +++ b/app/controllers/concerns/bbb_helper.rb @@ -107,6 +107,25 @@ def recordings recordings_formatted(res) end + # Fetch an individual recording + def recording(record_id) + r = bbb.get_recordings(meetingID: @room.handler, recordID: record_id) + unless r.key?(:error) + + r[:playbacks] = if !r[:playback] || !r[:playback][:format] + [] + elsif r[:playback][:format].is_a?(Array) + r[:playback][:format] + else + [r[:playback][:format]] + end + + r.delete(:playback) + end + + r[:recordings][0] + end + def server_running? begin bbb.get_meeting_info(@room.handler, @user) diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index c3432b27..4f98f945 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -17,6 +17,7 @@ # with BigBlueButton; if not, see . require 'bbb_app_rooms/user' +require 'json' class RoomsController < ApplicationController # Include libraries. @@ -190,6 +191,21 @@ def recording_delete redirect_to(room_path(params[:id], launch_nonce: params[:launch_nonce])) end + # POST /rooms/:id/recording/:record_id/:format/recording + # Makes an API call to the BBB server to retrieve an individual recording + # Used in the case of protected recordings because they can't be cached. + def individual_recording + rec = recording(params[:record_id]) + formats_arr = rec[:playback][:format] + format_obj = formats_arr.find { |i| i[:type] == params[:format] } + + playback_url = format_obj[:url] + + redirect_to(playback_url) && return unless playback_url.nil? + + redirect_to(errors_path(401)) + end + helper_method :recording_date, :recording_length, :meeting_running?, :bigbluebutton_moderator_roles, :bigbluebutton_recording_public_formats, :meeting_info, :bigbluebutton_recording_enabled, :server_running? diff --git a/app/views/shared/components/_recording_row.html.erb b/app/views/shared/components/_recording_row.html.erb index 47c239c2..5a8aed34 100644 --- a/app/views/shared/components/_recording_row.html.erb +++ b/app/views/shared/components/_recording_row.html.erb @@ -64,45 +64,88 @@
<% if recording[:published] %> <% sorted_playbacks = recording[:playbacks].sort_by { |hsh| hsh[:type] }%> - <% sorted_playbacks.each do |p| %> - <% # Don't show playback if user isn't moderator and the type isn't set as public %> - <% unless !(@user.admin? || @user.moderator?(bigbluebutton_moderator_roles)) && !bigbluebutton_recording_public_formats.include?(p[:type]) %> - <% if p[:type] == 'presentation' %> - <%= link_to p[:url], :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank", class: "mr-4 hover:bg-white hover:text-blue-700" do %> -
-
- - + <% if recording[:protected] != nil && recording[:protected] == "true" # check if protected field exists %> + <% sorted_playbacks.each do |p| %> + <% # Don't show playback if user isn't moderator and the type isn't set as public %> + <% unless !(@user.admin? || @user.moderator?(bigbluebutton_moderator_roles)) && !bigbluebutton_recording_public_formats.include?(p[:type]) %> + <% if p[:type] == 'presentation' %> + <%= link_to show_recording_path(@room, :launch_nonce => @launch_nonce, record_id: recording[:recordID], format: :presentation), method: :post, :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank", class: "mr-4 hover:bg-white hover:text-blue-700" do %> +
+
+ + + +
+
+ <% end %> + <% elsif p[:type] == 'statistics' %> + <%= link_to show_recording_path(@room, :launch_nonce => @launch_nonce, record_id: recording[:recordID], format: :statistics), method: :post, :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank" , class: "mr-4 hover:bg-white hover:text-blue-700 " do %> +
+
+ + + +
-
- <% end %> - <% elsif p[:type] == 'statistics' %> - <%= link_to p[:url], :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank" , class: "mr-4 hover:bg-white hover:text-blue-700 " do %> -
-
- - - - + <% end %> + <% elsif p[:type] == 'video' %> + <%= link_to show_recording_path(@room, :launch_nonce => @launch_nonce, record_id: recording[:recordID], format: :video), method: :post, :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank", class: "hover:bg-white hover:text-blue-700" do %> +
+
+ + + + +
-
+ <% end %> <% end %> - <% elsif p[:type] == 'video' %> - <%= link_to p[:url], :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank", class: "hover:bg-white hover:text-blue-700" do %> -
-
- - - - + <% end # for unless %> + <% end #for sorted playbacks loop %> + + <% else # if recording not protected %> + + <% sorted_playbacks.each do |p| %> + <% # Don't show playback if user isn't moderator and the type isn't set as public %> + <% unless !(@user.admin? || @user.moderator?(bigbluebutton_moderator_roles)) && !bigbluebutton_recording_public_formats.include?(p[:type]) %> + <% if p[:type] == 'presentation' %> + <%= link_to p[:url], :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank", class: "mr-4 hover:bg-white hover:text-blue-700" do %> +
+
+ + + +
+
+ <% end %> + <% elsif p[:type] == 'statistics' %> + <%= link_to p[:url], :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank" , class: "mr-4 hover:bg-white hover:text-blue-700 " do %> +
+
+ + + + +
-
- <% end %> - <% end %> - <% end %> - <% end %> - <% end %> + <% end %> + <% elsif p[:type] == 'video' %> + <%= link_to p[:url], :'data-toggle' => 'tooltip' , title: p[:type], target: "_blank", class: "hover:bg-white hover:text-blue-700" do %> +
+
+ + + + +
+
+ <% end %> + <% end %> + <% end %> <%# end of unless %> + <% end %> <%# end of sorted playbacks %> + <% end %> <%# end of if protected %> + <% end %> <%# end of if published %>
diff --git a/config/routes.rb b/config/routes.rb index 2745111e..8204179d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,6 +44,7 @@ post '/unprotect', to: 'rooms#recording_unprotect', as: :recording_unprotect post '/update', to: 'rooms#recording_update', as: :recording_update post '/delete', to: 'rooms#recording_delete', as: :recording_delete + post '/:format/recording', to: 'rooms#individual_recording', as: :show_recording end # Handles launches.