Skip to content

Commit

Permalink
Handle InProgressEtd::NO_EMBARGO values in the actor stack
Browse files Browse the repository at this point in the history
The `PregradEmbargo` actor is responsible for setting up attributes for a
six-year pregraduation embargo when an `embargo_length` is passed during `Etd`
creation. This works more or less the same as its predecessor, but relies more
on base Hyrax behavior. The values passed here are eventually interpreted at
graduation time to determine the post-grad embargo release date.

However, the `InProgressEtd` data stores a specific string indicating that no
embargo is requested, and passes that value to the stack. This is always
interpreted as a request for a pregrad embargo.

Ideally, we would handle this at the edge of `InProgressEtd` so other parts of
the application don't need to be aware of this blessed string. It's likely that
`InProgressEtd` needs this to be round-tripabble, and the handling for
transformation of this data lives across various methods. Rather than attempt an
immediate refactor, we fix the bug by handling the special data in the actor
stack. We raise a warning so the larger fix won't get ignored.

Fixes #1485.
  • Loading branch information
Tom Johnson committed Aug 7, 2018
1 parent 90f9700 commit 1eea962
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/actors/hyrax/actors/pregrad_embargo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def create(env)
def pregraduation_embargo_attributes(env)
return {} unless env.attributes.key?(:embargo_length)

return handle_malformed_data(env) if
env.attributes.fetch(:embargo_length, nil) == InProgressEtd::NO_EMBARGO

open = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_EMBARGO

Expand All @@ -22,6 +25,25 @@ def pregraduation_embargo_attributes(env)
visibility_after_embargo: open,
visibility_during_embargo: open }
end

##
# When creating an `Etd` with no embargo, `InProgressEtd` passes a
# particular string (`InProgressEtd::NO_EMBARGO'). For the moment, we
# need to handle
#
# @todo rework callers to avoid passing this "malformed" data. We
# shouldn't need to interpret strings passed to this value until
# graduation.
def handle_malformed_data(env)
warn "#{self.class} is cleaning up non-date data passed to the " \
":embargo_length attribute. #{env.attributes[:embargo_length]} " \
"is being interpreted as a request for no embargo on " \
"#{env.attributes[:title]}."

env.attributes.delete(:embargo_length)

{}
end
end
end
end
15 changes: 15 additions & 0 deletions spec/actors/hyrax/actors/pregrad_embargo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
expect { middleware.create(env) }.not_to change { env.attributes }
end

context 'with a specific string passed from InProgressEtd' do
let(:attributes) do
{ 'title' => ['good fun'],
'creator' => ['Sneddon, River'],
'school' => ['Emory College'],
'embargo_length' => InProgressEtd::NO_EMBARGO }
end

it 'does not apply an embargo' do
expect { middleware.create(env) }
.to change { env.attributes }
.to attributes.except('embargo_length')
end
end

context 'with a requested embargo' do
let(:six_years_from_today) { Time.zone.today + 6.years }

Expand Down

0 comments on commit 1eea962

Please sign in to comment.