Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/1.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Musiorski committed May 2, 2018
2 parents 3a2ab9e + 19ac4ae commit 3ce375b
Show file tree
Hide file tree
Showing 55 changed files with 1,008 additions and 422 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Metrics/ClassLength:
- 'lib/aic_type.rb'
- 'lib/aic_doc_type.rb'
- 'app/controllers/catalog_controller.rb'
- 'app/presenters/asset_presenter.rb'

Metrics/CyclomaticComplexity:
Exclude:
Expand Down Expand Up @@ -93,6 +94,8 @@ Style/PredicateName:
Exclude:
- 'app/presenters/asset_presenter.rb'
- 'app/presenters/concerns/citi_presenter_behaviors.rb'
- 'app/models/parameterized_relationships.rb'
- 'app/forms/curation_concerns/generic_work_form.rb'

Style/FileName:
Exclude:
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: ruby
sudo: false
rvm:
- 2.3.1
cache:
bundler: true
directories:
Expand Down
10 changes: 9 additions & 1 deletion app/actors/add_to_citi_resource_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AddToCitiResourceActor < CurationConcerns::Actors::AbstractActor
include CurationConcerns::Lockable

attr_reader :representations, :preferred_representations, :additional_representation, :documents,
:additional_document, :attachments
:additional_document, :attachments, :constituents

def create(attributes)
delete_relationship_attributes(attributes)
Expand All @@ -33,6 +33,7 @@ def delete_relationship_attributes(attributes)
@documents = attributes.delete(:documents_for)
@additional_document = attributes.delete(:additional_document)
@attachments = attributes.delete(:attachments_for)
@constituents = attributes.delete(:has_constituent_part)
end

# Assembles all unique representation ids, removing any empty strings passed in from the form.
Expand Down Expand Up @@ -62,6 +63,12 @@ def attachment_uris
Array.wrap(attachments).uniq.delete_if(&:empty?)
end

# Assets are referenced using uris and not ids
# @return [Array<String>]
def constituent_uris
Array.wrap(constituents).uniq.delete_if(&:empty?)
end

private

# @todo wrap this in an async job? If the list of ids is very long, these updates will be done
Expand All @@ -70,6 +77,7 @@ def add_relationships
management_service.add_or_remove_representations(representation_ids)
management_service.add_or_remove(:documents, document_ids)
management_service.add_or_remove(:attachments, attachment_uris)
management_service.add_or_remove(:constituents, constituent_uris)
management_service.update(:preferred_representations, preferred_representation_ids)
true
end
Expand Down
8 changes: 3 additions & 5 deletions app/controllers/batch_edits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,14 @@ def update_batch
end

# Remove (and its commit) when https://github.com/projecthydra/sufia/issues/2450 is closed
# Updates terms, permissions, and visibility for a given object in a batch.
# Note: Permissions and visibility are *always* copied down to any contained FileSet objects.
# There is no UI option presented to the user to prevent this, unlike the option that
# is present when changing permissions on a single work.
# Updates terms and visibility for a given object in a batch.
# Note: Visibility is copied down to any contained FileSet objects, but
# permissions are not because file sets use the same ACLs as its parent asset.
def update_asset(obj)
visibility_changed = visibility_status(obj)
actor = CurationConcerns::Actors::ActorStack.new(obj, current_user, actor_stack)
actor.update(work_params)
VisibilityCopyJob.perform_later(obj) if visibility_changed
InheritPermissionsJob.perform_later(obj) if work_params.fetch(:permissions_attributes, nil)
end

def form_class
Expand Down
10 changes: 3 additions & 7 deletions app/controllers/lakeshore/ingest_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ class IngestController < APIController
# load_and_authorize_resource :curation_concern, class: 'GenericWork'

delegate :intermediate_file, :asset_type, :ingestor, :attributes_for_actor,
:check_duplicates?, :represented_resources, to: :ingest
:check_duplicates_turned_off?, :represented_resources, :force_preferred_representation?, to: :ingest

