-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
6126 deactivated leases #6127
6126 deactivated leases #6127
Changes from 46 commits
6cc1544
7b19cca
b8789d1
42d504b
ed8f13a
d26467d
16cdbfa
8061f33
bf1b1eb
d413323
fac77c3
0362456
c886e64
0c86b0f
1f979dc
4b5b054
6314351
33ebb3d
9975ac8
3154b19
6a59d45
5a8398f
9b64c54
530750c
cfc5d91
cef578a
10215f0
6b76967
753d216
82bb390
cee247a
5fdc19f
ff52b95
d315ec2
8ea729a
b3bd3cc
ad4f247
5c4486d
ef3f8e2
6c071cb
3c503bf
45f586b
77f7ac0
720b140
796a1f6
9896d7a
04c9c2e
9d54048
a1ea69c
b2a9f23
3e28096
8970a44
580d817
04fac65
b16bace
f992e10
96f5719
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,15 +180,18 @@ def actor | |
|
||
## | ||
# @return [#errors] | ||
# rubocop:disable Metrics/MethodLength | ||
def create_valkyrie_work | ||
form = build_form | ||
return after_create_error(form_err_msg(form)) unless form.validate(params[hash_key_for_curation_concern]) | ||
# fallback to an empty array to avoid: # NoMethodError: undefined method `has_key?' for nil:NilClass | ||
original_input_params_for_form = params[hash_key_for_curation_concern] ? params[hash_key_for_curation_concern] : {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adjusted this error handling so that |
||
return after_create_error(form_err_msg(form), original_input_params_for_form) unless form.validate(original_input_params_for_form) | ||
|
||
result = | ||
transactions['change_set.create_work'] | ||
.with_step_args( | ||
'work_resource.add_to_parent' => { parent_id: params[:parent_id], user: current_user }, | ||
'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: params[hash_key_for_curation_concern][:file_set] }, | ||
'work_resource.add_file_sets' => { uploaded_files: uploaded_files, file_set_params: original_input_params_for_form[:file_set] }, | ||
'change_set.set_user_as_depositor' => { user: current_user }, | ||
'work_resource.change_depositor' => { user: ::User.find_by_user_key(form.on_behalf_of) }, | ||
'work_resource.save_acl' => { permissions_params: form.input_params["permissions"] } | ||
|
@@ -197,6 +200,7 @@ def create_valkyrie_work | |
@curation_concern = result.value_or { return after_create_error(transaction_err_msg(result)) } | ||
after_create_response | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
|
||
def update_valkyrie_work | ||
form = build_form | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div class="form-inline"> | ||
<%= visibility_badge(Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_LEASE) %> | ||
<%= f.input :visibility_during_lease, wrapper: :inline, collection: visibility_options(:loosen), include_blank: false %> | ||
<%= f.input :lease_expiration_date, wrapper: :inline, input_html: { value: f.object.lease_expiration_date || Date.tomorrow, class: 'datepicker' } %> | ||
<%= f.input :lease_expiration_date, wrapper: :inline, input_html: { value: f.object.lease_expiration_date&.to_date || Date.tomorrow, class: 'datepicker' } %> | ||
<%= f.input :visibility_after_lease, wrapper: :inline, collection: visibility_options(:restrict), include_blank: false %> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,15 +29,18 @@ def initialize(persister: Hyrax.persister, publisher: Hyrax.publisher) | |
# @return [Dry::Monads::Result] `Success(work)` if the change_set is | ||
# applied and the resource is saved; | ||
# `Failure([#to_s, change_set.resource])`, otherwise. | ||
# rubocop:disable Metrics/MethodLength | ||
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize | ||
def call(change_set, user: nil) | ||
begin | ||
if change_set.respond_to?(:lease) && change_set.lease | ||
valid_future_date?(change_set.lease, 'lease_expiration_date') | ||
add_lease_to_members(change_set) if change_set.model.member_ids&.present? | ||
end | ||
valid_future_date?(change_set.embargo, 'embargo_release_date') if change_set.respond_to?(:embargo) && change_set.embargo | ||
new_collections = changed_collection_membership(change_set) | ||
|
||
unsaved = change_set.sync | ||
if unsaved.embargo.present? | ||
unsaved.embargo.embargo_release_date = unsaved.embargo.embargo_release_date&.to_datetime | ||
unsaved.embargo = @persister.save(resource: unsaved.embargo) | ||
end | ||
save_leases_and_embargoes(unsaved) | ||
saved = @persister.save(resource: unsaved) | ||
rescue StandardError => err | ||
return Failure(["Failed save on #{change_set}\n\t#{err.message}", change_set.resource]) | ||
|
@@ -53,10 +56,54 @@ def call(change_set, user: nil) | |
publish_changes(resource: saved, user: user, new: unsaved.new_record, new_collections: new_collections) | ||
Success(saved) | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize | ||
|
||
private | ||
|
||
def valid_future_date?(item, attribute) | ||
raise StandardError, "#{item.model} must use a future date" if item.fields[attribute] < Time.zone.now | ||
end | ||
|
||
def save_leases_and_embargoes(unsaved) | ||
if unsaved.embargo.present? | ||
unsaved.embargo.embargo_release_date = unsaved.embargo.embargo_release_date&.to_datetime | ||
unsaved.embargo = @persister.save(resource: unsaved.embargo) | ||
end | ||
return if unsaved.lease.blank? | ||
|
||
unsaved.lease.lease_expiration_date = unsaved.lease.lease_expiration_date&.to_datetime | ||
unsaved.lease = @persister.save(resource: unsaved.lease) | ||
end | ||
|
||
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength | ||
def add_lease_to_members(change_set) | ||
# TODO: account for all members and levels, ref: #6131 | ||
# use recursion to ensure the change_set that applies to the member is getting saved and published/indexed | ||
change_set.model.member_ids&.each do |member| | ||
item = Hyrax.query_service.find_by(id: member.id) | ||
next unless item.is_a? Hyrax::FileSet | ||
|
||
lease_updates = change_set.lease.instance_variable_get(:@_changes).values.select { |v| v }.any? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. # example of what change_set.lease.instance_variable_get(:@_changes) could look like
@_changes={"visibility_after_lease"=>false, "visibility_during_lease"=>false, "lease_expiration_date"=>true} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really wish we weren't accessing an instance variable; that is breaking the encapsulation of the lease object. Could this method be extracted to the lease object? Or is there another method? I'm uncertain but this is a precarious bit of code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. below is what a #<Hyrax::Forms::Lease:0x00007f0cb073f0f0
@_changes={"visibility_after_lease"=>false, "visibility_during_lease"=>false, "lease_expiration_date"=>false},
@amv_errors=
#<Reform::Form::ActiveModel::Validations::Result::ResultErrors:0x00007f0cb07f2538
@amv_errors=#<ActiveModel::Errors:0x00007f0cafd82210 @base=#<Hyrax::Forms::Lease:0x00007f0cb073f0f0 ...>, @errors=[]>,
@dotted_errors={},
@form=#<Hyrax::Forms::Lease:0x00007f0cb073f0f0 ...>,
@result=#<Reform::Contract::Result:0x00007f0cafd81928 @failure=nil, @results=[]>,
@success=true>,
@fields={"visibility_after_lease"=>"restricted", "visibility_during_lease"=>"open", "lease_expiration_date"=>"2023-08-31", "lease_history"=>[]},
@mapper=
#<#<Class:0x00007f0cb1514e28>:0x00007f0caff1a168
@model=
#<Hyrax::Lease id=#<Valkyrie::ID:0x00007f0cb007da28 @id="285df028-9cf2-4372-a49a-2f8fe8889e7f"> internal_resource="Hyrax::Lease" created_at=Fri, 04 Aug 2023 15:23:13.900965000 UTC +00:00 updated_at=Fri, 04 Aug 2023 15:23:13.900965000 UTC +00:00 new_record=false visibility_after_lease="restricted" visibility_during_lease="open" lease_expiration_date=Thu, 31 Aug 2023 00:00:00 +0000 lease_history=[]>>,
@model=
#<Hyrax::Lease id=#<Valkyrie::ID:0x00007f0cb007da28 @id="285df028-9cf2-4372-a49a-2f8fe8889e7f"> internal_resource="Hyrax::Lease" created_at=Fri, 04 Aug 2023 15:23:13.900965000 UTC +00:00 updated_at=Fri, 04 Aug 2023 15:23:13.900965000 UTC +00:00 new_record=false visibility_after_lease="restricted" visibility_during_lease="open" lease_expiration_date=Thu, 31 Aug 2023 00:00:00 +0000 lease_history=[]>,
@result=#<Reform::Contract::Result:0x00007f0cafd81928 @failure=nil, @results=[]>> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this method into the LeaseManager. ref: b2a9f23 |
||
|
||
if item.lease && lease_updates | ||
item.lease.lease_expiration_date = change_set.lease.fields['lease_expiration_date'] | ||
item.lease.visibility_during_lease = change_set.lease.fields['visibility_during_lease'] | ||
item.lease.visibility_after_lease = change_set.lease.fields['visibility_after_lease'] | ||
item.lease = Hyrax.persister.save(resource: item.lease) | ||
else | ||
work_lease_manager = Hyrax::LeaseManager.new(resource: change_set.model) | ||
work_lease_manager.copy_lease_to(target: item) | ||
item = Hyrax.persister.save(resource: item) # rubocop:disable Lint/UselessAssignment | ||
end | ||
|
||
user ||= ::User.find_by_user_key(item.depositor) | ||
# the line below works in that it indexes the file set with the necessary lease properties | ||
# I do not know however if this is the best event_id to pass | ||
@publisher.publish('object.metadata.updated', object: item, user: user) | ||
end | ||
end | ||
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength | ||
|
||
## | ||
# @param [Hyrax::ChangeSet] change_set | ||
# | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the event
env.curation_concern
is an AF object, BUTHyrax.config.use_valkyrie?
is TRUE...we need the validation to run inWings::Valkyrie::Persister#save
because they were NOT run on the valkyrie object. otherwise, no errors are returned although they should be.in this case,
env.curation_concern.save
will equal false.