Skip to content

Commit

Permalink
limit embargo/lease date validation to create
Browse files Browse the repository at this point in the history
introduce a wrapper for `Hydra::AccessControls::Embargoable` with less agressive
validation behavior.
  • Loading branch information
tamsin johnson committed May 7, 2021
1 parent 6adbe21 commit cd5d22c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
22 changes: 22 additions & 0 deletions app/models/concerns/hyrax/embargoable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true
module Hyrax
module Embargoable
extend ActiveSupport::Concern
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
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
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

0 comments on commit cd5d22c

Please sign in to comment.