Skip to content

Commit

Permalink
LTI-150: do not use cache for protected recordings (#146)
Browse files Browse the repository at this point in the history
Everytime a request to a protected recording is made, make an API call
to retrieve the recording.

Co-authored-by: Jesus Federico <[email protected]>
  • Loading branch information
Mariam05 and jfederico authored Sep 15, 2022
1 parent 75aa47d commit dbcbacd
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 34 deletions.
19 changes: 19 additions & 0 deletions app/controllers/concerns/bbb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.

require 'bbb_app_rooms/user'
require 'json'

class RoomsController < ApplicationController
# Include libraries.
Expand Down Expand Up @@ -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?

Expand Down
111 changes: 77 additions & 34 deletions app/views/shared/components/_recording_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,45 +64,88 @@
<div class="flex items-end ">
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full" >
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2" fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full" >
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2" fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
</div>
</div>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2 " fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M11 3.055A9.001 9.001 0 1020.945 13H11V3.055z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M20.488 9H15V3.512A9.025 9.025 0 0120.488 9z" />
</svg>
</div>
</div>
</div>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2 " fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M11 3.055A9.001 9.001 0 1020.945 13H11V3.055z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M20.488 9H15V3.512A9.025 9.025 0 0120.488 9z" />
</svg>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2 " fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
</div>
</div>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2 " fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full" >
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2" fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
</svg>
</div>
</div>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2 " fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M11 3.055A9.001 9.001 0 1020.945 13H11V3.055z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M20.488 9H15V3.512A9.025 9.025 0 0120.488 9z" />
</svg>
</div>
</div>
</div>
<% 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 %>
<div class="bg-gray-200 p-2 rounded hover:bg-gray-300">
<div class= "bg-bbb-blue rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 bg-bbb-blue text-white m-2 " fill="none" viewBox="0 0 22 22" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
</div>
<% end %>
<% end %>
<% end %> <%# end of unless %>
<% end %> <%# end of sorted playbacks %>
<% end %> <%# end of if protected %>
<% end %> <%# end of if published %>
</div>
</td>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dbcbacd

Please sign in to comment.