before_action :validate_ingest, :validate_asset_type, only: [:create]
before_action :validate_duplicate_upload, :validate_preferred_representations, only: [:create, :update]
skip_before_action :validate_duplicate_upload, if: :duplicate_check_param_is_false

def create
if actor.create(attributes_for_actor)
Expand Down Expand Up @@ -42,23 +41,20 @@ def validate_asset_type
end

def validate_duplicate_upload
return if check_duplicates_turned_off?
return if duplicate_upload.empty?
ingest.errors.add(:intermediate_file, "is a duplicate of #{duplicate_upload.first}")
render json: duplicate_error, status: :conflict
end

def validate_preferred_representations
return unless represented_resources.present?
return if force_preferred_representation? || represented_resources.empty?
ingest.errors.add(:represented_resources, "#{represented_resources.join(', ')} already have a preferred representation")
render json: ingest.errors.full_messages, status: :conflict
end

private

def duplicate_check_param_is_false
params.fetch(:duplicate_check, nil) == "false"
end

def ingest
@ingest ||= Lakeshore::Ingest.new(params)
end
Expand Down
7 changes: 5 additions & 2 deletions app/forms/batch_upload_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class BatchUploadForm < Sufia::Forms::BatchUploadForm

self.terms = CurationConcerns::GenericWorkForm.terms

delegate :representations_for, :documents_for, :attachment_uris, :attachments_for, to: :parameterized_relationships
delegate :representations_for, :documents_for, :attachment_uris, :attachments_for,
:constituent_of_uris, :has_constituent_part, to: :parameterized_relationships

def primary_terms
CurationConcerns::GenericWorkForm.aic_terms(action_name: @action_name, current_ability: @current_ability) - [:asset_type, :pref_label, :external_resources]
Expand Down Expand Up @@ -68,6 +69,8 @@ def parameterized_relationships
@parameterized_relationships || OpenStruct.new(representations_for: [],
documents_for: [],
attachment_uris: [],
attachments_for: [])
attachments_for: [],
constituent_of_uris: [],
has_constituent_part: [])
end
end
2 changes: 2 additions & 0 deletions app/forms/concerns/asset_form_behaviors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ def self.build_permitted_params
{ representations_for: [] },
{ documents_for: [] },
{ attachments_for: [] },
{ has_constituent_part: [] },
{ preferred_representation_for: [] },
{ publish_channel_uris: [] },
{ imaging_uid: [] },
{ view_notes: [] },
{ attachment_uris: [] },
{ constituent_of_uris: [] },
{ licensing_restriction_uris: [] },
:document_type_uri,
:first_document_sub_type_uri,
Expand Down
15 changes: 9 additions & 6 deletions app/forms/curation_concerns/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class GenericWorkForm < Sufia::Forms::WorkForm
include AssetFormBehaviors
include PropertyPermissions

delegate :dept_created, :attachment_uris, :attachments, :copyright_representatives, :imaging_uid_placeholder, to: :model
delegate :dept_created, :attachment_uris, :attachments, :copyright_representatives,
:imaging_uid_placeholder, :constituent_of, :constituent_of_uris, to: :model

attr_accessor :action_name, :current_ability

Expand All @@ -29,7 +30,7 @@ def self.aic_terms(action_name: nil, current_ability: nil)
end

def self.multiple?(term)
return true if term == :attachment_uris
return true if [:attachment_uris, :constituent_of_uris].include?(term)
super
end

Expand Down Expand Up @@ -61,30 +62,32 @@ def uri_for(term)
end

# @return [Array<SolrDocument>]
# TODO: I don't know if this will work. Forms usually need AF::Base objects
def representations_for
representing_resource.representations
end

# @return [Array<SolrDocument>]
# TODO: I don't know if this will work. Forms usually need AF::Base objects
def documents_for
representing_resource.documents
end

