Module: Hydra::AccessControls::Embargoable
- Extended by:
- ActiveSupport::Concern
- Includes:
- WithAccessRight
- Defined in:
- app/models/concerns/hydra/access_controls/embargoable.rb
Instance Method Summary collapse
- #active_lease? ⇒ Boolean
- #apply_embargo(release_date, visibility_during = nil, visibility_after = nil) ⇒ Object
- #apply_lease(release_date, visibility_during = nil, visibility_after = nil) ⇒ Object
-
#deactivate_embargo! ⇒ Object
Deactivates the embargo and logs a message to the embargo object.
- #deactivate_lease! ⇒ Object
- #embargo_indexer_class ⇒ Object
-
#embargo_visibility! ⇒ Object
Set the current visibility to match what is described in the embargo.
- #enforce_future_date_for_embargo? ⇒ Boolean
- #enforce_future_date_for_lease? ⇒ Boolean
-
#existing_or_new_embargo ⇒ Object
if the embargo exists return it, if not, build one and return it.
-
#existing_or_new_lease ⇒ Object
if the lease exists return it, if not, build one and return it.
- #lease_indexer_class ⇒ Object
-
#lease_visibility! ⇒ Object
Set the current visibility to match what is described in the lease.
- #to_solr(solr_doc = {}) ⇒ Object
- #under_embargo? ⇒ Boolean
-
#validate_visibility_complies_with_embargo ⇒ Object
Validate that the current visibility is what is specified in the embargo.
- #validate_visibility_complies_with_lease ⇒ Object
-
#visibility=(value) ⇒ Object
If changing away from embargo or lease, this will deactivate the lease/embargo before proceeding.
Instance Method Details
#active_lease? ⇒ Boolean
55 56 57 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 55 def active_lease? lease && lease.active? end |
#apply_embargo(release_date, visibility_during = nil, visibility_after = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 69 def (release_date, visibility_during=nil, visibility_after=nil) self. = release_date self. = visibility_during unless visibility_during.nil? self. = visibility_after unless visibility_after.nil? visibility_will_change! if .changed? end |
#apply_lease(release_date, visibility_during = nil, visibility_after = nil) ⇒ Object
131 132 133 134 135 136 137 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 131 def apply_lease(release_date, visibility_during=nil, visibility_after=nil) self.lease_expiration_date = release_date self.visibility_during_lease = visibility_during unless visibility_during.nil? self.visibility_after_lease = visibility_after unless visibility_after.nil? lease_visibility! visibility_will_change! if lease.changed? end |
#deactivate_embargo! ⇒ Object
Deactivates the embargo and logs a message to the embargo object. Marks this record as dirty so that it will get reindexed.
79 80 81 82 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 79 def && .deactivate! visibility_will_change! end |
#deactivate_lease! ⇒ Object
139 140 141 142 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 139 def deactivate_lease! lease && lease.deactivate! visibility_will_change! end |
#embargo_indexer_class ⇒ Object
43 44 45 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 43 def EmbargoIndexer end |
#embargo_visibility! ⇒ Object
Set the current visibility to match what is described in the embargo.
103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 103 def return unless if self. = ? : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE self. = ? : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED self.visibility = else self.visibility = ? : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED end end |
#enforce_future_date_for_embargo? ⇒ Boolean
22 23 24 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 22 def end |
#enforce_future_date_for_lease? ⇒ Boolean
18 19 20 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 18 def enforce_future_date_for_lease? lease end |
#existing_or_new_embargo ⇒ Object
if the embargo exists return it, if not, build one and return it
27 28 29 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 27 def || end |
#existing_or_new_lease ⇒ Object
if the lease exists return it, if not, build one and return it
32 33 34 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 32 def existing_or_new_lease lease || build_lease end |
#lease_indexer_class ⇒ Object
47 48 49 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 47 def lease_indexer_class LeaseIndexer end |
#lease_visibility! ⇒ Object
Set the current visibility to match what is described in the lease.
145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 145 def lease_visibility! if lease_expiration_date if active_lease? self.visibility_during_lease = visibility_during_lease ? visibility_during_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED self.visibility_after_lease = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE self.visibility = visibility_during_lease else self.visibility = visibility_after_lease ? visibility_after_lease : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE end end end |
#to_solr(solr_doc = {}) ⇒ Object
36 37 38 39 40 41 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 36 def to_solr(solr_doc = {}) super.tap do |doc| doc.merge!(.new().generate_solr_document) if doc.merge!(lease_indexer_class.new(lease).generate_solr_document) if lease end end |
#under_embargo? ⇒ Boolean
51 52 53 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 51 def && .active? end |
#validate_visibility_complies_with_embargo ⇒ Object
Validate that the current visibility is what is specified in the embargo
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 85 def return true unless if expected_visibility = = "An embargo is in effect for this object until #{}. Until that time the " else expected_visibility = = "The embargo expired on #{}. The " end if visibility != expected_visibility << "visibility should be #{expected_visibility} but it is currently #{visibility}. Call embargo_visibility! on this object to repair." self.errors.add(:embargo, ) return false end true end |
#validate_visibility_complies_with_lease ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 114 def validate_visibility_complies_with_lease return true unless lease_expiration_date if active_lease? expected_visibility = visibility_during_lease = "A lease is in effect for this object until #{lease_expiration_date}. Until that time the " else expected_visibility = visibility_after_lease = "The lease expired on #{lease_expiration_date}. The " end if visibility != expected_visibility << "visibility should be #{expected_visibility} but it is currently #{visibility}. Call lease_visibility! on this object to repair." self.errors.add(:lease, ) return false end true end |
#visibility=(value) ⇒ Object
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.
62 63 64 65 66 67 |
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 62 def visibility=(value) # If changing from embargo or lease, deactivate the lease/embargo and wipe out the associated metadata before proceeding if (value) deactivate_lease! if deactivate_lease?(value) super end |