Skip to content
Snippets Groups Projects
Unverified Commit 73194147 authored by Ahmad Farhat's avatar Ahmad Farhat Committed by GitHub
Browse files

Auto delete recordings from BBB server when deleting a room (#5330)

* Auto delete recordings from BBB server when deleting a room

* Fix flaky test
parent b5506967
Branches
Tags
No related merge requests found
......@@ -46,6 +46,9 @@ RSpec/MultipleMemoizedHelpers:
RSpec/NestedGroups:
Max: 7
RSpec/StubbedMock:
Enabled: false
# Enable having lines with up to 150 charachters in length.
Layout/LineLength:
Max: 150
......
......@@ -56,9 +56,6 @@ module Api
# DELETE /api/v1/recordings/:id.json
# Deletes a recording in both BigBlueButton and Greenlight
def destroy
# TODO: Hadi - Need to change this to work preferably with after_destroy in recordings model
BigBlueButtonApi.new(provider: current_provider).delete_recordings(record_ids: params[:id])
Recording.destroy_by(record_id: params[:id])
render_data status: :ok
......
......@@ -38,6 +38,8 @@ class Recording < ApplicationRecord
scope :with_provider, ->(current_provider) { where(user: { provider: current_provider }) }
after_destroy :destroy_bbb_recording
def self.search(input)
if input
return joins(:formats).where('recordings.name ILIKE :input OR recordings.visibility ILIKE :input OR formats.recording_type ILIKE :input',
......@@ -68,4 +70,10 @@ class Recording < ApplicationRecord
all.includes(:formats)
end
private
def destroy_bbb_recording
BigBlueButtonApi.new(provider: user.provider).delete_recordings(record_ids: record_id)
end
end
......@@ -152,6 +152,8 @@ RSpec.describe Api::V1::RoomsController, type: :controller do
end
it 'deletes the recordings associated with the room' do
allow_any_instance_of(BigBlueButtonApi).to receive(:delete_recordings).and_return(true)
room = create(:room, user:)
create_list(:recording, 10, room:)
expect { delete :destroy, params: { friendly_id: room.friendly_id } }.to change(Recording, :count).by(-10)
......
......@@ -116,4 +116,12 @@ RSpec.describe Recording, type: :model do
expect(described_class.all.search('')).to match_array(described_class.all)
end
end
describe 'after_destroy' do
it 'makes a call to BBB to delete the recording' do
expect_any_instance_of(BigBlueButtonApi).to receive(:delete_recordings).and_return(true)
create(:recording).destroy
end
end
end
......@@ -23,6 +23,10 @@ describe RecordingsSync, type: :service do
let(:room) { create(:room, user:, recordings_processing: 5) }
let(:service) { described_class.new(room:, provider: 'greenlight') }
before do
allow_any_instance_of(BigBlueButtonApi).to receive(:delete_recordings).and_return(true)
end
describe '#call' do
let(:fake_recording_creator) { instance_double(RecordingCreator) }
let(:other_recordings) { create_list(:recording, 2) }
......@@ -61,7 +65,7 @@ describe RecordingsSync, type: :service do
expect(RecordingCreator).to receive(:new).with(recording: multiple_recordings_response[:recordings][1]).and_call_original
service.call
expect(Recording.where(id: other_recordings.pluck(:id))).to eq(other_recordings)
expect(Recording.where(id: other_recordings.pluck(:id))).to match_array(other_recordings)
end
it 'resets the recordings processing value for the room' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment