Skip to content

Commit

Permalink
don't attempt to save AF::WithMetadata::MetadataNode#file_hash
Browse files Browse the repository at this point in the history
`ActiveFedora::WithMetadata::MetadataNode` provides a `#file_hash` attribute,
but writing to it, even with the existing data, prevents all saves.

Wings needs to map data in and out of this class freely, and this attribute
functions as a honeypot. it baits Wings to preserve the data, and then fails
save when the converters try to do keep the existing data. since any attempt to
write this data will break save, ActiveFedora should treat it as read only.

never include `MetadataNode#file_hash` in changed attributes lists when Wings is
loaded.
  • Loading branch information
tamsin johnson authored and no-reply committed Jan 11, 2022
1 parent c52f3ea commit 64a610a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/wings/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ def self.default_sort_params
end
end

module WithMetadata
class MetadataNode
##
# @note fcrepo rejects `:file_hash` updates. the attribute is managed by
# the data store. always drop it from changed attributes.
def changed_attributes
super.except(:file_hash)
end
end
end

module Associations
class ContainerProxy
delegate :build_or_set, to: :@association
Expand Down
18 changes: 18 additions & 0 deletions spec/models/hyrax/file_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
type: contain_exactly(described_class::Use::ORIGINAL_FILE))
end

context 'when saved with a file' do
subject(:file_metadata) { Hyrax.custom_queries.find_file_metadata_by(id: file.id) }
let(:file_set) { FactoryBot.valkyrie_create(:hyrax_file_set) }

let(:file) do
Hyrax.storage_adapter.upload(resource: file_set,
file: Tempfile.new('blah'),
original_filename: 'blah.txt')
end

it 'can be changed and saved' do
file_metadata.creator = 'Tove'

expect(Hyrax.persister.save(resource: file_metadata).creator)
.to contain_exactly('Tove')
end
end

describe '#original_file?' do
context 'when use says file is the original file' do
before do
Expand Down

0 comments on commit 64a610a

Please sign in to comment.