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

limit embargo/lease date validation to create #4939

Merged
merged 1 commit into from
May 7, 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
24 changes: 24 additions & 0 deletions app/models/concerns/hyrax/embargoable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
module Hyrax
module Embargoable
extend ActiveSupport::Concern
include Hydra::AccessControls::Embargoable

included do
validates :lease_expiration_date, 'hydra/future_date': true, on: :create
validates :embargo_release_date, 'hydra/future_date': true, on: :create
end

##
# Override aggressive Hydra::AccessControls validation
def enforce_future_date_for_embargo?
false
end

##
# Override aggressive Hydra::AccessControls validation
def enforce_future_date_for_lease?
false
end
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/work_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module WorkBehavior
include Naming
include CoreMetadata
include InAdminSet
include Hydra::AccessControls::Embargoable
include Hyrax::Embargoable
include GlobalID::Identification
include NestedWorks
include Suppressible
Expand Down
15 changes: 15 additions & 0 deletions lib/wings/active_fedora_converter/default_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class DefaultWork < ActiveFedora::Base
include Hydra::AccessControls::Embargoable
cjcolvar marked this conversation as resolved.
Show resolved Hide resolved
property :nested_resource, predicate: ::RDF::URI("http://example.com/nested_resource"), class_name: "Wings::ActiveFedoraConverter::NestedResource"

validates :lease_expiration_date, 'hydra/future_date': true, on: :create
validates :embargo_release_date, 'hydra/future_date': true, on: :create

class_attribute :valkyrie_class
self.valkyrie_class = Hyrax::Resource

Expand All @@ -121,6 +124,18 @@ def to_rdf_representation
alias to_s inspect
end

##
# Override aggressive Hydra::AccessControls validation
def enforce_future_date_for_embargo?
false
end

##
# Override aggressive Hydra::AccessControls validation
def enforce_future_date_for_lease?
false
end

def indexing_service
Hyrax::ValkyrieIndexer.for(resource: valkyrie_resource)
end
Expand Down
33 changes: 33 additions & 0 deletions spec/models/generic_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@
end
end

describe "embargo" do
subject(:work) { described_class.new(title: ['a title'], embargo_release_date: embargo_release_date) }
let(:embargo_release_date) { Time.zone.today + 10 }

it { is_expected.to be_valid }

context 'with a past date' do
let(:embargo_release_date) { Time.zone.today - 10 }

it { is_expected.not_to be_valid }

it 'has errors related to the date' do
expect { work.valid? }
.to change { work.errors.to_a }
.from(be_empty)
.to include("Embargo release date Must be a future date")
end
end

context 'with a saved embargo' do
let(:past) { Time.zone.today - 10 }

before { work.save! }

it 'can update the embargo with any date' do
work.embargo_release_date = past

expect(work).to be_valid
expect{ work.save! }.not_to raise_error
end
end
end

describe "delegations" do
let(:work) { described_class.new { |gw| gw.apply_depositor_metadata("user") } }
let(:proxy_depositor) { create(:user) }
Expand Down