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

5844 deactivated embargoes #6098

Merged
merged 25 commits into from Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9371fbe
Merge branch 'main' into hyrax-5844-cannot-remove-embargo-from-work-2
alishaevn Jun 26, 2023
2ef464b
update the solr_params[:fq] value in #with_deactivated_embargos to ma…
alishaevn Jun 26, 2023
c4945a9
Merge branch 'main' into 5844-deactivated-embargoes
alishaevn Jun 27, 2023
6eb9420
properly set "embargo.embargo_history" when deactivating an embargo o…
alishaevn Jun 27, 2023
6293527
save the embargo on the work after its been updated, when deactivati…
alishaevn Jun 28, 2023
3962007
wip: able to display past embargoes on the edit embargo page, and und…
alishaevn Jun 28, 2023
d02bf8b
verify that there is an embargo release date in #enforced? before say…
alishaevn Jun 29, 2023
d3c8b7f
index the "embargo_history_ssim" value in solr when an embargo has be…
alishaevn Jun 29, 2023
a448ac4
stop persisting the work in EmbargoActor#destroy because the AccessCo…
alishaevn Jun 29, 2023
58988e8
Merge branch 'main' into 5844-deactivated-embargoes
orangewolf Jul 4, 2023
f9b081e
save the embargo id to the work as a reference instead of the embargo…
alishaevn Jul 11, 2023
30e7794
lease structure now matches embargo structure
sephirothkod Jul 11, 2023
efffe9b
save the embargo and lease before setting it, so we have access to th…
alishaevn Jul 12, 2023
ad13a6e
embargoes and leases are no longer saved to the work itself. instead,…
alishaevn Jul 12, 2023
bb3c29b
rubocop fixes
alishaevn Jul 12, 2023
e91a0b9
embargoes and leases now save during changeset sync along with the re…
sephirothkod Jul 12, 2023
8318274
update leases to work like embargoes. use the safe navigation operato…
alishaevn Jul 12, 2023
fb5c19b
fix some specs.
alishaevn Jul 12, 2023
062f321
fix lease spec issues
sephirothkod Jul 13, 2023
355ab8e
embargo actor spec fixes
sephirothkod Jul 13, 2023
a4d035f
decouple the deactivated lease work from the deactivated embargo work…
alishaevn Jul 14, 2023
44930da
fix one more embargo manager spec
alishaevn Jul 14, 2023
7d99819
move a few more lease related changes to #6111
alishaevn Jul 17, 2023
ccdef32
Update app/services/hyrax/embargo_manager.rb
alishaevn Jul 19, 2023
cb0a4f4
Update app/models/hyrax/resource.rb
alishaevn Jul 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/actors/hyrax/actors/embargo_actor.rb
Expand Up @@ -16,8 +16,9 @@ def destroy
when Valkyrie::Resource
embargo_manager = Hyrax::EmbargoManager.new(resource: work)
return if embargo_manager.embargo.embargo_release_date.blank?
embargo_manager.nullify(force: true)
embargo_manager.release(force: true)

embargo_manager.deactivate!
work.embargo = Hyrax.persister.save(resource: embargo_manager.embargo)
Hyrax::AccessControlList(work).save
else
work.embargo_visibility! # If the embargo has lapsed, update the current visibility.
Expand Down
Expand Up @@ -15,7 +15,7 @@ def index
# Removes a single embargo
def destroy
Hyrax::Actors::EmbargoActor.new(curation_concern).destroy
flash[:notice] = embargo_history(curation_concern)
flash[:notice] = embargo_history(curation_concern).last
if curation_concern.work? && work_has_file_set_members?(curation_concern)
redirect_to confirm_permission_path
else
Expand Down
1 change: 1 addition & 0 deletions app/forms/hyrax/forms/work_embargo_form.rb
Expand Up @@ -11,6 +11,7 @@ module Forms
# +EmbargoesControllerBehavior+.
class WorkEmbargoForm < Hyrax::ChangeSet
property :embargo, form: Hyrax::Forms::Embargo, populator: :embargo_populator, prepopulator: :embargo_populator
property :embargo_history, virtual: true, prepopulator: proc { |_opts| self.embargo_history = model.embargo&.embargo_history }
property :embargo_release_date, virtual: true, prepopulator: proc { |_opts| self.embargo_release_date = model.embargo&.embargo_release_date }
property :visibility_after_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_after_embargo = model.embargo&.visibility_after_embargo }
property :visibility_during_embargo, virtual: true, prepopulator: proc { |_opts| self.visibility_during_embargo = model.embargo&.visibility_during_embargo }
Expand Down
5 changes: 4 additions & 1 deletion app/indexers/hyrax/valkyrie_work_indexer.rb
Expand Up @@ -44,11 +44,14 @@ def admin_set_label(resource)
end

