Skip to content

Commit

Permalink
Merge c8256cf into e7764c1
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 13, 2018
2 parents e7764c1 + c8256cf commit a330bc1
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 101 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
6 changes: 5 additions & 1 deletion app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ module Blacklight::Bookmarks

copy_blacklight_config_from(CatalogController)

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

blacklight_config.add_results_collection_tool(:clear_bookmarks_widget)

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_action :require_user_authentication_provider
before_action :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
37 changes: 20 additions & 17 deletions app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def link_to_next_document(next_document)

##
# Current search context parameters
def search_session_params counter
def search_session_params counter
{ :'data-counter' => counter, :'data-search_id' => current_search_session.try(:id) }
end
deprecation_deprecate search_session_params: :session_tracking_params
Expand All @@ -83,11 +83,11 @@ def session_tracking_params document, counter
if document.nil?
return {}
end

{ :data => {:'context-href' => session_tracking_path(document, per_page: params.fetch(:per_page, search_session['per_page']), counter: counter, search_id: current_search_session.try(:id))}}
end
protected :session_tracking_params

##
# Get the URL for tracking search sessions across pages using polymorphic routing
def session_tracking_path document, params = {}
Expand Down Expand Up @@ -124,7 +124,7 @@ def start_over_path query_params = params
def link_back_to_catalog(opts={:label=>nil})
scope = opts.delete(:route_set) || self
query_params = current_search_session.try(:query_params) || {}

if search_session['counter']
per_page = (search_session['per_page'] || default_per_page).to_i
counter = search_session['counter'].to_i
Expand Down Expand Up @@ -156,11 +156,11 @@ def link_to_previous_search(params)

# @overload params_for_search(source_params, params_to_merge)
# Merge the source params with the params_to_merge hash
# @param [Hash] Hash
# @param [Hash] Hash
# @param [Hash] Hash to merge into above
# @overload params_for_search(params_to_merge)
# Merge the current search parameters with the
# parameters provided.
# Merge the current search parameters with the
# parameters provided.
# @param [Hash] Hash to merge into the parameters
# @overload params_for_search
# Returns the current search parameters after being sanitized by #sanitize_search_params
Expand Down Expand Up @@ -207,7 +207,10 @@ def sanitize_search_params source_params
# Reset any search parameters that store search context
# and need to be reset when e.g. constraints change
def reset_search_params source_params
sanitize_search_params(source_params).except(:page, :counter).with_indifferent_access
maybe_hash = sanitize_search_params(source_params).except(:page, :counter)
# maybe_hash is a hash in Rails 4 but a ActionController::Parameters in Rails 5
new_params = maybe_hash.respond_to?(:with_indifferent_access) ? maybe_hash : maybe_hash.to_h
maybe_hash.with_indifferent_access
end

# adds the value and/or field to params[:f]
Expand All @@ -233,7 +236,7 @@ def add_facet_params(field, item, source_params = params)
if facet_config.single and not p[:f][url_field].empty?
p[:f][url_field] = []
end

p[:f][url_field].push(value)

if item and item.respond_to?(:fq) and item.fq
Expand All @@ -249,14 +252,14 @@ def add_facet_params(field, item, source_params = params)
# on a facet value. Add on the facet params to existing
# search constraints. Remove any paginator-specific request
# params, or other request params that should be removed
# for a 'fresh' display.
# for a 'fresh' display.
# Change the action to 'index' to send them back to
# catalog/index with their new facet choice.
# catalog/index with their new facet choice.
def add_facet_params_and_redirect(field, item)
new_params = add_facet_params(field, item)

# Delete any request params from facet-specific action, needed
# to redir to index action properly.
# to redir to index action properly.
request_keys = blacklight_config.facet_paginator_class.request_keys
new_params.except! *request_keys.values

Expand Down Expand Up @@ -289,15 +292,15 @@ def remove_facet_params(field, item, source_params=params)
p.delete(:f) if p[:f].empty?
p
end
# A URL to refworks export, with an embedded callback URL to this app.
# the callback URL is to bookmarks#export, which delivers a list of

# A URL to refworks export, with an embedded callback URL to this app.
# the callback URL is to bookmarks#export, which delivers a list of
# user's bookmarks in 'refworks marc txt' format -- we tell refworks
# to expect that format.
# to expect that format.
def bookmarks_export_url(format, params = {})
bookmarks_url(params.merge(format: format, encrypted_user_id: encrypt_user_id(current_or_guest_user.id) ))
end

# This method should move to BlacklightMarc in Blacklight 6.x
def refworks_export_url params = {}
if params.is_a? ::SolrDocument or (params.nil? and instance_variable_defined? :@document)
Expand Down

0 comments on commit a330bc1

Please sign in to comment.