app/models/concerns/hydra/access_controls/embargoable.rb in hydra-access-controls-9.2.0 vs app/models/concerns/hydra/access_controls/embargoable.rb in hydra-access-controls-9.2.1
- old
+ new
@@ -3,11 +3,12 @@
module Embargoable
extend ActiveSupport::Concern
include Hydra::AccessControls::WithAccessRight
included do
- validates :embargo_release_date, :lease_expiration_date, :'hydra/future_date' => true
+ validates :lease_expiration_date, :'hydra/future_date' => true, if: :lease
+ validates :embargo_release_date, :'hydra/future_date' => true, if: :embargo
belongs_to :embargo, predicate: Hydra::ACL.hasEmbargo, class_name: 'Hydra::AccessControls::Embargo'
belongs_to :lease, predicate: Hydra::ACL.hasLease, class_name: 'Hydra::AccessControls::Lease'
delegate :visibility_during_embargo, :visibility_during_embargo=, :visibility_after_embargo, :visibility_after_embargo=, :embargo_release_date, :embargo_release_date=, :embargo_history, :embargo_history=, to: :existing_or_new_embargo
@@ -42,16 +43,12 @@
# If changing away from embargo or lease, this will deactivate the lease/embargo before proceeding.
# The lease_visibility! and embargo_visibility! methods rely on this to deactivate the lease when applicable.
def visibility=(value)
# If changing from embargo or lease, deactivate the lease/embargo and wipe out the associated metadata before proceeding
- if !embargo_release_date.nil?
- deactivate_embargo! unless value == visibility_during_embargo
- end
- if !lease_expiration_date.nil?
- deactivate_lease! unless value == visibility_during_lease
- end
+ deactivate_embargo! if deactivate_embargo?(value)
+ deactivate_lease! if deactivate_lease?(value)
super
end
def apply_embargo(release_date, visibility_during=nil, visibility_after=nil)
self.embargo_release_date = release_date
@@ -147,8 +144,21 @@
else
self.visibility = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
end
end
end
+
+ private
+
+ # @return [true, false] true if there is an embargo set up and the visibility will change
+ def deactivate_embargo?(value)
+ embargo && embargo.embargo_release_date && value != embargo.visibility_during_embargo
+ end
+
+ # @return [true, false] true if there is a lease set up and the visibility will change
+ def deactivate_lease?(value)
+ lease && lease.lease_expiration_date && value != lease.visibility_during_lease
+ end
+
end
end
end