Skip to content

Commit

Permalink
Merge pull request #3154 from projecthydra/use_admin_set_default_id_f…
Browse files Browse the repository at this point in the history
…rom_behavior

Use AdminSet::DEFAULT_ID from ASBehavior across app
  • Loading branch information
mjgiarlo authored Mar 17, 2017
2 parents 6efa189 + 431cbe2 commit 39aa714
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions app/services/sufia/admin_set_create_service.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module Sufia
# Creates AdminSets
class AdminSetCreateService
DEFAULT_ID = 'admin_sets/default'.freeze
DEFAULT_WORKFLOW_NAME = 'default'.freeze

def self.create_default!
return if AdminSet.exists?(DEFAULT_ID)
admin_set = AdminSet.new(id: DEFAULT_ID, title: ['Default Admin Set'])
return if AdminSet.exists?(AdminSet::DEFAULT_ID)
admin_set = AdminSet.new(id: AdminSet::DEFAULT_ID, title: ['Default Admin Set'])
begin
new(admin_set, nil, DEFAULT_WORKFLOW_NAME).create
rescue ActiveFedora::IllegalOperation
# It is possible that another thread created the AdminSet just before this method
# was called, so ActiveFedora will raise IllegalOperation. In this case we can safely
# ignore the error.
Rails.logger.error("AdminSet ID=#{DEFAULT_ID} may or may not have been created due to threading issues.")
Rails.logger.error("AdminSet ID=#{AdminSet::DEFAULT_ID} may or may not have been created due to threading issues.")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/migrate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace :sufia do
namespace :migrate do
task move_all_works_to_admin_set: :environment do
require 'sufia/move_all_works_to_admin_set'
MoveAllWorksToAdminSet.run(AdminSet.find(Sufia::DefaultAdminSetActor::DEFAULT_ID))
MoveAllWorksToAdminSet.run(AdminSet.find(AdminSet::DEFAULT_ID))
end

desc "Migrate workflow data from 7.3.0.rc1"
Expand Down
2 changes: 1 addition & 1 deletion spec/services/sufia/admin_set_create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

describe '.create_default!' do
let(:default_admin_set_id) { 'admin_sets/default' }
let(:default_admin_set_id) { 'admin_set/default' }
let(:permission_template) { Sufia::PermissionTemplate.find_by!(admin_set_id: default_admin_set_id) }
# It is important to test the side-effects as a default admin set is a fundamental assumption for Sufia >= 7.3
it 'creates AdminSet, PermissionTemplate' do
Expand Down

0 comments on commit 39aa714

Please sign in to comment.