Skip to content

Commit

Permalink
Merge pull request #5008 from sul-dlss/t4997-embargo_release
Browse files Browse the repository at this point in the history
Change EmbargoReleaseService to use RepositoryObject.
  • Loading branch information
jcoyne authored May 17, 2024
2 parents eaa99ac + 03bfe3b commit e837761
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
3 changes: 3 additions & 0 deletions app/models/repository_object_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ class RepositoryObjectVersion < ApplicationRecord
has_many :user_versions, dependent: :destroy

has_one :head_version_of, class_name: 'RepositoryObject', inverse_of: :head_version, dependent: nil

scope :in_virtual_objects, ->(member_druid) { where("structural #> '{hasMemberOrders,0}' -> 'members' ? :druid", druid: member_druid) }
scope :members_of_collection, ->(collection_druid) { where("structural -> 'isMemberOf' ? :druid", druid: collection_druid) }
# Note that this query is slow. Creating a timestamp index on the releaseDate field is not supported by PG.
scope :embargoed_and_releaseable, -> { where("(access -> 'embargo' ->> 'releaseDate')::timestamp <= ?", Time.zone.now) }

validates :version, :version_description, presence: true
after_save :update_object_source_id
Expand Down
2 changes: 1 addition & 1 deletion app/services/embargo_release_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class EmbargoReleaseService
def self.release_all
# Find objects to process
embargoed_items_to_release = Dro.embargoed_and_releaseable
embargoed_items_to_release = RepositoryObject.currently_embargoed_and_releaseable

return Rails.logger.info('No objects to process') if embargoed_items_to_release.none?

Expand Down
28 changes: 0 additions & 28 deletions spec/factories/dros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,4 @@
}
end
end

trait :with_embargo do
access do
{
view: 'dark',
download: 'dark',
embargo: {
releaseDate: 1.year.from_now.iso8601,
view: 'world',
download: 'world'
}
}
end
end

trait :with_releasable_embargo do
access do
{
view: 'dark',
download: 'dark',
embargo: {
releaseDate: 1.month.ago.iso8601,
view: 'world',
download: 'world'
}
}
end
end
end
49 changes: 49 additions & 0 deletions spec/factories/repository_object_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@
closed_at { nil }
end

trait :with_repository_object do
repository_object

after(:build) do |repository_object_version, _evaluator|
repository_object = repository_object_version.repository_object
# Repository object will already have a version 1, so delete it.
if repository_object_version.version == 1 && repository_object.versions.present?
repository_object.update(head_version: nil, opened_version: nil, last_closed_version: nil)
repository_object.versions.first.destroy!
end
repository_object.versions << repository_object_version
repository_object.head_version = repository_object_version
if repository_object_version.closed_at.present?
repository_object.last_closed_version = repository_object_version
else
repository_object.opened_version = repository_object_version
end
repository_object.save!
end
end

trait :dro_repository_object_version do # rubocop:disable Lint/EmptyBlock
end

Expand Down Expand Up @@ -98,4 +119,32 @@
end
structural { nil }
end

trait :with_embargo do
access do
{
view: 'dark',
download: 'dark',
embargo: {
releaseDate: 1.year.from_now.iso8601,
view: 'world',
download: 'world'
}
}
end
end

trait :with_releasable_embargo do
access do
{
view: 'dark',
download: 'dark',
embargo: {
releaseDate: 1.month.ago.iso8601,
view: 'world',
download: 'world'
}
}
end
end
end
6 changes: 3 additions & 3 deletions spec/services/embargo_release_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@
end

describe '#release_all' do
let!(:item_with_releasable_embargo) { create(:ar_dro, :with_releasable_embargo) }
let!(:item_with_releasable_embargo) { create(:repository_object_version, :with_repository_object, :with_releasable_embargo).repository_object }

before do
create(:ar_dro)
create(:ar_dro, :with_embargo)
create(:repository_object_version, :with_repository_object)
create(:repository_object_version, :with_repository_object, :with_embargo)
allow(described_class).to receive(:release)
end

Expand Down

0 comments on commit e837761

Please sign in to comment.