diff --git a/app/controllers/material_releases_controller.rb b/app/controllers/material_releases_controller.rb index 5e6c285..2aa7b4d 100644 --- a/app/controllers/material_releases_controller.rb +++ b/app/controllers/material_releases_controller.rb @@ -106,7 +106,7 @@ class MaterialReleasesController < ApplicationController :term_id, :term_text, :restriction_id, :restriction_text, :description, - :contract, { photos: [] } + :contract, files: [] ) end diff --git a/app/controllers/public/material_releases_controller.rb b/app/controllers/public/material_releases_controller.rb index dfcc5be..a0bd609 100644 --- a/app/controllers/public/material_releases_controller.rb +++ b/app/controllers/public/material_releases_controller.rb @@ -92,7 +92,7 @@ class Public::MaterialReleasesController < Public::BaseController params.require(:material_release).permit(person_params, guardian_params, second_guardian_params, :minor, :name, :address_street1, :address_street2, :address_city, :address_state, :address_zip, :address_country, :signature_base64, - :locale, :contract_template, :description, photos: [] + :locale, :contract_template, :description, files: [] ) end diff --git a/app/models/acquired_media_release.rb b/app/models/acquired_media_release.rb index d0aae53..631e1c4 100644 --- a/app/models/acquired_media_release.rb +++ b/app/models/acquired_media_release.rb @@ -15,7 +15,8 @@ class AcquiredMediaRelease < ApplicationRecord include SecondGuardianPhotoable include GuardianName include SecondGuardianName - + include FilesFilterable + class << self def custom_csv_exportable_headers %i[name files_count owner_info] @@ -106,16 +107,4 @@ class AcquiredMediaRelease < ApplicationRecord def files_count files.any? ? files.size : I18n.t('acquired_media_releases.acquired_media_release.no_media') end - - def image_files - files_blobs.where("content_type ILIKE ?", "%image%") - end - - def video_files - files_blobs.where("content_type ILIKE ?", "%video%") - end - - def other_files - files_blobs.where("NOT content_type ILIKE ANY (array[?])", ["%image%", "%video%"]) - end end diff --git a/app/models/concerns/files_filterable.rb b/app/models/concerns/files_filterable.rb new file mode 100644 index 0000000..c348976 --- /dev/null +++ b/app/models/concerns/files_filterable.rb @@ -0,0 +1,17 @@ +module FilesFilterable + extend ActiveSupport::Concern + + included do + def image_files + files_blobs.where("content_type ILIKE ?", "%image%") + end + + def video_files + files_blobs.where("content_type ILIKE ?", "%video%") + end + + def other_files + files_blobs.where("NOT content_type ILIKE ANY (array[?])", ["%image%", "%video%"]) + end + end +end diff --git a/app/models/material_release.rb b/app/models/material_release.rb index 4e41649..807c7dc 100644 --- a/app/models/material_release.rb +++ b/app/models/material_release.rb @@ -3,7 +3,7 @@ class MaterialRelease < ApplicationRecord include Contractable include Exploitable include Notable - include Photoable + include Photoable # This association needs to be removed after changing the API. Removing it right now will cause failure in API specs. include Releasable include Searchable include Signable @@ -16,11 +16,11 @@ class MaterialRelease < ApplicationRecord include SecondGuardianPhotoable include GuardianName include SecondGuardianName - + include FilesFilterable class << self def custom_csv_exportable_headers - %i[name owner_info] + %i[name owner_info files_count] end end @@ -56,6 +56,8 @@ class MaterialRelease < ApplicationRecord %w[guardian_2_address_zip zip], %w[guardian_2_address_country country] ] + + has_many_attached :files # We don't care for the argument but method WILL receive option name # when called from inside with_option block, hence * argument @@ -92,4 +94,8 @@ class MaterialRelease < ApplicationRecord def uses_edl? true end + + def files_count + files.any? ? files.size : I18n.t('material_releases.material_release.no_media') + end end diff --git a/app/policies/material_release_policy.rb b/app/policies/material_release_policy.rb index 4d1192f..a0330bd 100644 --- a/app/policies/material_release_policy.rb +++ b/app/policies/material_release_policy.rb @@ -19,12 +19,16 @@ class MaterialReleasePolicy < ReleasePolicy user.manager? || user.account_manager? end - def edit_photos? + def edit_files? true end + def update_files? + edit_files? + end + def update_photos? - edit_photos? + edit_files? end def tag_multiple? diff --git a/app/views/broadcasts/show.html.erb b/app/views/broadcasts/show.html.erb index 4b9707f..ed6c4e4 100644 --- a/app/views/broadcasts/show.html.erb +++ b/app/views/broadcasts/show.html.erb @@ -69,7 +69,7 @@ <%= javascript_tag nonce: true do %> new Clappr.Player({ parentId: '#broadcast_video', - source: "<%= @broadcast.stream_playback_url %>", + source: "<%= @broadcast.full_live_stream_playback_url %>", width: '100%', height: '100%', mute: true, diff --git a/app/views/contracts/pdf.html.erb b/app/views/contracts/pdf.html.erb index a261f96..92d8e73 100644 --- a/app/views/contracts/pdf.html.erb +++ b/app/views/contracts/pdf.html.erb @@ -52,7 +52,7 @@ <% end %> -<% if releasable.class == AcquiredMediaRelease %> +<% if releasable.respond_to?(:image_files) %>
<%= render "contracts/files", release: releasable, preview: preview %>
diff --git a/app/views/material_releases/_form.html.erb b/app/views/material_releases/_form.html.erb index ecfc028..79099c7 100644 --- a/app/views/material_releases/_form.html.erb +++ b/app/views/material_releases/_form.html.erb @@ -57,8 +57,8 @@
- <%= field_set_tag content_tag(:span, t(".photos.heading"), class: "h6 text-muted text-uppercase") do %> - <%= render "shared/photos_dropzone_fields", form: form, release: material_release %> + <%= field_set_tag content_tag(:span, t(".files.heading"), class: "h6 text-muted text-uppercase") do %> + <%= render "shared/releasable_files_dropzone", form: form, releasable: material_release %>
!material_release.minor?) %>" data-ujs-target="guardian-fields">
diff --git a/app/views/material_releases/_material_release.html.erb b/app/views/material_releases/_material_release.html.erb index 44c1b00..033f373 100644 --- a/app/views/material_releases/_material_release.html.erb +++ b/app/views/material_releases/_material_release.html.erb @@ -9,10 +9,10 @@ <% end %> - <% if material_release.photo.attached? %> - <%= image_tag medium_variant(material_release.photo), class: "img-fluid" %> + <% if material_release.files.any? %> + <%= material_release.files.size %> <% else %> - <%= fa_icon("warning", text: t(".no_photos"), class: "text-danger") %> + <%= fa_icon("warning", text: t(".no_media"), class: "text-danger") %> <% end %> @@ -41,8 +41,8 @@ <% if policy(material_release.tags).new? %> <%= link_to fa_icon("tags fw", text: "Tags"), [:new, material_release, :acts_as_taggable_on_tag], class: "dropdown-item", remote: true %> <% end %> - <% if policy(material_release).edit_photos? %> - <%= link_to fa_icon("picture-o fw", text: "Photos"), [:edit, material_release, :photos], class: "dropdown-item" %> + <% if policy(material_release).edit_files? %> + <%= link_to fa_icon("file-o fw", text: "Add Media"), [:edit, material_release, :files], class: "dropdown-item" %> <% end %> <% if policy(Contract).show? && (material_release.contract.attached? || material_release.contract_template.present?) %> <%= link_to fa_icon("download fw", text: "Download"), [material_release, :contracts, format: "pdf"], class: "dropdown-item", target: "_blank" %> diff --git a/app/views/material_releases/index.html.erb b/app/views/material_releases/index.html.erb index eaf63df..d9caf62 100644 --- a/app/views/material_releases/index.html.erb +++ b/app/views/material_releases/index.html.erb @@ -27,7 +27,7 @@ <%= check_box_tag "material_release_ids[]", false, false %> <%= t '.table_headers.approved'%> - + <%= t(".table_headers.files_count") %> <%= MaterialRelease.human_attribute_name(:name) %> <%= t(".table_headers.owner_info") %> <%= t(".table_headers.notes") %> diff --git a/app/views/public/material_releases/new.html.erb b/app/views/public/material_releases/new.html.erb index cb650f8..32dfcc5 100644 --- a/app/views/public/material_releases/new.html.erb +++ b/app/views/public/material_releases/new.html.erb @@ -45,8 +45,8 @@ <%= render "shared/address_fields", form: form, subject: "person", required: true %> <% end %> - <%= card_field_set_tag t(".photo.heading") do %> - <%= render "shared/photos_dropzone_fields", form: form, release: @material_release %> + <%= card_field_set_tag t(".files.heading") do %> + <%= render "shared/releasable_files_dropzone", form: form, releasable: @material_release %> <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 1645ae2..7413d44 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -904,6 +904,8 @@ en: form: contract_and_rights: heading: 3 of 4 Contract & Exploitable Rights + files: + heading: Files guardian_2_info: heading: Second Guardian Information (if company requires) guardian_info: @@ -911,7 +913,7 @@ en: material_details: heading: 1 of 3 Material Details photos: - dropzone_label: Tap to take a photo of Licensed Material (optional) + dropzone_label: "To Add Files to the release:
Drag & Drop Files
or
Click or Tap here to browse files" guardian_2_photo: heading: Second Guardian Photo guardian_photo: @@ -926,6 +928,7 @@ en: empty: Material Releases will appear here table_headers: approved: Approved + files_count: No. of Files name: Name notes: Notes owner_info: Owner Info @@ -937,6 +940,7 @@ en: review: Review messages: approved_tooltip: Approved by %{user} on %{timestamp} + no_media: No Media no_photos: Needs Photo new: heading: Import Material Release (Products / Logos) @@ -1255,6 +1259,8 @@ en: cancel: Cancel contact_info: heading: Licensor/Owner Contact Information + files: + heading: Files guardian_2_info: heading: Second Guardian Information (if company requires) guardian_2_photo: diff --git a/config/routes.rb b/config/routes.rb index 17da99c..b48e801 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,7 +55,7 @@ Rails.application.routes.draw do resources :appearance_releases, except: [:show], concerns: [:contractable, :notable] resources :appearance_release_imports, only: [:create] resources :location_releases, except: [:show], concerns: [:contractable, :notable, :photoable] - resources :material_releases, except: [:show], concerns: [:contractable, :notable, :photoable] + resources :material_releases, except: [:show], concerns: [:contractable, :notable, :file_uploadable] resources :music_releases, except: [:show], concerns: [:contractable, :notable] resources :talent_releases, except: [:show], concerns: [:contractable, :notable, :photoable] resources :medical_releases, except: [:show], concerns: [:contractable, :notable, :photoable] diff --git a/db/data_migrations/20200827095745_migrate_material_photos_to_files.rb b/db/data_migrations/20200827095745_migrate_material_photos_to_files.rb new file mode 100644 index 0000000..c151cc7 --- /dev/null +++ b/db/data_migrations/20200827095745_migrate_material_photos_to_files.rb @@ -0,0 +1,9 @@ +class MigrateMaterialPhotosToFiles < ActiveRecord::DataMigration + def up + photos = ActiveStorage::Attachment.where(name: "photos", record_type: "MaterialRelease") + + photos.each do |photo| + photo.update(name: "files") + end + end +end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index f6f8db3..b25da9c 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -68,13 +68,7 @@ RSpec.describe PhotosController, type: :controller do it_behaves_like "a photoable releases controller" end - - context "for material releases" do - subject { create(:material_release, project: project) } - - it_behaves_like "a photoable releases controller" - end - + private def release_params diff --git a/spec/controllers/public/material_releases_controller_spec.rb b/spec/controllers/public/material_releases_controller_spec.rb index dc7d970..c7ffe60 100644 --- a/spec/controllers/public/material_releases_controller_spec.rb +++ b/spec/controllers/public/material_releases_controller_spec.rb @@ -10,10 +10,10 @@ describe Public::MaterialReleasesController do it "allows photos param" do contract_template = create(:contract_template, project: project) - post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, material_release: material_release_params_with_photos } + post :create, params: { account_id: user.primary_account.to_param, project_id: project, contract_template_id: contract_template, material_release: material_release_params_with_files } expect(response).to be_successful - expect(MaterialRelease.last.photos.attached?).to eq true + expect(MaterialRelease.last.files.attached?).to eq true end it "displays validation errors" do @@ -63,8 +63,8 @@ describe Public::MaterialReleasesController do attributes_for(:material_release, :native).except(:signature).merge(signature_param) end - def material_release_params_with_photos - attributes_for(:material_release, :native, :with_photo).except(:signature).merge(signature_param) + def material_release_params_with_files + attributes_for(:material_release, :native, :with_file).except(:signature).merge(signature_param) end diff --git a/spec/factories/material_releases.rb b/spec/factories/material_releases.rb index c5ebb17..cb7ade6 100644 --- a/spec/factories/material_releases.rb +++ b/spec/factories/material_releases.rb @@ -42,6 +42,12 @@ FactoryBot.define do end end + trait :with_file do + files do + path = Rails.root.join("spec", "fixtures", "files", "material_photo.png") + [Rack::Test::UploadedFile.new(path, "image/png")] + end + end trait :non_native do contract do diff --git a/spec/features/user_managing_broadcasts_spec.rb b/spec/features/user_managing_broadcasts_spec.rb index 49b7461..30fd848 100644 --- a/spec/features/user_managing_broadcasts_spec.rb +++ b/spec/features/user_managing_broadcasts_spec.rb @@ -65,6 +65,25 @@ feature 'User managing broadcasts' do expect(page).to have_content(recording.name) end + context 'visit show page of active broadcast' do + scenario 'loads full live stream playback url if available' do + broadcast = create(:broadcast, :with_stream, :with_files, project: project, streamer_status: :recording, status: :active) + + visit project_broadcast_path(project, broadcast) + + expect(page.body).not_to match broadcast.stream_playback_url + expect(page.body).to match broadcast.full_live_stream_playback_url + end + + scenario 'loads full broadcast asset url if available' do + broadcast = create(:broadcast, :with_stream, :with_files, project: project, streamer_status: :recording, status: :active, full_live_stream_playback_uid: '') + + visit project_broadcast_path(project, broadcast) + + expect(page.body).to match broadcast.stream_playback_url + end + end + scenario 'Clicking Reset URL regenerates broadcast token' do broadcast = create(:broadcast, :with_stream, :with_files, project: project) old_token = broadcast.token diff --git a/spec/features/user_managing_material_releases_spec.rb b/spec/features/user_managing_material_releases_spec.rb index 9eda8be..eda959c 100644 --- a/spec/features/user_managing_material_releases_spec.rb +++ b/spec/features/user_managing_material_releases_spec.rb @@ -37,7 +37,7 @@ feature "User managing material releases" do click_button submit_release_button expect(page).to have_content success_submit_message - expect(MaterialRelease.last.photos.attached?).to eq true + expect(MaterialRelease.last.files.attached?).to eq true end scenario "creating a release for a minor - guardian fields are required when minor checkbox is checked", js: true do @@ -225,7 +225,7 @@ feature "User managing material releases" do click_button create_release_button expect(page).to have_content(create_release_notice) - expect(page).to have_photo("material_photo.png", visible: :all) + expect(page).to have_content("1") click_on "Manage" expect(page).to have_link("Download") @@ -364,19 +364,19 @@ feature "User managing material releases" do visit project_material_releases_path(project) - expect(page).to have_content("Needs Photo") + expect(page).to have_content("No Media") click_on "Manage" - click_on "Photos" + click_on "Add Media" - expect(page).to have_content("Add Photos") + expect(page).to have_content("Add Files") expect(page).to have_content("Apple MacBook Air") drop_file Rails.root.join(file_fixture("material_photo.png")), type: :dropzone click_on "Save Changes" - expect(page).to have_content("The release has been updated") - expect(page).to have_photo("material_photo.png", visible: :all) + expect(page).to have_content("Files added successfully to the release") + expect(page).to have_content("1") end scenario "viewing the contract PDF" do diff --git a/spec/policies/material_release_policy_spec.rb b/spec/policies/material_release_policy_spec.rb index f3e675a..c9baf93 100644 --- a/spec/policies/material_release_policy_spec.rb +++ b/spec/policies/material_release_policy_spec.rb @@ -24,7 +24,11 @@ describe MaterialReleasePolicy do end end - permissions :edit_photos? do + permissions :edit_files? do + it { is_expected.to permit(:edit_photos) } + end + + permissions :update_files? do it { is_expected.to permit(:edit_photos) } end