Sha256: b26e415a0269c2dd9166198df02a365de0f14b3a285f67f889c441576b544a66

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

module QuickSearch::OnCampus
  extend ActiveSupport::Concern

  private

  # Search for "Nucleation and growth mechanism of ferroelectric domain wall motion"
  # To test this. Result should not show up in Summon results off campus.

  ### WHY THIS IS HERE ###
  # There is a subset of Summon results that cannot be shown unless a person is
  # on campus or authenticated. So that we can show all results to people
  # searching QuickSearch from on campus we're checking IP addresses. If the IP is a
  # known campus IP we set the s.role=authenticated parameter in the Summon API request.

  def ip
    request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip
  end

  def on_campus?(ip)
    ip = remote_ip(ip)
    ip_range_check(ip)
  end

  # To spoof ON and OFF campus for development
  def remote_ip(ip)
    if ip == '127.0.0.1'
      '204.84.244.1' #On Campus
      #'127.0.0.1'  #Off Campus
    else
      ip
    end
  end

  def ip_range_check(ip)
    QuickSearch::Engine::APP_CONFIG['on_campus'].each do |on_campus_ip_regex|
      if on_campus_ip_regex === ip
        return true
      end
    end

    return false
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
quick_search-core-0.2.0 app/controllers/concerns/quick_search/on_campus.rb
quick_search-core-0.1.1 app/controllers/concerns/quick_search/on_campus.rb
quick_search-core-0.1.0 app/controllers/concerns/quick_search/on_campus.rb
quick_search-core-0.0.1 app/controllers/concerns/quick_search/on_campus.rb
quick_search-core-0.0.1.test app/controllers/concerns/quick_search/on_campus.rb