-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1289 from sul-dlss/984-manage-catkey-bulk-action
New manage catkey bulk action
- Loading branch information
Showing
16 changed files
with
285 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Job to update/add catkey to objects | ||
class ManageCatkeyJob < GenericJob | ||
queue_as :manage_catkey | ||
|
||
attr_reader :catkeys, :groups | ||
## | ||
# A job that allows a user to specify a list of pids and a list of catkeys to be associated with these pids | ||
# @param [Integer] bulk_action_id GlobalID for a BulkAction object | ||
# @param [Hash] params additional parameters that an Argo job may need | ||
# @option params [Array] :pids required list of pids | ||
# @option params [Hash] :manage_catkeys (required) list of catkeys to be associated 1:1 with pids in order | ||
# @option params [Array] :groups the groups the user belonged to when the started the job. Required for permissions check | ||
def perform(bulk_action_id, params) | ||
@catkeys = params[:manage_catkeys]['catkeys'].split.map(&:strip) | ||
@groups = params[:groups] | ||
@pids = params[:pids] | ||
@current_user = params[:user] | ||
with_bulk_action_log do |log| | ||
log.puts("#{Time.current} Starting ManageCatkeyJob for BulkAction #{bulk_action_id}") | ||
update_druid_count | ||
|
||
pids.each_with_index { |current_druid, i| update_catkey(current_druid, @catkeys[i], log) } | ||
log.puts("#{Time.current} Finished ManageCatkeyJob for BulkAction #{bulk_action_id}") | ||
end | ||
end | ||
|
||
private | ||
|
||
def update_catkey(current_druid, new_catkey, log) | ||
log.puts("#{Time.current} Beginning ManageCatkeyJob for #{current_druid}") | ||
current_obj = Dor.find(current_druid) | ||
unless can_manage?(current_druid) | ||
log.puts("#{Time.current} Not authorized for #{current_druid}") | ||
return | ||
end | ||
log.puts("#{Time.current} Adding catkey of #{new_catkey}") | ||
begin | ||
open_new_version(current_obj, "Catkey updated to #{new_catkey}") unless current_obj.allows_modification? | ||
current_obj.catkey = new_catkey | ||
current_obj.save | ||
close_version(current_obj) if current_obj.new_version_open? | ||
bulk_action.increment(:druid_count_success).save | ||
log.puts("#{Time.current} Catkey added/updated/removed successfully") | ||
rescue StandardError => e | ||
log.puts("#{Time.current} Catkey failed #{e.class} #{e.message}") | ||
bulk_action.increment(:druid_count_fail).save | ||
return | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class='form-group'> | ||
<label>List of catkeys*</label> | ||
<textarea id='bulk_action_manage_catkeys_catkeys' name='bulk_action[manage_catkeys][catkeys]' class='form-control' rows='10'> | ||
</textarea> | ||
<span class='help-block'>* must be same length as list of druids and in same order to update ... add a blank line to delete existing catkey</span> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.