Skip to content

Commit

Permalink
Merge 870cfca into e7764c1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored Dec 13, 2018
2 parents e7764c1 + 870cfca commit 2f299fb
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 62 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ notifications:
email: false

rvm:
- 2.3.1
- 2.3.8

matrix:
include:
- rvm: 2.5.3
env: "RAILS_VERSION=5.2.2"
- rvm: 2.2.5
env: "RAILS_VERSION=4.1.13"
- rvm: 2.1.5
Expand Down
25 changes: 15 additions & 10 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@
#
# Filters added to this controller apply to all controllers in the hosting application
# as this module is mixed-in to the application controller in the hosting app on installation.
module Blacklight::Controller
module Blacklight::Controller

extend ActiveSupport::Concern
extend Deprecation

self.deprecation_horizon = 'blacklight 6.0'

included do
include Blacklight::SearchFields
helper Blacklight::SearchFields

include ActiveSupport::Callbacks

# now in application.rb file under config.filter_parameters
# filter_parameter_logging :password, :password_confirmation
# filter_parameter_logging :password, :password_confirmation
helper_method :current_user_session, :current_user, :current_or_guest_user
after_filter :discard_flash_if_xhr

if Rails.version < '5'
after_filter :discard_flash_if_xhr
else
after_action :discard_flash_if_xhr
end

# handle basic authorization exception with #access_denied
rescue_from Blacklight::Exceptions::AccessDenied, :with => :access_denied

helper_method :request_is_for_user_resource?

# extra head content
helper_method :has_user_authentication_provider?
helper_method :blacklight_config
Expand Down Expand Up @@ -73,7 +78,7 @@ def search_facet_url options = {}
def searches_from_history
session[:history].blank? ? Search.none : Search.where(:id => session[:history]).order("updated_at desc")
end

#
# Controller and view helper for determining if the current url is a request for a user resource
#
Expand Down Expand Up @@ -112,7 +117,7 @@ def discard_flash_if_xhr
#
def has_user_authentication_provider?
respond_to? :current_user
end
end

def require_user_authentication_provider
raise ActionController::RoutingError.new('Not Found') unless has_user_authentication_provider?
Expand Down Expand Up @@ -140,7 +145,7 @@ def transfer_guest_user_actions_to_current_user
end

##
# To handle failed authorization attempts, redirect the user to the
# To handle failed authorization attempts, redirect the user to the
# login form and persist the current request uri as a parameter
def access_denied
# send the user home if the access was previously denied by the same
Expand All @@ -152,5 +157,5 @@ def access_denied

redirect_to new_user_session_url(:referer => request.fullpath)
end

end
20 changes: 12 additions & 8 deletions app/controllers/concerns/blacklight/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@ module Blacklight::SearchContext

# The following code is executed when someone includes blacklight::catalog::search_session in their
# own controller.
included do
included do
helper_method :current_search_session, :search_session

end

module ClassMethods
# Save the submitted search parameters in the search session
def record_search_parameters opts = { only: :index}
before_filter :current_search_session, opts
if Rails.version < '5'
before_filter :current_search_session, opts
else
before_action :current_search_session, opts
end
end
end

protected

# sets up the session[:search] hash if it doesn't already exist
def search_session
session[:search] ||= {}
end
# The current search session

# The current search session
def current_search_session

@current_search_session ||= if start_new_search_session?
Expand All @@ -31,7 +35,7 @@ def current_search_session
find_or_initialize_search_session_from_params JSON.load(params[:search_context])
elsif params[:search_id].present?
begin
# TODO : check the search id signature.
# TODO : check the search id signature.
searches_from_history.find(params[:search_id])
rescue ActiveRecord::RecordNotFound
nil
Expand Down Expand Up @@ -79,11 +83,11 @@ def add_to_search_history search
if session[:history].length > blacklight_config.search_history_window

session[:history] = session[:history].slice(0, blacklight_config.search_history_window )

