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

Gh 4845 settinig lease date in past #4889

Merged
merged 3 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions app/helpers/hyrax/embargo_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def assets_with_deactivated_embargoes
# holder until we switch to Valkyrie::ChangeSet instead of Form
# objects
def embargo_enforced?(resource)
# This is a guard; from the UI rendering perspective, there's no
# active embargo enforcement until the object is saved.
return false unless resource.persisted?

case resource
when Hydra::AccessControls::Embargoable
!resource.embargo_release_date.nil?
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/hyrax/lease_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def assets_with_deactivated_leases
# holder until we switch to Valkyrie::ChangeSet instead of Form
# objects
def lease_enforced?(resource)
# This is a guard; from the UI rendering perspective, there's no
# active lease enforcement until the object is saved.
return false unless resource.persisted?

case resource
when Hydra::AccessControls::Embargoable
!resource.lease_expiration_date.nil?
Expand Down
2 changes: 2 additions & 0 deletions app/views/hyrax/base/_form_visibility_error.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= f.full_error(:visibility) %>
<%= f.full_error(:embargo_release_date) %>
<%= f.full_error(:visibility_after_embargo) %>
<%= f.full_error(:lease_expiration_date) %>
<%= f.full_error(:visibility_after_lease) %>
30 changes: 26 additions & 4 deletions spec/helpers/hyrax/embargo_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
let(:resource) { build(:monograph) }

describe 'embargo_enforced?' do
# Including this stub to preserve the spec structure before the #4845 change
before { allow(resource).to receive(:persisted?).and_return(true) }

context 'with a non-persisted object' do
let(:resource) { build(:hyrax_work, :under_embargo) }

before { Hyrax::EmbargoManager.apply_embargo_for!(resource: resource) }

it 'returns false' do
# Note: This spec echoes "embargo_enforced? with a Hyrax::Work when an embargo is enforced on the resource"
allow(resource).to receive(:persisted?).and_return false
expect(embargo_enforced?(resource)).to be false
end
end

context 'with a Hyrax::Work' do
let(:resource) { build(:hyrax_work) }

Expand Down Expand Up @@ -94,7 +109,8 @@
end

context 'with a HydraEditor::Form' do
let(:resource) { Hyrax::GenericWorkForm.new(build(:work), ability, form_controller) }
let(:resource) { Hyrax::GenericWorkForm.new(model, ability, form_controller) }
let(:model) { build(:work) }
let(:ability) { :FAKE_ABILITY }
let(:form_controller) { :FAKE_CONTROLLER }

Expand All @@ -103,17 +119,21 @@
end

context 'when the wrapped work is under embargo' do
let(:resource) { Hyrax::GenericWorkForm.new(build(:embargoed_work), ability, form_controller) }
let(:model) { build(:embargoed_work) }

it 'returns true' do
# This allow call is a tweak to preserve spec for pre #4845 patch
allow(model).to receive(:persisted?).and_return(true)

expect(embargo_enforced?(resource)).to be true
end
end
end

context 'with a Hyrax::Forms::FailedSubmissionFormWrapper' do
let(:resource) { Hyrax::Forms::FailedSubmissionFormWrapper.new(form: form, input_params: {}, permitted_params: {}) }
let(:form) { Hyrax::GenericWorkForm.new(build(:work), ability, form_controller) }
let(:form) { Hyrax::GenericWorkForm.new(model, ability, form_controller) }
let(:model) { build(:work) }
let(:ability) { :FAKE_ABILITY }
let(:form_controller) { :FAKE_CONTROLLER }

Expand All @@ -122,9 +142,11 @@
end

context 'when the wrapped work is under embargo' do
let(:form) { Hyrax::GenericWorkForm.new(build(:embargoed_work), ability, form_controller) }
let(:model) { build(:embargoed_work) }

it 'returns true' do
# This allow call is a tweak to preserve spec for pre #4845 patch
allow(model).to receive(:persisted?).and_return(true)
expect(embargo_enforced?(resource)).to be true
end
end
Expand Down
29 changes: 25 additions & 4 deletions spec/helpers/hyrax/lease_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
let(:resource) { build(:monograph) }

describe 'lease_enforced?' do
# Including this stub to preserve the spec structure before the #4845 change
before { allow(resource).to receive(:persisted?).and_return(true) }

context 'with a non-persisted object' do
let(:resource) { build(:hyrax_work, :under_lease) }

before { Hyrax::LeaseManager.apply_lease_for!(resource: resource) }

it 'returns false' do
# Note: This spec echoes "lease_enforced? with a Hyrax::Work when a lease is enforced on the resource"
allow(resource).to receive(:persisted?).and_return false
expect(lease_enforced?(resource)).to be false
end
end

context 'with a Hyrax::Work' do
let(:resource) { build(:hyrax_work) }

Expand Down Expand Up @@ -92,7 +107,8 @@
end

context 'with a HydraEditor::Form' do
let(:resource) { Hyrax::GenericWorkForm.new(build(:work), ability, form_controller) }
let(:resource) { Hyrax::GenericWorkForm.new(model, ability, form_controller) }
let(:model) { build(:work) }
let(:ability) { :FAKE_ABILITY }
let(:form_controller) { :FAKE_CONTROLLER }

Expand All @@ -101,17 +117,20 @@
end

context 'when the wrapped work is under lease' do
let(:resource) { Hyrax::GenericWorkForm.new(build(:leased_work), ability, form_controller) }
let(:model) { build(:leased_work) }

it 'returns true' do
# This allow call is a tweak to preserve spec for pre #4845 patch
allow(model).to receive(:persisted?).and_return(true)
expect(lease_enforced?(resource)).to be true
end
end
end

context 'with a Hyrax::Forms::FailedSubmissionFormWrapper' do
let(:resource) { Hyrax::Forms::FailedSubmissionFormWrapper.new(form: form, input_params: {}, permitted_params: {}) }
let(:form) { Hyrax::GenericWorkForm.new(build(:work), ability, form_controller) }
let(:model) { build(:work) }
let(:form) { Hyrax::GenericWorkForm.new(model, ability, form_controller) }
let(:ability) { :FAKE_ABILITY }
let(:form_controller) { :FAKE_CONTROLLER }

Expand All @@ -120,9 +139,11 @@
end

context 'when the wrapped work is under embargo' do
let(:form) { Hyrax::GenericWorkForm.new(build(:leased_work), ability, form_controller) }
let(:model) { build(:leased_work) }

it 'returns true' do
# This allow call is a tweak to preserve spec for pre #4845 patch
allow(model).to receive(:persisted?).and_return(true)
expect(lease_enforced?(resource)).to be true
end
end
Expand Down