Skip to content

Commit

Permalink
remove deprecated methods from AdminSet
Browse files Browse the repository at this point in the history
  • Loading branch information
tamsin johnson authored and tamsin johnson committed Aug 24, 2023
1 parent eeb3c3e commit 863c4bc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 116 deletions.
32 changes: 1 addition & 31 deletions app/models/admin_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,6 @@ class AdminSet < ActiveFedora::Base
before_destroy :check_if_not_default_set, :check_if_empty
after_destroy :destroy_permission_template

def self.default_set?(id)
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
"Instead, use 'Hyrax::AdminSetCreateService.default_admin_set?(id:)'.")
Hyrax::AdminSetCreateService.default_admin_set?(id: id)
end

def default_set?
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
"Instead, use 'Hyrax::AdminSetCreateService.default_admin_set?(id:)'.")
self.class.default_set?(id)
end

# Creates the default AdminSet and an associated PermissionTemplate with workflow
def self.find_or_create_default_admin_set_id
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
"Instead, use 'Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id'.")
Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id.to_s
end

def collection_type_gid
# allow AdminSet to behave more like a regular Collection
Hyrax::CollectionType.find_or_create_admin_set_type.to_global_id
Expand All @@ -86,17 +67,6 @@ def active_workflow
Sipity::Workflow.find_active_workflow_for(admin_set_id: id)
end

##
# @deprecated use PermissionTemplate#reset_access_controls_for instead
#
# Calculate and update who should have edit access based on who
# has "manage" access in the PermissionTemplateAccess
def reset_access_controls!
Deprecation.warn("reset_access_controls! is deprecated; use PermissionTemplate#reset_access_controls_for instead.")

permission_template.reset_access_controls_for(collection: self)
end

# @api public
#
# return an id for the AdminSet.
Expand All @@ -120,7 +90,7 @@ def check_if_empty
end

def check_if_not_default_set
return true unless default_set?
return true unless Hyrax::AdminSetCreateService.default_admin_set?(id: id)
errors[:base] << I18n.t('hyrax.admin.admin_sets.delete.error_default_set')
throw :abort
end
Expand Down
85 changes: 0 additions & 85 deletions spec/models/admin_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,55 +112,6 @@
end
end

describe ".default_set?", :clean_repo do
before { FactoryBot.valkyrie_create(:default_hyrax_admin_set) }
context "with default AdminSet ID" do
it "returns true" do
expect(described_class.default_set?(described_class::DEFAULT_ID)).to be true
end
end

context "with a non-default ID" do
it "returns false" do
expect(described_class.default_set?('different-id')).to be false
end
end
end

describe "#default_set?", :clean_repo do
let(:default_admin_set) do
administrative_set = FactoryBot.valkyrie_create(:default_hyrax_admin_set)
Wings::ActiveFedoraConverter.new(resource: administrative_set).convert
end
context "with default AdminSet ID" do
subject { default_admin_set.default_set? }

it { is_expected.to be_truthy }
end

context "with a non-default ID" do
subject { described_class.new(id: 'why-would-you-name-the-default-chupacabra?').default_set? }

it { is_expected.to be_falsey }
end
end

describe ".find_or_create_default_admin_set_id" do
subject { described_class.find_or_create_default_admin_set_id }

let(:default_admin_set) { build(:default_hyrax_admin_set) }

before do
allow(Hyrax::AdminSetCreateService).to receive(:find_or_create_default_admin_set)
.and_return(default_admin_set)
end

it 'gets the default admin set from the create service and returns the DEFAULT_ID' do
expect(Hyrax::AdminSetCreateService).to receive(:find_or_create_default_admin_set)
expect(subject).to eq(described_class::DEFAULT_ID)
end
end

describe "#destroy" do
context "with member works" do
before do
Expand Down Expand Up @@ -227,40 +178,4 @@
end
end
end

describe '#reset_access_controls!' do
let!(:user) { build(:user) }
let!(:admin_set) { create(:admin_set, creator: [user.user_key], edit_users: [user.user_key], edit_groups: [::Ability.admin_group_name], read_users: [], read_groups: ['public']) }
let!(:permission_template) { build(:permission_template) }

before do
allow(admin_set).to receive(:permission_template).and_return(permission_template)
allow(permission_template).to receive(:agent_ids_for).with(access: 'manage', agent_type: 'user').and_return(['[email protected]', '[email protected]', user.user_key])
allow(permission_template).to receive(:agent_ids_for).with(access: 'manage', agent_type: 'group').and_return(['managers', ::Ability.admin_group_name])
allow(permission_template).to receive(:agent_ids_for).with(access: 'deposit', agent_type: 'user').and_return(['[email protected]', '[email protected]'])
allow(permission_template).to receive(:agent_ids_for).with(access: 'deposit', agent_type: 'group').and_return(['depositors', 'registered'])
allow(permission_template).to receive(:agent_ids_for).with(access: 'view', agent_type: 'user').and_return(['[email protected]', '[email protected]'])
allow(permission_template).to receive(:agent_ids_for).with(access: 'view', agent_type: 'group').and_return(['viewers', 'public'])
end

it 'resets user edit access' do
admin_set.reset_access_controls!
expect(admin_set.edit_users).to match_array([user.user_key, '[email protected]', '[email protected]'])
end

it 'resets group edit access' do
admin_set.reset_access_controls!
expect(admin_set.edit_groups).to match_array(['managers', ::Ability.admin_group_name])
end

it 'resets user read access' do
admin_set.reset_access_controls!
expect(admin_set.read_users).to match_array(['[email protected]', '[email protected]', '[email protected]', '[email protected]'])
end

it 'resets group read access' do
admin_set.reset_access_controls!
expect(admin_set.read_groups).to match_array(['depositors', 'viewers'])
end
end
end

0 comments on commit 863c4bc

Please sign in to comment.