-
Notifications
You must be signed in to change notification settings - Fork 0
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 #961 from scientist-softserv/fixing_reshare_some_m…
…ore_part_deux 🎁 Add loading splash screen and speed up redirect
- Loading branch information
Showing
17 changed files
with
399 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# This class is responsible for assigning a conceptually "private" group to the | ||
# members of of the {Cdl} work. | ||
# | ||
# The reason for creating this group is when a person gains access to the CDL | ||
# (via the lending application) it is more performant to add the person to a | ||
# group than it is to add the person directly to each of the underlying files. | ||
class CreateGroupAndAddMembersJob < ApplicationJob | ||
RETRY_MAX = 5 | ||
|
||
queue_as :default | ||
|
||
def perform(cdl_id, retries = 0) | ||
work = Cdl.where(id: cdl_id).first | ||
return if work.nil? | ||
|
||
page_count = work.file_sets.first.page_count.first.to_i | ||
child_model = work.iiif_print_config.pdf_split_child_model | ||
child_works_count = work.members.select { |member| member.is_a?(child_model) }.count | ||
|
||
if page_count == child_works_count | ||
group = Hyrax::Group.find_or_create_by!(name: work.id) | ||
work.read_groups = [group.name] | ||
|
||
work.members.each do |member| | ||
assign_read_groups(member, group.name) | ||
end | ||
|
||
work.save | ||
group.save | ||
else | ||
return if retries > RETRY_MAX | ||
|
||
retries += 1 | ||
CreateGroupAndAddMembersJob.set(wait: 10.minutes).perform_later(cdl_id, retries) | ||
end | ||
end | ||
|
||
private | ||
|
||
def assign_read_groups(member, group_name) | ||
member.read_groups = [group_name] | ||
member.save | ||
member.members.each do |sub_member| | ||
assign_read_groups(sub_member, group_name) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class DestroyCdlGroupJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(id) | ||
Hyrax::Group.find_by(name: id)&.destroy | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class DestroySplitPagesJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(id) | ||
work = ActiveFedora::Base.where(id: id).first | ||
return unless work&.is_child | ||
|
||
work.members.each(&:destroy) | ||
work.destroy | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
# OVERRIDE IIIF Print v1.0.0 to call CreateGroupAndAddMembersJob | ||
|
||
module IiifPrint | ||
module Jobs | ||
module CreateRelationshipsJobDecorator | ||
def perform(parent_id:, parent_model:, child_model:, retries: 0, **) | ||
@parent_id = parent_id | ||
@parent_model = parent_model | ||
@child_model = child_model | ||
@retries = retries + 1 | ||
|
||
@number_of_successes = 0 | ||
@number_of_failures = 0 | ||
@parent_record_members_added = false | ||
@errors = [] | ||
|
||
# Because we need our children in the correct order, we can't create any | ||
# relationships until all child works have been created. | ||
if completed_child_data | ||
# add the members | ||
add_children_to_parent | ||
if @number_of_failures.zero? && @number_of_successes == @pending_children.count | ||
# remove pending relationships upon valid completion | ||
@pending_children.each(&:destroy) | ||
elsif @number_of_failures.zero? && @number_of_successes > @pending_children.count | ||
# remove pending relationships but raise error that too many relationships formed | ||
@pending_children.each(&:destroy) | ||
raise "CreateRelationshipsJob for parent id: #{@parent_id} " \ | ||
"added #{@number_of_successes} children, " \ | ||
"expected #{@pending_children} children." | ||
else | ||
# report failures & keep pending relationships | ||
raise "CreateRelationshipsJob failed for parent id: #{@parent_id} " \ | ||
"had #{@number_of_successes} successes & #{@number_of_failures} failures, " \ | ||
"with errors: #{@errors}. Wanted #{@pending_children} children." | ||
end | ||
|
||
# OVERRIDE begin | ||
CreateGroupAndAddMembersJob.set(wait: 2.minutes).perform_later(parent_id) | ||
# OVERRIDE end | ||
else | ||
# if we aren't ready yet, reschedule the job and end this one normally | ||
reschedule_job | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
IiifPrint::Jobs::CreateRelationshipsJob.prepend(IiifPrint::Jobs::CreateRelationshipsJobDecorator) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal:true | ||
|
||
require 'sushi/error' | ||
|
||
module Sushi | ||
mattr_accessor :info | ||
|
||
|
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# CREATE_GROUP_FOR=tenant rake hyku:cdl:create_group_and_add_members[id1.id2.id3] | ||
# NOTE: we are using period separations because comma separates don't seem to work | ||
# without the CREATE_GROUP_FOR env var, it will default to 'blc' tenant | ||
namespace :hyku do | ||
namespace :cdl do | ||
desc 'Enqueue CreateGroupAndAddMembersJob for each provided ID' | ||
task :create_group_and_add_members, [:ids] => :environment do |_, args| | ||
tenant = ENV['CREATE_GROUPS_FOR'] || 'blc' | ||
switch!(tenant) | ||
|
||
ids = args[:ids].split('.').map(&:strip) | ||
ids.each do |id| | ||
CreateGroupAndAddMembersJob.perform_later(id) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.