Skip to content

Commit

Permalink
Merge c269ef4 into 60c77eb
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Dec 15, 2018
2 parents 60c77eb + c269ef4 commit 6ea58a6
Show file tree
Hide file tree
Showing 29 changed files with 346 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Metrics/MethodLength:
# Offense count: 9
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 208
Max: 211
Exclude:
- 'lib/blacklight/solr/search_builder_behavior.rb'

Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist: trusty
addons:
chrome: stable
language: ruby
sudo: false

Expand Down Expand Up @@ -26,6 +29,7 @@ matrix:
before_install:
- gem update --system
- gem install bundler
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

before_script:
- if [[ "${RAILS_VERSION}" =~ ^4.2.* ]]; then perl -pi -e "s/ActiveRecord::Migration\[[\d\.]+\]/ActiveRecord::Migration/" db/migrate/*; fi
Expand All @@ -40,5 +44,6 @@ notifications:

global_env:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- ENGINE_CART_RAILS_OPTIONS='--skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-action-cable --skip-coffee --skip-test'

jdk: oraclejdk8
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ else
gem 'sass-rails', '>= 5.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'json', '~> 1.8'
gem 'capybara', '~> 2.0'
when /^4.[01]/
gem 'sass-rails', '< 5.0'
end
Expand Down
20 changes: 17 additions & 3 deletions app/controllers/concerns/blacklight/bookmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update
# is simpler.
def create
@bookmarks = if params[:bookmarks]
params[:bookmarks]
permit_bookmarks[:bookmarks]
else
[{ document_id: params[:id], document_type: blacklight_config.document_model.to_s }]
end
Expand Down Expand Up @@ -103,9 +103,19 @@ def create
# Beware, :id is the Solr document_id, not the actual Bookmark id.
# idempotent, as DELETE is supposed to be.
def destroy
bookmark = current_or_guest_user.bookmarks.find_by(document_id: params[:id], document_type: blacklight_config.document_model.to_s)
@bookmarks =
if params[:bookmarks]
permit_bookmarks[:bookmarks]
else
[{ document_id: params[:id], document_type: blacklight_config.document_model.to_s }]
end

if bookmark && bookmark.delete && bookmark.destroyed?
success = @bookmarks.all? do |bookmark|
bookmark = current_or_guest_user.bookmarks.find_by(bookmark)
bookmark && bookmark.delete && bookmark.destroyed?
end

if success
if request.xhr?
render(json: { bookmarks: { count: current_or_guest_user.bookmarks.count }})
elsif respond_to? :redirect_back
Expand Down Expand Up @@ -144,4 +154,8 @@ def verify_user
def start_new_search_session?
action_name == "index"
end

def permit_bookmarks
params.permit(bookmarks: [:document_id, :document_type])
end
end
6 changes: 4 additions & 2 deletions app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ module Blacklight::Catalog
# The following code is executed when someone includes blacklight::catalog in their
# own controller.
included do
helper_method :sms_mappings, :has_search_parameters?
if respond_to? :helper_method
helper_method :sms_mappings, :has_search_parameters?
end

helper Blacklight::Facet
helper Blacklight::Facet if respond_to? :helper

# When an action raises Blacklight::Exceptions::RecordNotFound, handle
# the exception appropriately.
Expand Down
17 changes: 10 additions & 7 deletions app/controllers/concerns/blacklight/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ module Blacklight::Controller

included do
include Blacklight::SearchFields
helper Blacklight::SearchFields
helper Blacklight::SearchFields if respond_to? :helper

include ActiveSupport::Callbacks

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

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

# extra head content
helper_method :has_user_authentication_provider?
helper_method :blacklight_config, :blacklight_configuration_context
helper_method :search_action_url, :search_action_path, :search_facet_url, :search_facet_path
helper_method :search_state
if respond_to? :helper_method
helper_method :current_user_session, :current_user, :current_or_guest_user

# extra head content
helper_method :has_user_authentication_provider?
helper_method :blacklight_config, :blacklight_configuration_context
helper_method :search_action_url, :search_action_path, :search_facet_path
helper_method :search_state
end

# Specify which class to use for the search state. You can subclass SearchState if you
# want to override any of the methods (e.g. SearchState#url_for_document)
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/concerns/blacklight/search_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
module Blacklight::SearchContext
extend ActiveSupport::Concern

# The following code is executed when someone includes blacklight::catalog::search_session in their
# The following code is executed when someone includes Blacklight::Catalog::SearchSession in their
# own controller.
included do
helper_method :current_search_session, :search_session
included do
if respond_to? :helper_method
helper_method :current_search_session, :search_session
end
end

module ClassMethods
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/concerns/blacklight/token_based_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module Blacklight::TokenBasedUser
extend ActiveSupport::Concern

included do
helper_method :encrypt_user_id
if respond_to? :helper_method
helper_method :encrypt_user_id
end

rescue_from Blacklight::Exceptions::ExpiredSessionToken do
head :unauthorized
Expand Down
17 changes: 3 additions & 14 deletions app/models/blacklight/suggest_search.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

module Blacklight
class SuggestSearch
attr_reader :request_params, :repository

##
# @param [Hash] params
# @param [Blacklight::AbstractRepository] repository
def initialize(params, repository)
@request_params = { q: params[:q] }
@repository = repository
Expand All @@ -15,20 +17,7 @@ def initialize(params, repository)
# Blacklight::Suggest::Response
# @return [Blacklight::Suggest::Response]
def suggestions
Blacklight::Suggest::Response.new suggest_results, request_params, suggest_handler_path
end

##
# Query the suggest handler using RSolr::Client::send_and_receive
# @return [RSolr::HashWithResponse]
def suggest_results
repository.connection.send_and_receive(suggest_handler_path, params: request_params)
end

##
# @return [String]
def suggest_handler_path
repository.blacklight_config.autocomplete_path
repository.suggestions(request_params)
end
end
end
4 changes: 3 additions & 1 deletion app/models/concerns/blacklight/document.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true
##

require 'globalid'

##
# = Introduction
# Blacklight::Document is the module with logic for a class representing
Expand Down
8 changes: 5 additions & 3 deletions app/models/concerns/blacklight/suggest/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@
module Blacklight
module Suggest
class Response
attr_reader :response, :request_params, :suggest_path
attr_reader :response, :request_params, :suggest_path, :suggester_name

##
# Creates a suggest response
# @param [RSolr::HashWithResponse] response
# @param [Hash] request_params
# @param [String] suggest_path
def initialize(response, request_params, suggest_path)
# @param [String] suggester_name
def initialize(response, request_params, suggest_path, suggester_name)
@response = response
@request_params = request_params
@suggest_path = suggest_path
@suggester_name = suggester_name
end

##
# Trys the suggestor response to return suggestions if they are
# present
# @return [Array]
def suggestions
response.try(:[], suggest_path).try(:[], 'mySuggester').try(:[], request_params[:q]).try(:[], 'suggestions') || []
(response.try(:[], suggest_path).try(:[], suggester_name).try(:[], request_params[:q]).try(:[], 'suggestions') || []).uniq
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions blacklight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|

s.add_dependency "rails", ">= 4.2", "< 6"
s.add_dependency "globalid"
s.add_dependency "jbuilder"
s.add_dependency "jbuilder", '~> 2.7'
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.6", "< 3" # Library for interacting with rSolr.
Expand All @@ -39,9 +39,10 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec-rails", "~> 3.5"
s.add_development_dependency "rspec-its"
s.add_development_dependency "rspec-collection_matchers", ">= 1.0"
s.add_development_dependency "capybara", '~> 2.6'
s.add_development_dependency "poltergeist"
s.add_development_dependency 'engine_cart', '~> 1.0'
s.add_development_dependency "capybara", '>= 2', '< 4'
s.add_development_dependency 'chromedriver-helper', '< 2.0.0' # 2.1.0 is causing "Unable to find chromedriver" on Travis
s.add_development_dependency "selenium-webdriver", '>= 3.13.1'
s.add_development_dependency 'engine_cart', '~> 1.2'
s.add_development_dependency "equivalent-xml"
s.add_development_dependency "coveralls"
s.add_development_dependency "simplecov"
Expand Down
8 changes: 4 additions & 4 deletions lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'deprecation'
require 'blacklight/utils'
require 'active_support/hash_with_indifferent_access'
require 'jbuilder'

module Blacklight
autoload :AbstractRepository, 'blacklight/abstract_repository'
Expand Down Expand Up @@ -105,17 +106,16 @@ 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
14 changes: 13 additions & 1 deletion lib/blacklight/abstract_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ def search(params = {})
raise NotImplementedError
end

protected
# Query the fields that exist from the index
# @return [Hash]
def reflect_fields
raise NotImplementedError
end

##
# Is the repository in a working state?
def ping
raise NotImplementedError
end

private

def connection_config
blacklight_config.connection_config
Expand Down
3 changes: 2 additions & 1 deletion lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def default_values
default_more_limit: 20,
# proc for determining whether the session is a crawler/bot
# ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ }
crawler_detector: nil
crawler_detector: nil,
autocomplete_suggester: 'mySuggester'
}
end
end
Expand Down

0 comments on commit 6ea58a6

Please sign in to comment.