Skip to content

Commit

Permalink
Persist visibility settings to generic files.
Browse files Browse the repository at this point in the history
When ingesting the visibility should be copied to the generic files.

Closes #253.
  • Loading branch information
Trey Terrell authored and Trey Terrell committed Sep 2, 2015
1 parent fea1d9f commit 23ca380
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ def create_metadata(batch_id, work_id, generic_file_params = {})
ActiveFedora::Base.logger.warn 'unable to find batch to attach to'
end

if assign_visibility?(generic_file_params)
interpret_visibility generic_file_params
end
unless work_id.blank?
work = ActiveFedora::Base.find(work_id)

if !((generic_file_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty?
interpret_visibility generic_file_params
else
unless assign_visibility?(generic_file_params)
copy_visibility(work, generic_file)
end
work.generic_files << generic_file
Expand All @@ -51,6 +52,10 @@ def create_metadata(batch_id, work_id, generic_file_params = {})
yield(generic_file) if block_given?
end

def assign_visibility?(generic_file_params = {})
!((generic_file_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty?
end

def create_content(file)
# Tell UploadFileToGenericFile service to skip versioning because versions will be minted by VersionCommitter (called by save_characterize_and_record_committer) when necessary
Hydra::Works::UploadFileToGenericFile.call(generic_file, file, versioning: false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module CurationConcerns::WorkActorBehavior
include CurationConcerns::ManagesEmbargoesActor
attr_accessor :raw_attributes

def create
# set the @files ivar then remove the files attribute so it isn't set by default.
files && attributes.delete(:files)
self.raw_attributes = attributes.dup
# Files must be attached before saving in order to persist their relationship to the work
assign_pid && interpret_visibility && attach_files && super && assign_representative && copy_visibility
end
Expand Down Expand Up @@ -68,14 +70,19 @@ def attach_file(file)
generic_file = ::GenericFile.new
generic_file_actor = CurationConcerns::GenericFileActor.new(generic_file, user)
# TODO: we're passing an ID rather than an object. This means the actor does an unnecessary lookup
generic_file_actor.create_metadata(curation_concern.id, curation_concern.id)
generic_file.visibility = visibility
generic_file_actor.create_metadata(curation_concern.id, curation_concern.id, visibility_attributes)
generic_file_actor.create_content(file)
@generic_files ||= []
@generic_files << generic_file # This is so that other methods like assign_representative can access the generic_files wihtout reloading them from fedora
curation_concern.generic_files << generic_file
end

# The attributes used for visibility - used to send as initial params to
# created GenericFiles.
def visibility_attributes
raw_attributes.slice(:visibility, :visibility_during_lease, :visibility_after_lease, :lease_expiration_date, :embargo_release_date, :visibility_during_embargo, :visibility_after_embargo)
end

def valid_file?(file_path)
file_path.present? && File.exist?(file_path) && !File.zero?(file_path)
end
Expand Down
20 changes: 20 additions & 0 deletions spec/actors/curation_concerns/work_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@
expect(curation_concern.visibility_after_embargo).to eq 'open'
expect(curation_concern.visibility).to eq 'authenticated'
end
context "with attached files" do
let(:attributes) do
{ title: ['New embargo'], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO,
visibility_during_embargo: 'authenticated', embargo_release_date: date.to_s,
visibility_after_embargo: 'open', visibility_during_lease: 'open',
lease_expiration_date: '2014-06-12', visibility_after_lease: 'restricted',
files: [
file
],
rights: ['http://creativecommons.org/licenses/by/3.0/us/'] }
end
it "applies it to attached files" do
subject.create
file = curation_concern.generic_files.first
expect(file).to be_persisted
expect(file.visibility_during_embargo).to eq 'authenticated'
expect(file.visibility_after_embargo).to eq 'open'
expect(file.visibility).to eq 'authenticated'
end
end
end

context 'when embargo_release_date is in the past' do
Expand Down

0 comments on commit 23ca380

Please sign in to comment.