Skip to content

Commit

Permalink
Merge pull request #6707 from samvera/favor-configuration
Browse files Browse the repository at this point in the history
♻️ Favor source_type config check
  • Loading branch information
dlpierce authored Feb 20, 2024
2 parents 612a58f + e25c8dc commit 630dc62
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions app/services/hyrax/collections/permissions_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
module Hyrax
module Collections
# rubocop:disable Metrics/ClassLength
class PermissionsService
# @api private
#
Expand All @@ -20,17 +21,34 @@ def self.source_ids_for_user(access:, ability:, source_type: nil, exclude_groups
end
private_class_method :source_ids_for_user

# rubocop:disable Metrics/MethodLength
def self.filter_source(source_type:, ids:)
return [] if ids.empty?
model = case source_type
when 'admin_set'
Hyrax::AdministrativeSet
when 'collection'
Hyrax::PcdmCollection
end
models = case source_type
when 'admin_set'
Hyrax::ModelRegistry.admin_set_classes
when 'collection'
Hyrax::ModelRegistry.collection_classes
end

Hyrax.custom_queries.find_ids_by_model(model: model, ids: ids).to_a
# Antics to cope with all of the how the custom queries work.
if defined?(Wings::ModelRegistry)
models = models.map do |model|
Wings::ModelRegistry.reverse_lookup(model)
rescue NoMethodError
nil
end.compact
end

models.flat_map do |model|
if model
Hyrax.custom_queries.find_ids_by_model(model: model, ids: ids).to_a
else
[]
end
end.uniq
end
# rubocop:enable Metrics/MethodLength
private_class_method :filter_source

# @api private
Expand Down Expand Up @@ -249,5 +267,6 @@ def self.access_to_collection?(collection_id:, access:, ability:, exclude_groups
end
private_class_method :access_to_collection?
end
# rubocop:enable Metrics/ClassLength
end
end

0 comments on commit 630dc62

Please sign in to comment.