def index_embargo(doc)
if Hyrax::EmbargoManager.new(resource: resource).under_embargo?
if resource.embargo&.active?
doc['embargo_release_date_dtsi'] = resource.embargo.embargo_release_date&.to_datetime
doc['visibility_after_embargo_ssim'] = resource.embargo.visibility_after_embargo
doc['visibility_during_embargo_ssim'] = resource.embargo.visibility_during_embargo
else
doc['embargo_history_ssim'] = resource&.embargo&.embargo_history
end

doc
end

Expand Down
13 changes: 12 additions & 1 deletion app/models/hyrax/resource.rb
Expand Up @@ -35,7 +35,7 @@ class Resource < Valkyrie::Resource
include Hyrax::WithEvents

attribute :alternate_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID)
attribute :embargo, Hyrax::Embargo.optional
attribute :embargo_id, Valkyrie::Types::ID
attribute :lease, Hyrax::Lease.optional

delegate :edit_groups, :edit_groups=,
Expand Down Expand Up @@ -103,6 +103,17 @@ def visibility
visibility_reader.read
end

def embargo=(value)
raise TypeError "can't convert #{value.class} into Hyrax::Embargo" unless value.is_a? Hyrax::Embargo

@embargo = value
self.embargo_id = @embargo.id
end

def embargo
@embargo ||= (Hyrax.query_service.find_by(id: embargo_id) if embargo_id.present?)
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
end

protected

def visibility_writer
Expand Down
34 changes: 32 additions & 2 deletions app/services/hyrax/embargo_manager.rb
Expand Up @@ -17,6 +17,7 @@ module Hyrax
# - "Enforced" means the object's visibility matches the pre-release
# visibility of the embargo; i.e. the embargo has been applied,
# but not released.
# "Deactivate" means that the existing embargo will be removed
alishaevn marked this conversation as resolved.
Show resolved Hide resolved
#
# Note that an resource may be `#under_embargo?` even if the embargo is not
# be `#enforced?` (in this case, the application should seek to apply the
Expand Down Expand Up @@ -119,6 +120,22 @@ def release_embargo_for!(resource:, query_service: Hyrax.query_service)
end
end

# Deactivates the embargo and logs a message to the embargo_history property
def deactivate!
embargo_state = embargo.active? ? 'active' : 'expired'
embargo_record = embargo_history_message(
embargo_state,
Time.zone.today,
DateTime.parse(embargo.embargo_release_date),
embargo.visibility_during_embargo,
embargo.visibility_after_embargo
)

nullify(force: true)
release(force: true)
embargo.embargo_history += [embargo_record]
end

##
# Copies and applies the embargo to a new (target) resource.
#
Expand All @@ -128,7 +145,7 @@ def release_embargo_for!(resource:, query_service: Hyrax.query_service)
def copy_embargo_to(target:)
return false unless under_embargo?

target.embargo = Embargo.new(clone_attributes)
target.embargo = Hyrax.persister.save(resource: Embargo.new(clone_attributes))
self.class.apply_embargo_for(resource: target)
end

Expand All @@ -152,7 +169,8 @@ def apply!
##
# @return [Boolean]
def enforced?
embargo.visibility_during_embargo.to_s == resource.visibility
embargo.embargo_release_date.present? &&
(embargo.visibility_during_embargo.to_s == resource.visibility)
end

