Skip to content

Commit

Permalink
🐛🏳️ post Big refactor fixes
Browse files Browse the repository at this point in the history
Refactoring caused some bugs. At this point we are able to successfully import CSV works again.
  • Loading branch information
Shana Moore committed Mar 19, 2024
1 parent 2c7b042 commit 11b4517
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
23 changes: 19 additions & 4 deletions app/factories/bulkrax/object_factory_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,32 @@ def update
update_work(attrs)
end
end
conditionally_apply_depositor_metadata
apply_depositor_metadata
log_updated(object)
end

private

def add_user_to_collection_permissions(*args)
self.class.add_user_to_collection_permissions(*args)
arguments = args.first
self.class.add_user_to_collection_permissions(**arguments)
end

def log_created(obj)
msg = "Created #{klass.model_name.human} #{obj.id}"
Rails.logger.info("#{msg} (#{Array(attributes[work_identifier]).first})")
end

def log_updated(obj)
msg = "Updated #{klass.model_name.human} #{obj.id}"
Rails.logger.info("#{msg} (#{Array(attributes[work_identifier]).first})")
end

def log_deleted_fs(obj)
msg = "Deleted All Files from #{obj.id}"
Rails.logger.info("#{msg} (#{Array(attributes[work_identifier]).first})")
end

private

def apply_depositor_metadata
object.apply_depositor_metadata(@user) && object.save! if object.depositor.nil?
end
Expand Down
4 changes: 2 additions & 2 deletions app/factories/bulkrax/valkyrie_object_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def create_work(attrs)
perform_transaction_for(object: object, attrs: attrs) do
transactions["change_set.create_work"]
.with_step_args(
'work_resource.add_file_sets' => { uploaded_files: get_files(attrs) },
'work_resource.add_file_sets' => { uploaded_files: uploaded_files_from(attrs) },
"change_set.set_user_as_depositor" => { user: @user },
"work_resource.change_depositor" => { user: @user },
'work_resource.save_acl' => { permissions_params: [attrs['visibility'] || 'open'].compact }
Expand Down Expand Up @@ -353,7 +353,7 @@ def destroy_existing_files
@object.thumbnail_id = nil
end

def transform_attributes
def transform_attributes(update: false)
attrs = super.merge(alternate_ids: [source_identifier_value])
.symbolize_keys

Expand Down
5 changes: 4 additions & 1 deletion app/models/concerns/bulkrax/file_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def destroy_existing_files

def set_removed_filesets
local_file_sets.each do |fileset|
# TODO: We need to consider the Valkyrie pathway
return if fileset.is_a?(Valkyrie::Resource)

remove_file_set(file_set: fileset)
end
end
Expand Down Expand Up @@ -166,7 +169,7 @@ def import_files

def import_file(path)
u = Hyrax::UploadedFile.new
u.user_id = @user.id
u.user_id = user.id
u.file = CarrierWave::SanitizedFile.new(path)
update_filesets(u)
end
Expand Down

0 comments on commit 11b4517

Please sign in to comment.