Skip to content
Snippets Groups Projects
Unverified Commit 5724e049 authored by Hadi Cheaito's avatar Hadi Cheaito Committed by GitHub
Browse files

Publish/Unpublish Recordings (#3504)

* Publish/Unpublish Recordings

* Fixes + Cleaning

* Cleaning

* Fixes + rspec tests
parent 56436ff1
No related branches found
No related tags found
No related merge requests found
......@@ -24,3 +24,9 @@
}
.visibility-dropdown {
width: 125px;
height: 40px;
cursor: pointer;
}
......@@ -42,6 +42,19 @@ module Api
render_json(status: :ok)
end
def publish_recording
publish = params[:publish]
record_id = params[:record_id]
case publish
when 'true'
visibility = 'Published'
when 'false'
visibility = 'Unpublished'
end
Recording.find_by(record_id:).update(visibility:)
BigBlueButtonApi.new.publish_recordings(record_ids: record_id, publish:)
end
end
end
end
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTrashAlt, faVideo } from '@fortawesome/free-solid-svg-icons';
import Form from 'react-bootstrap/Form';
import React from 'react';
import PropTypes from 'prop-types';
import { Button, Stack, Table } from 'react-bootstrap';
import Modal from '../shared/Modal';
import DeleteRecordingForm from '../forms/DeleteRecordingForm';
import usePublishRecording from '../../hooks/mutations/recordings/usePublishRecording';
export default function RecordingsList({ recordings }) {
const { handlePublishRecording } = usePublishRecording();
return (
<Table hover className="text-secondary mb-0 recordings-list">
<thead>
......@@ -36,7 +40,18 @@ export default function RecordingsList({ recordings }) {
</td>
<td> {recording.length}min</td>
<td> {recording.users} </td>
<td> {recording.visibility} </td>
<td>
<Form.Select
className="visibility-dropdown"
onChange={(event) => {
handlePublishRecording({ publish: event.target.value, record_id: recording.record_id });
}}
>
<option selected hidden>{recording.visibility}</option>
<option value="true">Published</option>
<option value="false">Unpublished</option>
</Form.Select>
</td>
<td>
{recording.formats.map((format) => (
<Button
......
import { useMutation, useQueryClient } from 'react-query';
import axios from '../../../helpers/Axios';
export default function usePublishRecording() {
const updatePublish = (visibilityData) => axios.post('/recordings/publish.json', visibilityData);
const queryClient = useQueryClient();
const mutation = useMutation(updatePublish, {
onSuccess: () => {
queryClient.invalidateQueries('getRecordings');
},
onError: (error) => {
console.log('mutate error', error);
},
});
const handlePublishRecording = (visibilityData) => mutation.mutateAsync(visibilityData)
.catch(/* Prevents the promise exception from bubbling */() => {});
return { handlePublishRecording, ...mutation };
}
......@@ -35,6 +35,11 @@ class BigBlueButtonApi
bbb_server.delete_recordings(record_ids)
end
# Sets publish (true/false) for recording(s) with given record_id(s)
def publish_recordings(record_ids:, publish:)
bbb_server.publish_recordings(record_ids, publish)
end
private
def bbb_endpoint
......
......@@ -17,11 +17,12 @@ class RecordingsSync
recordings[:recordings].each do |recording|
room_id = Room.find_by(meeting_id: recording[:meetingID]).id
visibility = recording[:published] ? 'Published' : 'Unpublished'
# 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: 'Unlisted',
new_recording = Recording.create(room_id:, name: recording[:name], record_id: recording[:recordID], visibility:,
users: recording[:participants], length:)
# Create format(s)
......
......@@ -31,6 +31,7 @@ Rails.application.routes.draw do
resources :recordings, only: %i[index destroy] do
collection do
get '/resync', to: 'recordings#resync'
post '/publish', to: 'recordings#publish_recording'
end
end
resources :shared_accesses, only: %i[create show destroy], param: :friendly_id do
......
......@@ -78,4 +78,13 @@ RSpec.describe Api::V1::RecordingsController, type: :controller do
get :resync
end
end
describe '#publish_recording' do
it 'Updates Recording with new visibility value' do
recording = create(:recording, visibility: 'Unpublished')
expect { post :publish_recording, params: { publish: 'true', record_id: recording.record_id } }.to change {
recording.reload.visibility
}.to('Published')
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment