-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transaction exercise: transaction solution
- Loading branch information
tamsin johnson
committed
Oct 23, 2023
1 parent
8f16983
commit bcab2bb
Showing
3 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class MintId | ||
include Dry::Monads[:result] | ||
|
||
def call(obj) | ||
return Failure[:no_identifier_attribute] unless | ||
obj.respond_to?(:identifier=) | ||
|
||
return Failure[:object_not_persisted] unless | ||
obj.try(:persisted?) | ||
|
||
user = User.find_by_user_key(obj.depositor) | ||
|
||
obj.identifier = "my_id_scheme:#{obj.id}" | ||
|
||
result = Hyrax.persister.save(resource: obj) | ||
Hyrax.publisher.publish("object.metadata.updated", object: obj, user: user) | ||
|
||
Success(result) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Hyrax::Transactions::Container.register('work_resource.mint_id', MintId.new) | ||
|
||
class ApplicationContainerOverrides | ||
extend Dry::Container::Mixin | ||
|
||
namespace 'change_set' do |ops| | ||
ops.register 'create_work' do | ||
Hyrax::Transactions::WorkCreate.new(steps: | ||
['change_set.set_default_admin_set', | ||
'change_set.ensure_admin_set', | ||
'change_set.set_user_as_depositor', | ||
'change_set.apply', | ||
'work_resource.mint_id', | ||
'work_resource.apply_permission_template', | ||
'work_resource.save_acl', | ||
'work_resource.add_file_sets', | ||
'work_resource.change_depositor', | ||
'work_resource.add_to_parent']) | ||
end | ||
end | ||
end | ||
|
||
Hyrax::Transactions::Container.merge(ApplicationContainerOverrides) |