From fb356907719c0019b2704ff8fe251c5be3d947b0 Mon Sep 17 00:00:00 2001 From: tamsin johnson Date: Fri, 7 May 2021 10:27:22 -0700 Subject: [PATCH] limit embargo/lease date validation to create introduce a wrapper for `Hydra::AccessControls::Embargoable` with less agressive validation behavior. --- app/models/concerns/hyrax/embargoable.rb | 21 +++++++++++++++++++ app/models/concerns/hyrax/work_behavior.rb | 2 +- .../active_fedora_converter/default_work.rb | 15 +++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/models/concerns/hyrax/embargoable.rb diff --git a/app/models/concerns/hyrax/embargoable.rb b/app/models/concerns/hyrax/embargoable.rb new file mode 100644 index 0000000000..54defa890b --- /dev/null +++ b/app/models/concerns/hyrax/embargoable.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +module Hyrax + module Embargoable + included { include Hydra::AccessControls::Embargoable } + + validates :lease_expiration_date, 'hydra/future_date': true, on: :create + validates :embargo_release_date, 'hydra/future_date': true, on: :create + + ## + # 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 diff --git a/app/models/concerns/hyrax/work_behavior.rb b/app/models/concerns/hyrax/work_behavior.rb index 71eaecca0f..8f44eed930 100644 --- a/app/models/concerns/hyrax/work_behavior.rb +++ b/app/models/concerns/hyrax/work_behavior.rb @@ -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 diff --git a/lib/wings/active_fedora_converter/default_work.rb b/lib/wings/active_fedora_converter/default_work.rb index d23c1acb0d..ada7e8853f 100644 --- a/lib/wings/active_fedora_converter/default_work.rb +++ b/lib/wings/active_fedora_converter/default_work.rb @@ -100,6 +100,9 @@ class DefaultWork < ActiveFedora::Base include Hydra::AccessControls::Embargoable 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 @@ -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