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,
:restriction_id, :restriction_text,
:description,
:contract, { photos: [] }
:contract, files: []
)
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,
: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

View File

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

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

View File

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

View File

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

View File

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

View File

@@ -57,8 +57,8 @@
<hr>
<%= 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 %>
<div class="<%= class_string("collapse" => !material_release.minor?) %>" data-ujs-target="guardian-fields">
<br>

View File

@@ -9,10 +9,10 @@
<% end %>
</td>
<td>
<% 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 %>
</td>
<td>
@@ -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" %>

View File

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

View File

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

View File

@@ -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:<br>Drag & Drop Files<br>or<br>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:

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

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