Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions app/models/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def fill_in_solr_fields_that_need_sections(solr_doc)

def fill_in_solr_fields_needing_leases(solr_doc)
solr_doc['read_access_virtual_group_ssim'] = virtual_read_groups + leases('external').map(&:inherited_read_groups).flatten
solr_doc['read_access_ip_group_ssim'] = collect_ips_for_index(ip_read_groups + leases('ip').map(&:inherited_read_groups).flatten)
solr_doc['read_access_ip_group_ssim'] = (ip_read_groups + leases('ip').map(&:inherited_read_groups).flatten).uniq
solr_doc[Hydra.config.permissions.read.group] ||= []
solr_doc[Hydra.config.permissions.read.group] += solr_doc['read_access_ip_group_ssim']
end
Expand Down Expand Up @@ -495,14 +495,6 @@ def calculate_duration
section_solr_docs.collect { |h| h['duration_ssi'].to_i }.compact.sum
end

def collect_ips_for_index ip_strings
ips = ip_strings.collect do |ip|
addr = IPAddr.new(ip) rescue next
addr.to_range.map(&:to_s)
end
ips.flatten.compact.uniq || []
end

def sections_with_files(tag: '*')
# TODO: Optimize this into a single solr query?
section_ids.select { |m| SpeedyAF::Proxy::MasterFile.find(m).supplemental_files(tag: tag).present? }
Expand Down
16 changes: 16 additions & 0 deletions config/initializers/policy_aware_modification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,19 @@ def self.count(query, args = {})
result['response']['numFound'].to_i
end
end

# Override to expand IP address ranges
Blacklight::AccessControls::Ability.class_eval do
def read_groups(id)
doc = permissions_doc(id)
return [] if doc.nil?
groups = Array(doc[self.class.read_group_field]).uniq
groups = groups.map do |g|
ip = IPAddr.new(g) rescue nil
ip.present? ? ip.to_range.map(&:to_s) : g
end.flatten.compact.uniq
rg = download_groups(id) | groups
Rails.logger.debug("[CANCAN] read_groups: #{rg.inspect}")
rg
end
end