Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure HashWithIndifferentAccess #971

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def create_file_set(attrs)
end

def create_work(attrs)
# NOTE: We do not add relationships here; that is part of the create
# relationships job.
# NOTE: We do not add relationships here; that is part of the create relationships job.
attrs = HashWithIndifferentAccess.new(attrs)
perform_transaction_for(object: object, attrs: attrs) do
uploaded_files = uploaded_files_from(attrs)
file_set_params = file_set_params_for(uploaded_files, combined_files_with(remote_files: attrs["remote_files"]))
Expand All @@ -259,13 +259,13 @@ def create_work(attrs)
'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: file_set_params },
"change_set.set_user_as_depositor" => { user: @user },
"work_resource.change_depositor" => { user: @user },
'work_resource.save_acl' => { permissions_params: [attrs['visibility'] || 'open'].compact }
'work_resource.save_acl' => { permissions_params: [attrs.try('visibility') || 'open'].compact }
)
end
end

def combined_files_with(remote_files:)
thumbnail_url = self.attributes['thumbnail_url']
thumbnail_url = HashWithIndifferentAccess.new(self.attributes)['thumbnail_url']
return [thumbnail_url] if remote_files.blank?
@combined_files ||= (thumbnail_url.present? ? remote_files + [thumbnail_url] : remote_files)
end
Expand All @@ -277,7 +277,7 @@ def file_set_params_for(uploaded_files, combined_files)
# - included in the file_set_metadata.yaml
# - overriden in file_set_args from Hyrax::WorkUploadsHandler
additional_attributes = combined_files.map do |hash|
hash.reject { |key, _| key == 'url' || key == 'file_name' }
hash.reject { |key, _| key.to_s == 'url' || key.to_s == 'file_name' }
end

file_attrs = []
Expand Down Expand Up @@ -353,6 +353,7 @@ def permitted_attributes
end

def update_work(attrs)
attrs = HashWithIndifferentAccess.new(attrs)
perform_transaction_for(object: object, attrs: attrs) do
uploaded_files = uploaded_files_from(attrs)
file_set_params = file_set_params_for(uploaded_files, combined_files_with(remote_files: attrs["remote_files"]))
Expand Down
Loading