end
end

# A list of query parameters that should not be persisted for a search
# A list of query parameters that should not be persisted for a search
def blacklisted_search_session_params
[:commit, :counter, :total, :search_id, :page, :per_page]
end
Expand Down
21 changes: 13 additions & 8 deletions app/controllers/saved_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ class SavedSearchesController < ApplicationController
include Blacklight::Configurable

copy_blacklight_config_from(CatalogController)
before_filter :require_user_authentication_provider
before_filter :verify_user

if Rails.version < '5'
before_filter :require_user_authentication_provider
before_filter :verify_user
else
before_filter :require_user_authentication_provider
before_filter :verify_user
end

def index
@searches = current_user.searches
end
def save

def save
current_user.searches << searches_from_history.find(params[:id])
if current_user.save
flash[:notice] = I18n.t('blacklight.saved_searches.add.success')
Expand All @@ -33,14 +38,14 @@ def forget
end
redirect_to :back
end

# Only dereferences the user rather than removing the items in case they
# are in the session[:history]
def clear
def clear
if current_user.searches.update_all("user_id = NULL")
flash[:notice] = I18n.t('blacklight.saved_searches.clear.success')
else
flash[:error] = I18n.t('blacklight.saved_searches.clear.failure')
flash[:error] = I18n.t('blacklight.saved_searches.clear.failure')
end
redirect_to :action => "index"
end
Expand Down
2 changes: 1 addition & 1 deletion blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "rails", ">= 3.2.6", "< 5"
s.add_dependency "rails", ">= 3.2.6", "< 6"
s.add_dependency "nokogiri", "~>1.6" # XML Parser
s.add_dependency "kaminari", ">= 0.15" # the pagination (page 1,2,3, etc..) of our search results
s.add_dependency "rsolr", "~> 1.0", ">= 1.0.11" # Library for interacting with rSolr.
Expand Down
8 changes: 7 additions & 1 deletion db/migrate/20140202020201_create_searches.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# -*- encoding : utf-8 -*-
class CreateSearches < ActiveRecord::Migration
from = if Rails.version > '5'
ActiveRecord::Migration[5.0]
else
ActiveRecord::Migration
end

class CreateSearches < from
def self.up
create_table :searches do |t|
t.text :query_params
Expand Down
11 changes: 9 additions & 2 deletions db/migrate/20140202020202_create_bookmarks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# -*- encoding : utf-8 -*-
class CreateBookmarks < ActiveRecord::Migration

from = if Rails.version > '5'
ActiveRecord::Migration[5.0]
else
ActiveRecord::Migration
end

class CreateBookmarks < from
def self.up
create_table :bookmarks do |t|
t.integer :user_id, :null=>false
Expand All @@ -13,5 +20,5 @@ def self.up
def self.down
drop_table :bookmarks
end

end
11 changes: 9 additions & 2 deletions db/migrate/20140320000000_add_polymorphic_type_to_bookmarks.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# -*- encoding : utf-8 -*-
class AddPolymorphicTypeToBookmarks < ActiveRecord::Migration

from = if Rails.version > '5'
ActiveRecord::Migration[5.0]
else
ActiveRecord::Migration
end

class AddPolymorphicTypeToBookmarks < from
def change
add_column(:bookmarks, :document_type, :string)

add_index :bookmarks, :user_id
end
end
14 changes: 7 additions & 7 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class SolrRepository < Solr::Repository
def initialize blacklight_config
Deprecation.warn(self, 'Blacklight::SolrRepository is deprecated; use Blacklight::Solr::Repository instead')
super
end
end
end

class SolrResponse < Solr::Response
extend Deprecation
def initialize(data, request_params, options = {})
Deprecation.warn(self, 'Blacklight::SolrResponse is deprecated; use Blacklight::Solr::Response instead')
super
end
end
end

# Secret key used to share session information with
Expand Down Expand Up @@ -144,7 +144,7 @@ def self.solr_yml

