Module: CurationConcerns::ManagesEmbargoesActor
- Extended by:
- ActiveSupport::Concern
- Included in:
- FileSetActor, WorkActorBehavior
- Defined in:
- app/actors/concerns/curation_concerns/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
end
def update
interpret_visibility && super
end
end
Instance Method Summary collapse
-
#interpret_embargo_visibility(attributes = self.attributes) ⇒ Object
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.
-
#interpret_lease_visibility(attributes = self.attributes) ⇒ Object
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.
-
#interpret_visibility(attributes = self.attributes) ⇒ Object
Interprets embargo & lease visibility if necessary returns false if there are any errors.
Instance Method Details
#interpret_embargo_visibility(attributes = self.attributes) ⇒ Object
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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/actors/concerns/curation_concerns/manages_embargoes_actor.rb', line 35 def (attributes = self.attributes) if attributes[:visibility] == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO if !attributes[:embargo_release_date] curation_concern.errors.add(:visibility, 'When setting visibility to "embargo" you must also specify embargo release date.') should_continue = false else attributes.delete(:visibility) curation_concern.(attributes[:embargo_release_date], attributes.delete(:visibility_during_embargo), attributes.delete(:visibility_after_embargo)) if curation_concern. curation_concern..save # See https://github.com/projecthydra/hydra-head/issues/226 end should_continue = true end else should_continue = true # clear embargo_release_date if it isn't being used. Otherwise it sets the embargo_date # even though they didn't select embargo on the form. attributes.delete(:embargo_release_date) end attributes.delete(:visibility_during_embargo) attributes.delete(:visibility_after_embargo) should_continue end |
#interpret_lease_visibility(attributes = self.attributes) ⇒ Object
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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/actors/concerns/curation_concerns/manages_embargoes_actor.rb', line 64 def interpret_lease_visibility(attributes = self.attributes) if attributes[:visibility] == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE if !attributes[:lease_expiration_date] curation_concern.errors.add(:visibility, 'When setting visibility to "lease" you must also specify lease expiration date.') should_continue = false else curation_concern.apply_lease(attributes[:lease_expiration_date], attributes.delete(:visibility_during_lease), attributes.delete(:visibility_after_lease)) if curation_concern.lease curation_concern.lease.save # See https://github.com/projecthydra/hydra-head/issues/226 end attributes.delete(:visibility) should_continue = true end else # clear lease_expiration_date if it isn't being used. Otherwise it sets the lease_expiration # even though they didn't select lease on the form. attributes.delete(:lease_expiration_date) should_continue = true end attributes.delete(:visibility_during_lease) attributes.delete(:visibility_after_lease) should_continue end |
#interpret_visibility(attributes = self.attributes) ⇒ Object
Interprets embargo & lease visibility if necessary returns false if there are any errors
25 26 27 28 29 30 31 |
# File 'app/actors/concerns/curation_concerns/manages_embargoes_actor.rb', line 25 def interpret_visibility(attributes = self.attributes) should_continue = (attributes) && interpret_lease_visibility(attributes) if attributes[:visibility] curation_concern.visibility = attributes[:visibility] end should_continue end |