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

use a helper for lease/embargo expiration #4304

Merged
merged 1 commit into from
May 12, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/helpers/hyrax/embargo_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,16 @@ def assets_under_embargo
def assets_with_deactivated_embargoes
@assets_with_deactivated_embargoes ||= EmbargoService.assets_with_deactivated_embargoes
end

##
# @since 3.0.0
#
# @param [Valkyrie::Resource, ActiveFedora::Base] resource
#
# @return [Boolean] whether the resource has an embargo that is currently
# enforced (regardless of whether it has expired)
def embargo_enforced?(resource)
!resource.embargo_release_date.nil?
end
end
end
11 changes: 11 additions & 0 deletions app/helpers/hyrax/lease_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,16 @@ def assets_under_lease
def assets_with_deactivated_leases
@assets_with_deactivated_leases ||= LeaseService.assets_with_deactivated_leases
end

##
# @since 3.0.0
#
# @param [Valkyrie::Resource, ActiveFedora::Base] resource
#
# @return [Boolean] whether the resource has an lease that is currently
# enforced (regardless of whether it has expired)
def lease_enforced?(resource)
!resource.lease_expiration_date.nil?
end
end
end
4 changes: 2 additions & 2 deletions app/views/hyrax/base/_form_permission.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% # This is used by works and by FileSet and the layout (col-6 vs col-12) is different for both %>
<% if f.object.embargo_release_date %>
<% if embargo_enforced?(f.object) %>
<%= render 'form_permission_under_embargo', f: f %>
<% elsif f.object.lease_expiration_date %>
<% elsif lease_enforced?(f.object) %>
<%= render 'form_permission_under_lease', f: f %>
<% else %>
<fieldset class="set-access-controls">
Expand Down
4 changes: 2 additions & 2 deletions app/views/hyrax/base/_form_visibility_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if f.object.embargo_release_date %>
<% if embargo_enforced?(f.object) %>
<%= render 'form_permission_under_embargo', f: f %>
<% elsif f.object.lease_expiration_date %>
<% elsif lease_enforced?(f.object) %>
<%= render 'form_permission_under_lease', f: f %>
<% else %>
<fieldset>
Expand Down
36 changes: 36 additions & 0 deletions spec/helpers/hyrax/embargo_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

RSpec.describe Hyrax::EmbargoHelper do
let(:resource) { build(:monograph) }

describe 'embargo_enforced?' do
context 'with an ActiveFedora resource' do
let(:resource) { build(:work) }

it 'returns false' do
expect(embargo_enforced?(resource)).to be false
end

context 'when the resource is under embargo' do
let(:resource) { build(:embargoed_work) }

it 'returns true' do
expect(embargo_enforced?(resource)).to be true
end

it 'and the embargo is expired returns true' do
resource.embargo.embargo_release_date = Time.zone.today - 1

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

it 'and the embargo is deactivated returns false' do
resource.embargo.embargo_release_date = Time.zone.today - 1
resource.embargo.deactivate!

expect(embargo_enforced?(resource)).to be false
end
end
end
end
end
36 changes: 36 additions & 0 deletions spec/helpers/hyrax/lease_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

RSpec.describe Hyrax::LeaseHelper do
let(:resource) { build(:monograph) }

describe 'lease_enforced?' do
context 'with an ActiveFedora resource' do
let(:resource) { build(:work) }

it 'returns false' do
expect(lease_enforced?(resource)).to be false
end

context 'when the resource is under lease' do
let(:resource) { build(:leased_work) }

it 'returns true' do
expect(lease_enforced?(resource)).to be true
end

it 'and the lease is expired returns true' do
resource.lease.lease_expiration_date = Time.zone.today - 1

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

it 'and the lease is deactivated returns false' do
resource.lease.lease_expiration_date = Time.zone.today - 1
resource.lease.deactivate!

expect(lease_enforced?(resource)).to be false
end
end
end
end
end