From 3987a8b913efe4498f48bd0cc5811c23f4eef884 Mon Sep 17 00:00:00 2001
From: Ahmad Farhat <ahmad.af.farhat@gmail.com>
Date: Sun, 19 Sep 2021 14:14:53 -0400
Subject: [PATCH] Added support for protected recordings (#2907)

---
 app/controllers/concerns/bbb_server.rb             | 14 ++++++++++++++
 app/controllers/recordings_controller.rb           |  6 ++++++
 app/helpers/application_helper.rb                  |  5 +++++
 .../shared/components/_recording_row.html.erb      |  7 +++++++
 4 files changed, 32 insertions(+)

diff --git a/app/controllers/concerns/bbb_server.rb b/app/controllers/concerns/bbb_server.rb
index 1346f187..26d9ea2d 100644
--- a/app/controllers/concerns/bbb_server.rb
+++ b/app/controllers/concerns/bbb_server.rb
@@ -119,6 +119,20 @@ module BbbServer
     bbb_server.publish_recordings(record_id, false)
   end
 
+  # Protect a recording
+  def protect_recording(record_id, meta = {})
+    meta[:recordID] = record_id
+    meta[:protect] = true
+    bbb_server.send_api_request("updateRecordings", meta)
+  end
+
+  # Unprotect a recording
+  def unprotect_recording(record_id, meta = {})
+    meta[:recordID] = record_id
+    meta[:protect] = false
+    bbb_server.send_api_request("updateRecordings", meta)
+  end
+
   # Deletes a recording from a room.
   def delete_recording(record_id)
     bbb_server.delete_recordings(record_id)
diff --git a/app/controllers/recordings_controller.rb b/app/controllers/recordings_controller.rb
index f3e200ba..54b9d784 100644
--- a/app/controllers/recordings_controller.rb
+++ b/app/controllers/recordings_controller.rb
@@ -28,6 +28,12 @@ class RecordingsController < ApplicationController
       "meta_#{META_LISTED}" => (params[:state] == "public"),
     }
 
+    if params[:state] == "protected"
+      protect_recording(params[:record_id])
+    else
+      unprotect_recording(params[:record_id])
+    end
+
     if params[:state] == "inaccessible"
       unpublish_recording(params[:record_id])
     else
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 6e752d0b..550c71a2 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -147,4 +147,9 @@ module ApplicationHelper
       current_user&.role&.get_permission("can_launch_recording")
     end
   end
+
+  # Returns true if protected recordings is enabled on BigBlueButton/Scalelite server
+  def protected_recording?(rec)
+    !rec[:protected].nil?
+  end
 end
diff --git a/app/views/shared/components/_recording_row.html.erb b/app/views/shared/components/_recording_row.html.erb
index a6c4cb3c..091fbc15 100644
--- a/app/views/shared/components/_recording_row.html.erb
+++ b/app/views/shared/components/_recording_row.html.erb
@@ -52,6 +52,8 @@
     <div class="dropdown">
       <% if recording[:metadata][:"gl-listed"] == "true" %>
         <button class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown"><i class="dropdown-icon fas fa-globe px-2"></i> <%= t("recording.visibility.public") %></button>
+      <% elsif recording[:protected] == "true" %>
+        <button class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown"><i class="dropdown-icon fas fa-shield-alt px-2"></i> <%= t("recording.visibility.protected") %></button>
       <% elsif !recording[:published] %>
         <button class="btn btn-sm btn-secondary dropdown-toggle" data-toggle="dropdown"><i class="dropdown-icon fas fa-lock px-2"></i> <%= t("recording.visibility.inaccessible") %></button>
       <% else %>
@@ -61,6 +63,11 @@
         <%= button_to update_recording_path(meetingID: recording[:meetingID], record_id: recording[:recordID], state: "public"), class: "dropdown-item", "data-disable": "" do %>
           <i class="dropdown-icon fas fa-globe"></i> <%= t("recording.visibility.public") %>
         <% end %>
+        <% if protected_recording?(recording) %>
+          <%= button_to update_recording_path(meetingID: recording[:meetingID], record_id: recording[:recordID], state: "protected"), class: "dropdown-item", "data-disable": "" do %>
+            <i class="dropdown-icon fas fa-shield-alt"></i> <%= t("recording.visibility.protected") %>
+          <% end %>
+        <% end %>
         <%= button_to update_recording_path(meetingID: recording[:meetingID], record_id: recording[:recordID], state: "unlisted"), class: "dropdown-item", "data-disable": "" do %>
           <i class="dropdown-icon fas fa-link"></i> <%= t("recording.visibility.unlisted") %>
         <% end %>
-- 
GitLab