Skip to content

Commit

Permalink
move over a few more lease related changes from #6098.
Browse files Browse the repository at this point in the history
co-authored-by: braydon <braydon.justice@1268456bcltd.ca>
  • Loading branch information
alishaevn and sephirothkod committed Jul 17, 2023
1 parent 6cc1544 commit 7b19cca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/services/hyrax/lease_manager.rb
Expand Up @@ -86,7 +86,11 @@ def enforced?
##
# @return [Hyrax::Lease]
def lease
resource.lease || Lease.new
if resource[:lease_id].present?
Hyrax.query_service.find_by(id: resource[:lease_id])
else
Hyrax.persister.save(resource: Lease.new)
end
end

##
Expand Down
1 change: 1 addition & 0 deletions lib/hyrax/transactions/steps/save.rb
Expand Up @@ -33,6 +33,7 @@ def call(change_set, user: nil)
begin
new_collections = changed_collection_membership(change_set)
unsaved = change_set.sync
unsaved.lease = @persister.save(resource: unsaved.lease) if unsaved.lease.present?
saved = @persister.save(resource: unsaved)
rescue StandardError => err
return Failure(["Failed save on #{change_set}\n\t#{err.message}", change_set.resource])
Expand Down
6 changes: 4 additions & 2 deletions spec/factories/hyrax_lease.rb
@@ -1,12 +1,14 @@
# frozen_string_literal: true
FactoryBot.define do
factory :hyrax_lease, class: "Hyrax::Lease" do
lease_expiration_date { Time.zone.today + 10 }
lease_expiration_date { (Time.zone.today + 10).to_s }
visibility_after_lease { 'authenticated' }
visibility_during_lease { 'open' }

to_create do |instance|
Valkyrie.config.metadata_adapter.persister.save(resource: instance)
saved_instance = Valkyrie.config.metadata_adapter.persister.save(resource: instance)
instance.id = saved_instance.id
saved_instance
end

trait :expired do
Expand Down

0 comments on commit 7b19cca

Please sign in to comment.