Module: Worthwhile::ManagesEmbargoesActor

Extended by:
ActiveSupport::Concern
Included in:
CurationConcern::GenericFileActor, CurationConcern::GenericWorkActor
Defined in:
app/actors/concerns/worthwhile/manages_embargoes_actor.rb

Overview

To use this module, include it in your Actor class

and then add its interpreters wherever you want them to run.
They should be called _before_ apply_attributes is called because
they intercept values in the attributes Hash.

@example
class MyActorClass < BaseActor
   include Worthwile::ManagesEmbargoesActor

   def create
     interpret_visibility && super && copy_visibility
   end

   def update
     interpret_visibility && super && copy_visibility
   end
end

Instance Method Summary collapse

Instance Method Details

#copy_visibilityObject



74
75
76
77
# File 'app/actors/concerns/worthwhile/manages_embargoes_actor.rb', line 74

def copy_visibility
  Sufia.queue.push(VisibilityCopyWorker.new(curation_concern.id)) if @needs_to_copy_visibility
  true
end

#interpret_embargo_visibilityObject

If user has set visibility to embargo, interprets the relevant information and applies it Returns false if there are any errors and sets an error on the curation_concern



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/actors/concerns/worthwhile/manages_embargoes_actor.rb', line 31

def interpret_embargo_visibility
  if attributes[:visibility] != Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO
    # clear embargo_release_date even if it isn't being used. Otherwise it sets the embargo_date
    # even though they didn't select embargo on the form.
    attributes.delete(:visibility_during_embargo)
    attributes.delete(:visibility_after_embargo)
    attributes.delete(:embargo_release_date)
    true
  elsif !attributes[:embargo_release_date]
    curation_concern.errors.add(:visibility, 'When setting visibility to "embargo" you must also specify embargo release date.')
    false
  else
    attributes.delete(:visibility)
    curation_concern.apply_embargo(attributes[:embargo_release_date], attributes.delete(:visibility_during_embargo),
                                   attributes.delete(:visibility_after_embargo))
    @needs_to_copy_visibility = true
    true
  end
end

#interpret_lease_visibilityObject

If user has set visibility to lease, interprets the relevant information and applies it Returns false if there are any errors and sets an error on the curation_concern



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/actors/concerns/worthwhile/manages_embargoes_actor.rb', line 53

def interpret_lease_visibility
  if attributes[:visibility] != Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE
    # clear lease_expiration_date even if it isn't being used. Otherwise it sets the lease_expiration
    # even though they didn't select lease on the form.
    attributes.delete(:visibility_during_lease)
    attributes.delete(:visibility_after_lease)
    attributes.delete(:lease_expiration_date)
    true
  elsif !attributes[:lease_expiration_date]
    curation_concern.errors.add(:visibility, 'When setting visibility to "lease" you must also specify lease expiration date.')
    false
  else
    curation_concern.apply_lease(attributes[:lease_expiration_date], attributes.delete(:visibility_during_lease),
                                   attributes.delete(:visibility_after_lease))
    @needs_to_copy_visibility = true
    attributes.delete(:visibility)
    true
  end
end

#interpret_visibilityObject

Interprets embargo & lease visibility if necessary returns false if there are any errors



25
26
27
# File 'app/actors/concerns/worthwhile/manages_embargoes_actor.rb', line 25

def interpret_visibility
  interpret_embargo_visibility && interpret_lease_visibility
end