return @solr_yml if @solr_yml
unless File.exists?(solr_file)
raise "You are missing a solr configuration file: #{solr_file}. Have you run \"rails generate blacklight:install\"?"
raise "You are missing a solr configuration file: #{solr_file}. Have you run \"rails generate blacklight:install\"?"
end

begin
Expand Down Expand Up @@ -176,17 +176,17 @@ def self.logger= logger
@logger = logger
end

#############
#############
# Methods for figuring out path to BL plugin, and then locate various files
# either in the app itself or defaults in the plugin -- whether you are running
# from the plugin itself or from an actual app using te plugin.
# In a seperate module so it can be used by both Blacklight class, and
# by rake tasks without loading the whole Rails environment.
# by rake tasks without loading the whole Rails environment.
#############

# returns the full path the the blacklight plugin installation
def self.root
@root ||= File.expand_path(File.dirname(File.dirname(__FILE__)))
end

end
2 changes: 1 addition & 1 deletion lib/blacklight/solr/request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Blacklight::Solr::InvalidParameter < ArgumentError; end

class Blacklight::Solr::Request < HashWithIndifferentAccess
class Blacklight::Solr::Request < ActiveSupport::HashWithIndifferentAccess

SINGULAR_KEYS = %w{facet fl q qt rows start spellcheck spellcheck.q sort per_page wt hl group defType}
ARRAY_KEYS = %w{facet.field facet.query facet.pivot fq hl.fl}
Expand Down
4 changes: 2 additions & 2 deletions lib/blacklight/solr/response.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Blacklight::Solr::Response < HashWithIndifferentAccess
class Blacklight::Solr::Response < ActiveSupport::HashWithIndifferentAccess
extend Deprecation

require 'blacklight/solr/response/pagination_methods'
Expand Down Expand Up @@ -89,7 +89,7 @@ def force_to_utf8(value)
when Array
value.each { |v| force_to_utf8(v) }
when String
value.force_encoding("utf-8") if value.respond_to?(:force_encoding)
value.force_encoding("utf-8") if value.respond_to?(:force_encoding)
end
value
end
Expand Down
10 changes: 8 additions & 2 deletions lib/blacklight/utils.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
require 'ostruct'

# Backport for Rails 4:
if Rails.version < '5'
ActiveSupport::HashWithIndifferentAccess = HashWithIndifferentAccess
end

module Blacklight

module Utils
Expand Down Expand Up @@ -48,7 +54,7 @@ def respond_to? method, *args
def to_h
@table
end

def select *args, &block
self.class.new to_h.select(*args, &block)
end
Expand Down Expand Up @@ -85,7 +91,7 @@ def deep_dup


##
# An OpenStruct refinement that converts any hash-keys into
# An OpenStruct refinement that converts any hash-keys into
# additional instances of NestedOpenStructWithHashAccess
class NestedOpenStructWithHashAccess < OpenStructWithHashAccess
attr_reader :nested_class
Expand Down
10 changes: 4 additions & 6 deletions lib/generators/blacklight/test_support_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@


# Need the requires here so we can call the generator from environment.rb
# as suggested above.
# as suggested above.
require 'rails/generators'
require 'rails/generators/base'
module Blacklight
class TestSupport < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
desc """
Generate blacklight testing configurations for blacklight's own tests, or for blacklight plugins to use for testing
desc """
Generate blacklight testing configurations for blacklight's own tests, or for blacklight plugins to use for testing
"""
def alternate_controller
copy_file "alternate_controller.rb", "app/controllers/alternate_controller.rb"
Expand All @@ -19,9 +19,7 @@ def alternate_controller
member do
get :facet
end
end")


end\n") # the trailing CR is important (in Rails 5) so that any other additional routes get added on the next line.
end

def configure_action_mailer
Expand Down
Loading

0 comments on commit 2f299fb

Please sign in to comment.