# @return [Array<SolrDocument>]
# TODO: I don't know if this will work. Forms usually need AF::Base objects
def attachments_for
representing_resource.assets
end

# @return [Array<SolrDocument>]
def has_constituent_part
representing_resource.constituents
end

def preferred_representation_for
# TODO: need to add this to the relationships tab
end

# Overrides hydra-editor MultiValueInput#collection
def [](term)
if [:representations_for, :documents_for, :attachments_for].include? term
if [:representations_for, :documents_for, :attachments_for, :has_constituent_part].include? term
send(term)
else
super
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/asset_relationship_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module AssetRelationshipHelper
def publish_channels_to_badges(publish_channels)
html = []

publish_channels.each do |publish_channel|
interpretive_resources = ["Multimedia", "Educational Resources", "Teacher Resources"]

(publish_channels - interpretive_resources).each do |publish_channel|
html << content_tag(:span, publish_channel, title: publish_channel, class: "label label-primary")
end
html.join.html_safe
Expand Down
1 change: 1 addition & 0 deletions app/indexers/asset_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def generate_solr_document
solr_doc[Solrizer.solr_name("publish_channels", :facetable)] = object.publish_channels.map(&:pref_label)
solr_doc[Solrizer.solr_name("publish_channels", :symbol)] = object.publish_channels.map(&:pref_label)
solr_doc[Solrizer.solr_name("attachments", :symbol)] = object.attachments.map(&:id)
solr_doc[Solrizer.solr_name("constituent_of", :symbol)] = object.constituent_of.map(&:id)
solr_doc[Solrizer.solr_name("related_works", :symbol)] = field_builder.related_works
solr_doc[Solrizer.solr_name("related_work_main_ref_number", :symbol)] = field_builder.main_ref_numbers
solr_doc[Solrizer.solr_name("rdf_types", :symbol)] = object.type.map(&:to_s)
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/citi_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class CitiNotificationJob < ActiveJob::Base
# @param [CitiResource] citi_resource
# When the citi_resource is supplied, it is assumed that the accompanying file set is the correct one
# containing the preferred representation.
def perform(file_set, citi_resource = nil)
def perform(file_set, citi_resource = nil, imaging_uid_update = nil)
return unless ENV.fetch("citi_api_uid", nil)
citi_resource ||= find_citi_resource(file_set)
return unless citi_resource
post = notify(CitiNotification.new(file_set, citi_resource))
post = notify(CitiNotification.new(file_set, citi_resource, imaging_uid_update))
return post.body if post.response.code.to_i == 202
raise Lakeshore::CitiNotificationError,
"CITI notification failed. Expected 202 but received #{post.response.code}. #{post.body}"
Expand Down
12 changes: 10 additions & 2 deletions app/models/citi_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ class CitiNotification

# @param [FileSet] file_set
# @param [CitiResource, SolrDocument] citi_resource such as a work, exhibit
def initialize(file_set, citi_resource)
def initialize(file_set, citi_resource, imaging_uid_update = nil)
@file_set = file_set
@citi_resource = citi_resource
@imaging_uid_update = imaging_uid_update
end

# @return [String]
Expand Down Expand Up @@ -51,9 +52,16 @@ def type
end
end

# if citi notification type is just an imaging_uid on the asset
# then change last_modified to the asset's last modifed, so that
# CITI processes the message
def last_modified
return unless file_set && file_set.original_file
file_set.original_file.fcrepo_modified.first.iso8601
if @imaging_uid_update
file_set.parent.date_modified.iso8601
else
file_set.original_file.fcrepo_modified.first.iso8601
end
end

def image_uid
Expand Down
5 changes: 4 additions & 1 deletion app/models/concerns/asset_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def second_document_sub_type=(value)

property :publish_channels, predicate: AIC.publishChannel, class_name: "PublishChannel"

# @todo this should be renamed attachment_of for consistency, and can be done during #1682
property :attachments, predicate: AIC.isAttachmentOf, class_name: "GenericWork"

