Skip to content

Commit

Permalink
Auto delete recordings from BBB server when deleting a room (#5330)
Browse files Browse the repository at this point in the history
* Auto delete recordings from BBB server when deleting a room

* Fix flaky test
  • Loading branch information
farhatahmad authored Jul 14, 2023
1 parent b550696 commit 7319414
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/api/v1/recordings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ def update
# 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
Expand Down
8 changes: 8 additions & 0 deletions app/models/recording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -68,4 +70,10 @@ def self.server_search(input)

all.includes(:formats)
end

private

def destroy_bbb_recording
BigBlueButtonApi.new(provider: user.provider).delete_recordings(record_ids: record_id)
end
end
2 changes: 2 additions & 0 deletions spec/controllers/rooms_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
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)
Expand Down
8 changes: 8 additions & 0 deletions spec/models/recording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,12 @@
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
6 changes: 5 additions & 1 deletion spec/services/recordings_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
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) }
Expand Down Expand Up @@ -61,7 +65,7 @@
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
Expand Down

0 comments on commit 7319414

Please sign in to comment.