Module: Hydra::AccessControls::Embargoable

Extended by:
ActiveSupport::Concern
Includes:
WithAccessRight
Defined in:
app/models/concerns/hydra/access_controls/embargoable.rb

Instance Method Summary collapse

Instance Method Details

#active_lease?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 38

def active_lease?
  lease && lease.active?
end

#apply_embargo(release_date, visibility_during = nil, visibility_after = nil) ⇒ Object



56
57
58
59
60
61
62
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 56

def apply_embargo(release_date, visibility_during=nil, visibility_after=nil)
  self.embargo_release_date = release_date
  self.visibility_during_embargo = visibility_during unless visibility_during.nil?
  self.visibility_after_embargo = visibility_after unless visibility_after.nil?
  embargo_visibility!
  visibility_will_change!
end

#apply_lease(release_date, visibility_during = nil, visibility_after = nil) ⇒ Object



127
128
129
130
131
132
133
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 127

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!
end

#deactivate_embargo!Object



64
65
66
67
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 64

def deactivate_embargo!
  embargo && embargo.deactivate!
  visibility_will_change!
end

#deactivate_lease!Object



135
136
137
138
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 135

def deactivate_lease!
  lease && lease.deactivate!
  visibility_will_change!
end

#embargo_visibility!Object

Set the current visibility to match what is described in the embargo.



94
95
96
97
98
99
100
101
102
103
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 94

def embargo_visibility!
  return unless embargo_release_date
  if under_embargo?
    self.visibility_during_embargo = visibility_during_embargo ? visibility_during_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
    self.visibility_after_embargo = visibility_after_embargo ? visibility_after_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
    self.visibility = visibility_during_embargo
  else
    self.visibility = visibility_after_embargo ? visibility_after_embargo : Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
  end
end

#existing_or_new_embargoObject

if the embargo exists return it, if not, build one and return it



18
19
20
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 18

def existing_or_new_embargo
  embargo || build_embargo
end

#existing_or_new_leaseObject

if the lease exists return it, if not, build one and return it



23
24
25
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 23

def existing_or_new_lease
  lease || build_lease
end

#lease_visibility!Object

Set the current visibility to match what is described in the lease.



141
142
143
144
145
146
147
148
149
150
151
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 141

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



27
28
29
30
31
32
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 27

def to_solr(solr_doc = {})
  super.tap do |doc|
    doc.merge!(embargo.to_hash) if embargo
    doc.merge!(lease.to_hash) if lease
  end
end

#under_embargo?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 34

def under_embargo?
  embargo && embargo.active?
end

#validate_embargoObject

Validate that the current visibility is what is specified in the embargo



70
71
72
73
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 70

def validate_embargo
  Deprecation.warn Embargoable, "validate_embargo is deprecated and will be removed in hydra-access-controls 9.0.0. Use validate_visibility_complies_with_embargo instead."
  validate_visibility_complies_with_embargo
end

#validate_leaseObject



105
106
107
108
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 105

def validate_lease
  Deprecation.warn Embargoable, "validate_lease is deprecated and will be removed in hydra-access-controls 9.0.0. Use validate_visibility_complies_with_lease instead."
  validate_visibility_complies_with_lease
end

#validate_visibility_complies_with_embargoObject

Validate that the current visibility is what is specified in the embargo



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 76

def validate_visibility_complies_with_embargo
  return true unless embargo_release_date
  if under_embargo?
    expected_visibility = visibility_during_embargo
    failure_message = "An embargo is in effect for this object until #{embargo_release_date}.  Until that time the "
  else
    expected_visibility = visibility_after_embargo
    failure_message = "The embargo expired on #{embargo_release_date}.  The "
  end
  if visibility != expected_visibility
    failure_message << "visibility should be #{expected_visibility} but it is currently #{visibility}.  Call embargo_visibility! on this object to repair."
    self.errors[:embargo] << failure_message
    return false
  end
  true
end

#validate_visibility_complies_with_leaseObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 110

def validate_visibility_complies_with_lease
  return true unless lease_expiration_date
  if active_lease?
    expected_visibility = visibility_during_lease
    failure_message = "A lease is in effect for this object until #{lease_expiration_date}.  Until that time the "
  else
    expected_visibility = visibility_after_lease
    failure_message = "The lease expired on #{lease_expiration_date}.  The "
  end
  if visibility != expected_visibility
    failure_message << "visibility should be #{expected_visibility} but it is currently #{visibility}.  Call lease_visibility! on this object to repair."
    self.errors[:lease] << failure_message
    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.



45
46
47
48
49
50
51
52
53
54
# File 'app/models/concerns/hydra/access_controls/embargoable.rb', line 45

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
  super
end