property :constituent_of, predicate: AIC.isConstituentPartOf, class_name: "GenericWork"

property :copyright_representatives, predicate: AIC.copyrightRepresentative, class_name: "Agent" do |index|
index.as :stored_searchable, using: :pref_label
end
Expand All @@ -75,6 +78,6 @@ def second_document_sub_type=(value)

accepts_uris_for :keyword, :digitization_source, :document_type, :first_document_sub_type,
:second_document_sub_type, :publish_channels, :attachments, :copyright_representatives,
:licensing_restrictions
:licensing_restrictions, :constituent_of
end
end
4 changes: 4 additions & 0 deletions app/models/concerns/solr_document_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def attachment_ids
Array(self[Solrizer.solr_name('attachments', :symbol)])
end

def constituent_of_ids
Array(self[Solrizer.solr_name('constituent_of', :symbol)])
end

def visibility
@visibility ||= if read_groups.include? Hydra::AccessControls::AccessRight::PERMISSION_TEXT_VALUE_PUBLIC
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
Expand Down
8 changes: 8 additions & 0 deletions app/models/generic_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def imaging_uid_placeholder
end

def imaging_uid_placeholder=(val)
if (val != imaging_uid_placeholder) && preferred_representation?
CitiNotificationJob.perform_later(intermediate_file_set.first, nil, true)
end
self.imaging_uid = [val]
end

Expand Down Expand Up @@ -95,4 +98,9 @@ def representing_resource
def assignment_service
@assignment_service ||= AssetTypeAssignmentService.new(self)
end

# tells whether a GenericWork asset is a preferred representation
def preferred_representation?
InboundRelationships.new(self).preferred_representation.present?
end
end
9 changes: 9 additions & 0 deletions app/models/inbound_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def representation_ids
@representation_ids ||= ids_with(:representations_ssim)
end

# @todo this is memoizing the wrong thing; needs to be @assets
def assets
@asset_ids ||= resources_with(:attachments_ssim)
end
Expand All @@ -59,6 +60,14 @@ def asset_ids
end
alias attachment_ids asset_ids

def constituents
@constituents ||= resources_with(:constituent_of_ssim)
end

def constituent_ids
@constituent_ids ||= ids_with(:constituent_of_ssim)
end

private

# @return [Array<SolrDocument>]
Expand Down
17 changes: 12 additions & 5 deletions app/models/lakeshore/ingest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Ingest

attr_reader :ingestor, :submitted_asset_type, :document_type_uri, :original_file,
:intermediate_file, :presevation_master_file, :legacy_file, :additional_files, :params,
:preferred_representation_for
:preferred_representation_for, :force_preferred_representation

validates :ingestor, :asset_type, :document_type_uri, :intermediate_file, presence: true

Expand Down Expand Up @@ -43,10 +43,10 @@ def valid_update?
ingestor.present?
end

# @return [Boolean]
# Only returns false if the parameter is explicitly set to "false"
def check_duplicates?
params.fetch(:duplicate_check, nil) == "false" ? false : true
# @return [true, false]
# Only returns true if the parameter is explicitly set to "false"
def check_duplicates_turned_off?
params.fetch(:duplicate_check, nil) == "false"
end

# @return [Array<String>]
Expand All @@ -57,6 +57,12 @@ def represented_resources
end
end

# @return [true, false]
# Only returns true if the parameter is explicitly set to "true"
def force_preferred_representation?
params.fetch(:force_preferred_representation, nil) == "true"
end

private

def register_terms(metadata)
Expand Down Expand Up @@ -119,6 +125,7 @@ def legacy_upload
end

def additional_uploads
return [] unless additional_files
additional_files.values.map do |file|
Sufia::UploadedFile.create(file: file, user: ingestor)
end
Expand Down
Loading

0 comments on commit 3ce375b

Please sign in to comment.