Skip to content
Snippets Groups Projects
Unverified Commit 8c2d62db authored by Khemissi Amir's avatar Khemissi Amir Committed by GitHub
Browse files

Backend: Added recording update name. (#3514)

Todo:
		- Frontend.
parent dec666db
Branches
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ module Api
module V1
class RecordingsController < ApiController
skip_before_action :verify_authenticity_token # TODO: - Revisit this.
before_action :find_recording, only: :update
# GET /api/v1/recordings.json
# Returns: { data: Array[serializable objects(recordings)] , errors: Array[String] }
......@@ -37,6 +38,19 @@ module Api
render_json(status: :ok)
end
# PUT/PATCH /api/v1/recordings/:recording_id.json
# Returns: { data: Array[serializable objects(recordings)] , errors: Array[String] }
# Does: Update the recording name.
def update
new_name = recording_params[:name]
return render_json errors: [Rails.configuration.custom_error_msgs[:missing_params]], status: :bad_request if new_name.blank?
BigBlueButtonApi.new.update_recordings record_id: @recording.record_id, meta_hash: { meta_name: new_name }
Recording.update! @recording.id, name: new_name
render_json
end
def resync
RecordingsSync.new(user: current_user).call
......@@ -57,6 +71,16 @@ module Api
render_json(status: :ok)
end
private
def recording_params
params.require(:recording).permit(:name)
end
def find_recording
@recording = Recording.find_by! record_id: params[:id]
end
end
end
end
......@@ -40,6 +40,10 @@ class BigBlueButtonApi
bbb_server.publish_recordings(record_ids, publish)
end
def update_recordings(record_id:, meta_hash:)
bbb_server.update_recordings(record_id, {}, meta_hash)
end
private
def bbb_endpoint
......
......@@ -22,7 +22,9 @@ class RecordingsSync
# Get length of presentation format(s)
length = get_recording_length(recording:)
new_recording = Recording.create(room_id:, name: recording[:name], record_id: recording[:recordID], visibility:,
new_name = recording[:metadata][:name] || recording[:name]
new_recording = Recording.create(room_id:, name: new_name, record_id: recording[:recordID], visibility:,
users: recording[:participants], length:)
# Create format(s)
......
......@@ -32,7 +32,7 @@ Rails.application.routes.draw do
end
end
resources :room_settings, only: %i[show update], param: :friendly_id
resources :recordings, only: %i[index destroy] do
resources :recordings, only: %i[index update destroy] do
collection do
get '/resync', to: 'recordings#resync'
post '/publish', to: 'recordings#publish_recording'
......
......@@ -53,6 +53,40 @@ RSpec.describe Api::V1::RecordingsController, type: :controller do
end
end
describe '#update' do
let(:room) { create(:room, user:) }
let(:recording) { create(:recording, room:) }
before do
allow_any_instance_of(BigBlueButtonApi).to receive(:update_recordings).and_return(http_ok_response)
end
it 'updates the recordings name with valid params returning :ok status code' do
expect_any_instance_of(BigBlueButtonApi).to receive(:update_recordings).with(record_id: recording.record_id,
meta_hash: { meta_name: 'My Awesome Recording!' })
expect { post :update, params: { recording: { name: 'My Awesome Recording!' }, id: recording.record_id } }.to(change { recording.reload.name })
expect(response).to have_http_status(:ok)
end
it 'does not update the recordings name for invalid params returning a :bad_request status code' do
expect_any_instance_of(BigBlueButtonApi).not_to receive(:update_recordings)
expect do
post :update,
params: { recording: { name: '' }, id: recording.record_id }
end.not_to(change { recording.reload.name })
expect(response).to have_http_status(:bad_request)
end
it 'does not update the recordings name for invalid recording id returning :not_found status code' do
expect_any_instance_of(BigBlueButtonApi).not_to receive(:update_recordings)
post :update, params: { recording: { name: '' }, id: '404' }
expect(response).to have_http_status(:not_found)
end
end
# TODO: - Uncomment once delete_recordings is no longer in destroy
# describe '#destroy' do
# it 'deletes recording from the database' do
......@@ -82,16 +116,14 @@ RSpec.describe Api::V1::RecordingsController, type: :controller do
describe '#publish_recording' do
it 'Updates Recording with new visibility value' do
recording = create(:recording, visibility: 'Unpublished')
allow_any_instance_of(BigBlueButtonApi).to receive(:publish_recordings).and_return(publish_recordings_response)
allow_any_instance_of(BigBlueButtonApi).to receive(:publish_recordings).and_return(http_ok_response)
expect { post :publish_recording, params: { publish: 'true', record_id: recording.record_id } }.to change {
recording.reload.visibility
}.to('Published')
end
end
end
private
def publish_recordings_response
def http_ok_response
Net::HTTPSuccess.new(1.0, '200', 'OK')
end
end
......@@ -26,4 +26,13 @@ describe BigBlueButtonApi, type: :service do
expect(bbb_api).to eq(bbb_api2).and eq(bbb_api3)
end
end
describe '#update_recordings' do
it 'calls bbb_api #update_recordings with the passed options' do
allow_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:update_recordings).and_return(true)
expect_any_instance_of(BigBlueButton::BigBlueButtonApi).to receive(:update_recordings).with('recording_id', {},
{ 'meta_recording-name': 'recording_new_name' })
bbb_service.update_recordings(record_id: 'recording_id', meta_hash: { 'meta_recording-name': 'recording_new_name' })
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment