Skip to content

Commit

Permalink
add hyrax patch for student_works (see #1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed May 3, 2024
1 parent f39c88a commit 15eff61
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/forms/hyrax/student_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def model_attributes(_form_params)
def admin_set_id
Spot::StudentWorkAdminSetCreateService.find_or_create_student_work_admin_set_id
rescue Ldp::Gone
AdminSet.find_or_create_default_admin_set_id
'admin_set/default'
end
end

Expand Down
14 changes: 7 additions & 7 deletions app/services/spot/student_work_admin_set_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
module Spot
# @todo do we need this service anymore?
class StudentWorkAdminSetCreateService
ADMIN_SET_ID = 'admin_set/student_work'
DEFAULT_TITLE = ['Student Work'].freeze
WORKFLOW_NAME = 'mediated_student_work_deposit'
class_attribute :admin_set_id, default: 'admin_set/student_work'
class_attribute :default_title, default: ['Student Work'].freeze
class_attribute :workflow_name, default: 'mediated_student_work_deposit'

def self.find_or_create_student_work_admin_set_id
return ADMIN_SET_ID if AdminSet.exists?(ADMIN_SET_ID)
return admin_set_id if AdminSet.exists?(admin_set_id)

new.create_student_work_admin_set.id
end
Expand Down Expand Up @@ -37,7 +37,7 @@ def activate_workflow!(workflow:, permission_template:)
end

def create_admin_set
AdminSet.create(id: ADMIN_SET_ID, title: DEFAULT_TITLE)
AdminSet.create(id: admin_set_id, title: default_title)
end

def create_permission_template!(admin_set:)
Expand All @@ -53,14 +53,14 @@ def find_or_create_permission_template(source_id:)
end

def find_or_create_workflow(permission_template:)
workflow = Sipity::Workflow.find_by(name: WORKFLOW_NAME, permission_template: permission_template)
workflow = Sipity::Workflow.find_by(name: workflow_name, permission_template: permission_template)
return workflow unless workflow.nil?

Hyrax::Workflow::WorkflowImporter.generate_from_json_file(path: workflow_json_path, permission_template: permission_template).first
end

def workflow_json_name
"#{WORKFLOW_NAME}_workflow.json"
"#{workflow_name}_workflow.json"
end

def workflow_json_path
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/spot_overrides.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def files_for_import(file, cloud_files)
end

# Define this constant, intended to be similar to AdminSet::DEFAULT_ID
AdminSet::STUDENT_WORK_ID = Spot::StudentWorkAdminSetCreateService::ADMIN_SET_ID
AdminSet::STUDENT_WORK_ID = Spot::StudentWorkAdminSetCreateService.admin_set_id

# Our own Characterization Service subclass that uses :fits_servlet by default
CharacterizeJob.characterization_service = Spot::CharacterizationService
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/spot/student_work_admin_set.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace :spot do
begin
admin_set = AdminSet.find(Spot::StudentWorkAdminSetCreateService.find_or_create_student_work_admin_set_id)
rescue Ldp::Gone
puts "AdminSet(ID=#{Spot::StudentWorkAdminSetCreateService::ADMIN_SET_ID}) has been deleted."
puts "AdminSet(ID=#{Spot::StudentWorkAdminSetCreateService.admin_set_id}) has been deleted."
next
end

Expand Down
4 changes: 2 additions & 2 deletions spec/forms/hyrax/student_work_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@
before do
allow(Spot::StudentWorkAdminSetCreateService)
.to receive(:find_or_create_student_work_admin_set_id)
.and_return(Spot::StudentWorkAdminSetCreateService::ADMIN_SET_ID)
.and_return(Spot::StudentWorkAdminSetCreateService.admin_set_id)
end

it 'uses the StudentWork AdminSet id' do
expect(attributes[:admin_set_id]).to eq Spot::StudentWorkAdminSetCreateService::ADMIN_SET_ID
expect(attributes[:admin_set_id]).to eq Spot::StudentWorkAdminSetCreateService.admin_set_id
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

context 'when the admin_set exists' do
before do
allow(AdminSet).to receive(:exists?).with(described_class::ADMIN_SET_ID).and_return(true)
allow(AdminSet).to receive(:exists?).with(described_class.admin_set_id).and_return(true)
end

it { is_expected.to eq described_class::ADMIN_SET_ID }
it { is_expected.to eq described_class.admin_set_id }
end

context 'when the admin_set does not exist' do
Expand All @@ -27,7 +27,7 @@
# We're only loading the 'mediated_student_work_deposit' workflow,
# but we need to make sure it's activated.
expect(admin_set.active_workflow).to be_persisted
expect(admin_set.active_workflow.name).to eq described_class::WORKFLOW_NAME
expect(admin_set.active_workflow.name).to eq described_class.workflow_name

expect(admin_set.read_groups).not_to include('public')
expect(admin_set.edit_groups).to eq ['admin']
Expand All @@ -38,7 +38,7 @@
before do
allow(File)
.to receive(:exist?)
.with(Rails.root.join('config', 'workflows', "#{described_class::WORKFLOW_NAME}_workflow.json"))
.with(Rails.root.join('config', 'workflows', "#{described_class.workflow_name}_workflow.json"))
.and_return(false)
end

Expand Down

0 comments on commit 15eff61

Please sign in to comment.