- <%= link_to file, target: "_blank" do %>
- <%= fa_icon("file", style: "font-size: 2rem") %>
-
<%= file.filename %>
+
+ <% broadcast = file.record %>
+ <% show_delete = controller.class.module_parent.to_s == "Public" ? false : policy(broadcast).destroy_file? %>
+ <% file_class = show_delete ? "col-8" : "col-12" %>
+
+
+ <% if file.variable? %>
+ <%= link_to image_tag(file.variant(resize_and_pad: [300, 300, background: "#F7F8F9"]), class: "bg-light img-thumbnail img-fluid"), file, target: "_blank" %>
+ <% else %>
+
+ <%= link_to file, target: "_blank" do %>
+ <%= fa_icon("file", style: "font-size: 2rem") %>
+
<%= file.filename %>
+ <% end %>
+
<% end %>
+
+
+ <% if show_delete %>
+
+ <% url = url_for [:destroy_file, broadcast.project, broadcast, { file_id: file.id }] %>
+ <%= link_to fa_icon("trash fw", text: t('.actions.delete_file')), url, class: "btn btn-danger", remote: true, method: :delete, data: { confirm: t('.confirm_delete') } %>
<% end %>
-
+
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 0031f0f..5bc2fbb 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -214,6 +214,10 @@ en:
destroy:
alert: A live stream has been deleted
api_error: Something went wrong, please try again later after some time
+ file:
+ actions:
+ delete_file: Delete
+ confirm_delete: Are you sure?
index:
actions:
new: Create New Live Stream
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 00d454a..52d5faf 100644
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -81,6 +81,10 @@ es:
do_not_copy_warning: "Do not copy (ES)"
serial_number_label: "Serial Number (ES)"
broadcasts:
+ file:
+ actions:
+ delete_file: Delete
+ confirm_delete: Are you sure? (ES)
show:
actions:
reset_url: Reset URL (ES)
diff --git a/config/routes.rb b/config/routes.rb
index 6f2e9a9..bd619ac 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -96,6 +96,9 @@ Rails.application.routes.draw do
end
resources :projects, only: [] do
resources :broadcasts, except: [:edit] do
+ member do
+ delete :destroy_file
+ end
resource :zoom_meeting, only: [:show]
end
resources :directories, except: [:index] do
diff --git a/spec/controllers/api/broadcasts_controller_spec.rb b/spec/controllers/api/broadcasts_controller_spec.rb
index ee5e3af..5927bca 100644
--- a/spec/controllers/api/broadcasts_controller_spec.rb
+++ b/spec/controllers/api/broadcasts_controller_spec.rb
@@ -106,7 +106,7 @@ RSpec.describe Api::BroadcastsController, type: :controller do
included = JSON.parse(response.body).dig('included')
expect(relationships.keys).to include('files')
- expect(included.size).to eq 1
+ expect(included.size).to eq 3
expect(included.first.dig("id")).to eq broadcast.files.first.id.to_s
expect(included.first.dig("type")).to eq 'active_storage_attachment'
end
diff --git a/spec/controllers/public/broadcasts_controller_spec.rb b/spec/controllers/public/broadcasts_controller_spec.rb
index 8850bd7..f42338d 100644
--- a/spec/controllers/public/broadcasts_controller_spec.rb
+++ b/spec/controllers/public/broadcasts_controller_spec.rb
@@ -87,6 +87,7 @@ RSpec.describe Public::BroadcastsController, type: :controller do
let!(:broadcast) { create(:broadcast, :with_stream, skip_create_callback: true, project: project ) }
it "uploads files to broadcast" do
+ allow(BroadcastsChannel).to receive(:broadcast_file_upload_updates)
patch :update, params: { token: broadcast.token, broadcast: file_params }, xhr: true
expect(broadcast.files.count).to eq(1)
diff --git a/spec/factories/broadcasts.rb b/spec/factories/broadcasts.rb
index 3b022c2..4148242 100644
--- a/spec/factories/broadcasts.rb
+++ b/spec/factories/broadcasts.rb
@@ -17,7 +17,13 @@ FactoryBot.define do
end
trait :with_files do
- files { [Rack::Test::UploadedFile.new('spec/fixtures/files/contract.pdf', 'application/pdf')] }
+ files do
+ [
+ Rack::Test::UploadedFile.new('spec/fixtures/files/contract.pdf', 'application/pdf'),
+ Rack::Test::UploadedFile.new('spec/fixtures/files/audio.mp3', 'audio/mpeg'),
+ Rack::Test::UploadedFile.new('spec/fixtures/files/video_file.mp4', 'video/mp4')
+ ]
+ end
end
after(:build) do |broadcast, evaluator|
diff --git a/spec/features/user_managing_broadcasts_spec.rb b/spec/features/user_managing_broadcasts_spec.rb
index b20cabc..5805ee2 100644
--- a/spec/features/user_managing_broadcasts_spec.rb
+++ b/spec/features/user_managing_broadcasts_spec.rb
@@ -164,6 +164,21 @@ feature 'User managing broadcasts' do
click_on add_file_button
end
+ scenario 'manager user can click delete button next to the file and delete file', js: true do
+ broadcast = create(:broadcast, :with_stream, :with_files, project: project)
+
+ visit project_broadcast_path(project, broadcast)
+
+ expect(page).to have_content delete_file_button, count: 3
+
+ accept_alert do
+ first('a', text: delete_file_button).click
+ end
+
+ expect(page).to have_content delete_file_button, count: 2
+ expect(Broadcast.find(broadcast.id).files.count).to eq 2
+ end
+
scenario 'visit multi-view broadcast page', js: true do
broadcast_one = create(:broadcast, :with_stream, :with_files, name: 'Broadcast 1', project: project)
broadcast_two = create(:broadcast, :with_stream, :with_files, name: 'Broadcast 2', project: project)
@@ -198,6 +213,14 @@ feature 'User managing broadcasts' do
expect(page).to have_content schedule_demo
expect(page).not_to have_content create_stream
end
+
+ scenario 'associate user does not see delete button next to the file', js: true do
+ broadcast = create(:broadcast, :with_stream, :with_files, project: project)
+
+ visit project_broadcast_path(project, broadcast)
+
+ expect(page).to have_content delete_file_button, count: 0
+ end
end
context 'When the user is account manager' do
@@ -209,6 +232,21 @@ feature 'User managing broadcasts' do
expect(page).to have_content schedule_demo
expect(page).to have_content create_stream
end
+
+ scenario 'account manager user can click delete button next to the file and delete file', js: true do
+ broadcast = create(:broadcast, :with_stream, :with_files, project: project)
+
+ visit project_broadcast_path(project, broadcast)
+
+ expect(page).to have_content delete_file_button, count: 3
+
+ accept_alert do
+ first('a', text: delete_file_button).click
+ end
+
+ expect(page).to have_content delete_file_button, count: 2
+ expect(Broadcast.find(broadcast.id).files.count).to eq 2
+ end
end
end
@@ -262,5 +300,9 @@ feature 'User managing broadcasts' do
'Live stream is waiting to begin'
end
+ def delete_file_button
+ t 'broadcasts.file.actions.delete_file'
+ end
+
end