##
Expand Down Expand Up @@ -213,5 +231,17 @@ def clone_attributes
def core_attribute_keys
[:visibility_after_embargo, :visibility_during_embargo, :embargo_release_date]
end

protected

# Create the log message used when deactivating an embargo
def embargo_history_message(state, deactivate_date, release_date, visibility_during, visibility_after)
I18n.t 'hydra.embargo.history_message',
state: state,
deactivate_date: deactivate_date,
release_date: release_date,
visibility_during: visibility_during,
visibility_after: visibility_after
end
end
end
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.embargo = @persister.save(resource: unsaved.embargo) if unsaved.embargo.present?
saved = @persister.save(resource: unsaved)
bkiahstroud marked this conversation as resolved.
Show resolved Hide resolved
rescue StandardError => err
return Failure(["Failed save on #{change_set}\n\t#{err.message}", change_set.resource])
Expand Down
7 changes: 4 additions & 3 deletions spec/actors/hyrax/actors/embargo_actor_spec.rb
Expand Up @@ -6,8 +6,9 @@

describe "#destroy" do
let(:work) do
FactoryBot.valkyrie_create(:hyrax_resource, :under_embargo)
FactoryBot.valkyrie_create(:hyrax_resource, embargo: embargo)
end
let(:embargo) { FactoryBot.create(:hyrax_embargo) }

before do
work.visibility = authenticated_vis
Expand All @@ -33,14 +34,14 @@
FactoryBot.valkyrie_create(:hyrax_resource, embargo: embargo)
end

let(:embargo) { FactoryBot.build(:hyrax_embargo) }
let(:embargo) { FactoryBot.create(:hyrax_embargo) }
let(:embargo_manager) { Hyrax::EmbargoManager.new(resource: work) }
let(:embargo_release_date) { work.embargo.embargo_release_date }

before do
allow(Hyrax::TimeService)
.to receive(:time_in_utc)
.and_return(embargo_release_date + 1)
.and_return(embargo_release_date.to_datetime + 1)
expect(embargo_manager.under_embargo?).to eq false
end

Expand Down
6 changes: 4 additions & 2 deletions spec/factories/hyrax_embargo.rb
@@ -1,12 +1,14 @@
# frozen_string_literal: true
FactoryBot.define do
factory :hyrax_embargo, class: "Hyrax::Embargo" do
embargo_release_date { Time.zone.today + 10 }
embargo_release_date { (Time.zone.today + 10).to_s }
visibility_after_embargo { 'open' }
visibility_during_embargo { 'authenticated' }

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
2 changes: 1 addition & 1 deletion spec/factories/hyrax_resource.rb
Expand Up @@ -5,7 +5,7 @@
FactoryBot.define do
factory :hyrax_resource, class: "Hyrax::Resource" do
trait :under_embargo do
association :embargo, factory: :hyrax_embargo
embargo_id { FactoryBot.create(:hyrax_embargo).id }
end

trait :under_lease do
Expand Down
4 changes: 3 additions & 1 deletion spec/models/hyrax/resource_spec.rb
Expand Up @@ -19,7 +19,9 @@
subject(:resource) { described_class.new(embargo: embargo) }
let(:embargo) { FactoryBot.build(:hyrax_embargo) }

it 'saves the embargo' do
it 'saves the embargo id' do
resource.embargo = Hyrax.persister.save(resource: embargo)

expect(Hyrax.persister.save(resource: resource).embargo)
.to have_attributes(embargo_release_date: embargo.embargo_release_date)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/services/hyrax/embargo_manager_spec.rb
Expand Up @@ -129,8 +129,8 @@
expect(manager.embargo)
.to have_attributes visibility_after_embargo: 'open',
visibility_during_embargo: 'authenticated',
embargo_release_date: an_instance_of(Date),
embargo_history: be_empty
embargo_release_date: an_instance_of(String),
embargo_history: match_array([])
end
end
end
Expand Down