Upstream sync

This commit is contained in:
Senad Uka
2020-09-01 17:15:16 +02:00
parent 95a14ab2f6
commit f611382e9e
21 changed files with 107 additions and 53 deletions

View File

@@ -106,7 +106,7 @@ class MaterialReleasesController < ApplicationController
:term_id, :term_text, :term_id, :term_text,
:restriction_id, :restriction_text, :restriction_id, :restriction_text,
:description, :description,
:contract, { photos: [] } :contract, files: []
) )
end end

View File

@@ -92,7 +92,7 @@ class Public::MaterialReleasesController < Public::BaseController
params.require(:material_release).permit(person_params, guardian_params, second_guardian_params, :minor, 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, :name, :address_street1, :address_street2, :address_city, :address_state, :address_zip, :address_country,
:signature_base64, :signature_base64,
:locale, :contract_template, :description, photos: [] :locale, :contract_template, :description, files: []
) )
end end

View File

@@ -15,6 +15,7 @@ class AcquiredMediaRelease < ApplicationRecord
include SecondGuardianPhotoable include SecondGuardianPhotoable
include GuardianName include GuardianName
include SecondGuardianName include SecondGuardianName
include FilesFilterable
class << self class << self
def custom_csv_exportable_headers def custom_csv_exportable_headers
@@ -106,16 +107,4 @@ class AcquiredMediaRelease < ApplicationRecord
def files_count def files_count
files.any? ? files.size : I18n.t('acquired_media_releases.acquired_media_release.no_media') files.any? ? files.size : I18n.t('acquired_media_releases.acquired_media_release.no_media')
end 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 end

View File

@@ -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

View File

@@ -3,7 +3,7 @@ class MaterialRelease < ApplicationRecord
include Contractable include Contractable
include Exploitable include Exploitable
include Notable 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 Releasable
include Searchable include Searchable
include Signable include Signable
@@ -16,11 +16,11 @@ class MaterialRelease < ApplicationRecord
include SecondGuardianPhotoable include SecondGuardianPhotoable
include GuardianName include GuardianName
include SecondGuardianName include SecondGuardianName
include FilesFilterable
class << self class << self
def custom_csv_exportable_headers def custom_csv_exportable_headers
%i[name owner_info] %i[name owner_info files_count]
end end
end end
@@ -57,6 +57,8 @@ class MaterialRelease < ApplicationRecord
%w[guardian_2_address_country country] %w[guardian_2_address_country country]
] ]
has_many_attached :files
# We don't care for the argument but method WILL receive option name # We don't care for the argument but method WILL receive option name
# when called from inside with_option block, hence * argument # when called from inside with_option block, hence * argument
def self.face_photo_acceptable_content_types(*) def self.face_photo_acceptable_content_types(*)
@@ -92,4 +94,8 @@ class MaterialRelease < ApplicationRecord
def uses_edl? def uses_edl?
true true
end end
def files_count
files.any? ? files.size : I18n.t('material_releases.material_release.no_media')
end
end end

View File

@@ -19,12 +19,16 @@ class MaterialReleasePolicy < ReleasePolicy
user.manager? || user.account_manager? user.manager? || user.account_manager?
end end
def edit_photos? def edit_files?
true true
end end
def update_files?
edit_files?
end
def update_photos? def update_photos?
edit_photos? edit_files?
end end
def tag_multiple? def tag_multiple?

View File

@@ -69,7 +69,7 @@
<%= javascript_tag nonce: true do %> <%= javascript_tag nonce: true do %>
new Clappr.Player({ new Clappr.Player({
parentId: '#broadcast_video', parentId: '#broadcast_video',
source: "<%= @broadcast.stream_playback_url %>", source: "<%= @broadcast.full_live_stream_playback_url %>",
width: '100%', width: '100%',
height: '100%', height: '100%',
mute: true, mute: true,

View File

@@ -52,7 +52,7 @@
</div> </div>
<% end %> <% end %>
<% if releasable.class == AcquiredMediaRelease %> <% if releasable.respond_to?(:image_files) %>
<div class="page"> <div class="page">
<%= render "contracts/files", release: releasable, preview: preview %> <%= render "contracts/files", release: releasable, preview: preview %>
</div> </div>

View File

@@ -57,8 +57,8 @@
<hr> <hr>
<%= field_set_tag content_tag(:span, t(".photos.heading"), class: "h6 text-muted text-uppercase") do %> <%= field_set_tag content_tag(:span, t(".files.heading"), class: "h6 text-muted text-uppercase") do %>
<%= render "shared/photos_dropzone_fields", form: form, release: material_release %> <%= render "shared/releasable_files_dropzone", form: form, releasable: material_release %>
<div class="<%= class_string("collapse" => !material_release.minor?) %>" data-ujs-target="guardian-fields"> <div class="<%= class_string("collapse" => !material_release.minor?) %>" data-ujs-target="guardian-fields">
<br> <br>

View File

@@ -9,10 +9,10 @@
<% end %> <% end %>
</td> </td>
<td> <td>
<% if material_release.photo.attached? %> <% if material_release.files.any? %>
<%= image_tag medium_variant(material_release.photo), class: "img-fluid" %> <%= material_release.files.size %>
<% else %> <% else %>
<%= fa_icon("warning", text: t(".no_photos"), class: "text-danger") %> <%= fa_icon("warning", text: t(".no_media"), class: "text-danger") %>
<% end %> <% end %>
</td> </td>
<td> <td>
@@ -41,8 +41,8 @@
<% if policy(material_release.tags).new? %> <% 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 %> <%= link_to fa_icon("tags fw", text: "Tags"), [:new, material_release, :acts_as_taggable_on_tag], class: "dropdown-item", remote: true %>
<% end %> <% end %>
<% if policy(material_release).edit_photos? %> <% if policy(material_release).edit_files? %>
<%= link_to fa_icon("picture-o fw", text: "Photos"), [:edit, material_release, :photos], class: "dropdown-item" %> <%= link_to fa_icon("file-o fw", text: "Add Media"), [:edit, material_release, :files], class: "dropdown-item" %>
<% end %> <% end %>
<% if policy(Contract).show? && (material_release.contract.attached? || material_release.contract_template.present?) %> <% 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" %> <%= link_to fa_icon("download fw", text: "Download"), [material_release, :contracts, format: "pdf"], class: "dropdown-item", target: "_blank" %>

View File

@@ -27,7 +27,7 @@
<tr> <tr>
<th data-behavior="all-selectable"><%= check_box_tag "material_release_ids[]", false, false %></th> <th data-behavior="all-selectable"><%= check_box_tag "material_release_ids[]", false, false %></th>
<th><%= t '.table_headers.approved'%></th> <th><%= t '.table_headers.approved'%></th>
<th></th> <th><%= t(".table_headers.files_count") %></th>
<th><%= MaterialRelease.human_attribute_name(:name) %></th> <th><%= MaterialRelease.human_attribute_name(:name) %></th>
<th><%= t(".table_headers.owner_info") %> <th><%= t(".table_headers.owner_info") %>
<th><%= t(".table_headers.notes") %></th> <th><%= t(".table_headers.notes") %></th>

View File

@@ -45,8 +45,8 @@
<%= render "shared/address_fields", form: form, subject: "person", required: true %> <%= render "shared/address_fields", form: form, subject: "person", required: true %>
<% end %> <% end %>
<%= card_field_set_tag t(".photo.heading") do %> <%= card_field_set_tag t(".files.heading") do %>
<%= render "shared/photos_dropzone_fields", form: form, release: @material_release %> <%= render "shared/releasable_files_dropzone", form: form, releasable: @material_release %>
<% end %> <% end %>
<hr> <hr>

View File

@@ -904,6 +904,8 @@ en:
form: form:
contract_and_rights: contract_and_rights:
heading: 3 of 4 Contract & Exploitable Rights heading: 3 of 4 Contract & Exploitable Rights
files:
heading: Files
guardian_2_info: guardian_2_info:
heading: Second Guardian Information (if company requires) heading: Second Guardian Information (if company requires)
guardian_info: guardian_info:
@@ -911,7 +913,7 @@ en:
material_details: material_details:
heading: 1 of 3 Material Details heading: 1 of 3 Material Details
photos: photos:
dropzone_label: Tap to take a photo of Licensed Material (optional) dropzone_label: "To Add Files to the release:<br>Drag & Drop Files<br>or<br>Click or Tap here to browse files"
guardian_2_photo: guardian_2_photo:
heading: Second Guardian Photo heading: Second Guardian Photo
guardian_photo: guardian_photo:
@@ -926,6 +928,7 @@ en:
empty: Material Releases will appear here empty: Material Releases will appear here
table_headers: table_headers:
approved: Approved approved: Approved
files_count: No. of Files
name: Name name: Name
notes: Notes notes: Notes
owner_info: Owner Info owner_info: Owner Info
@@ -937,6 +940,7 @@ en:
review: Review review: Review
messages: messages:
approved_tooltip: Approved by %{user} on %{timestamp} approved_tooltip: Approved by %{user} on %{timestamp}
no_media: No Media
no_photos: Needs Photo no_photos: Needs Photo
new: new:
heading: Import Material Release (Products / Logos) heading: Import Material Release (Products / Logos)
@@ -1255,6 +1259,8 @@ en:
cancel: Cancel cancel: Cancel
contact_info: contact_info:
heading: Licensor/Owner Contact Information heading: Licensor/Owner Contact Information
files:
heading: Files
guardian_2_info: guardian_2_info:
heading: Second Guardian Information (if company requires) heading: Second Guardian Information (if company requires)
guardian_2_photo: guardian_2_photo:

View File

@@ -55,7 +55,7 @@ Rails.application.routes.draw do
resources :appearance_releases, except: [:show], concerns: [:contractable, :notable] resources :appearance_releases, except: [:show], concerns: [:contractable, :notable]
resources :appearance_release_imports, only: [:create] resources :appearance_release_imports, only: [:create]
resources :location_releases, except: [:show], concerns: [:contractable, :notable, :photoable] 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 :music_releases, except: [:show], concerns: [:contractable, :notable]
resources :talent_releases, except: [:show], concerns: [:contractable, :notable, :photoable] resources :talent_releases, except: [:show], concerns: [:contractable, :notable, :photoable]
resources :medical_releases, except: [:show], concerns: [:contractable, :notable, :photoable] resources :medical_releases, except: [:show], concerns: [:contractable, :notable, :photoable]

View File

@@ -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

View File

@@ -69,12 +69,6 @@ RSpec.describe PhotosController, type: :controller do
it_behaves_like "a photoable releases controller" it_behaves_like "a photoable releases controller"
end end
context "for material releases" do
subject { create(:material_release, project: project) }
it_behaves_like "a photoable releases controller"
end
private private
def release_params def release_params

View File

@@ -10,10 +10,10 @@ describe Public::MaterialReleasesController do
it "allows photos param" do it "allows photos param" do
contract_template = create(:contract_template, project: project) 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(response).to be_successful
expect(MaterialRelease.last.photos.attached?).to eq true expect(MaterialRelease.last.files.attached?).to eq true
end end
it "displays validation errors" do it "displays validation errors" do
@@ -63,8 +63,8 @@ describe Public::MaterialReleasesController do
attributes_for(:material_release, :native).except(:signature).merge(signature_param) attributes_for(:material_release, :native).except(:signature).merge(signature_param)
end end
def material_release_params_with_photos def material_release_params_with_files
attributes_for(:material_release, :native, :with_photo).except(:signature).merge(signature_param) attributes_for(:material_release, :native, :with_file).except(:signature).merge(signature_param)
end end

View File

@@ -42,6 +42,12 @@ FactoryBot.define do
end end
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 trait :non_native do
contract do contract do

View File

@@ -65,6 +65,25 @@ feature 'User managing broadcasts' do
expect(page).to have_content(recording.name) expect(page).to have_content(recording.name)
end 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 scenario 'Clicking Reset URL regenerates broadcast token' do
broadcast = create(:broadcast, :with_stream, :with_files, project: project) broadcast = create(:broadcast, :with_stream, :with_files, project: project)
old_token = broadcast.token old_token = broadcast.token

View File

@@ -37,7 +37,7 @@ feature "User managing material releases" do
click_button submit_release_button click_button submit_release_button
expect(page).to have_content success_submit_message 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 end
scenario "creating a release for a minor - guardian fields are required when minor checkbox is checked", js: true do 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 click_button create_release_button
expect(page).to have_content(create_release_notice) 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" click_on "Manage"
expect(page).to have_link("Download") expect(page).to have_link("Download")
@@ -364,19 +364,19 @@ feature "User managing material releases" do
visit project_material_releases_path(project) 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 "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") expect(page).to have_content("Apple MacBook Air")
drop_file Rails.root.join(file_fixture("material_photo.png")), type: :dropzone drop_file Rails.root.join(file_fixture("material_photo.png")), type: :dropzone
click_on "Save Changes" click_on "Save Changes"
expect(page).to have_content("The release has been updated") expect(page).to have_content("Files added successfully to the release")
expect(page).to have_photo("material_photo.png", visible: :all) expect(page).to have_content("1")
end end
scenario "viewing the contract PDF" do scenario "viewing the contract PDF" do

View File

@@ -24,7 +24,11 @@ describe MaterialReleasePolicy do
end end
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) } it { is_expected.to permit(:edit_photos) }
end end