Module: Blacklight::Controller
- Extended by:
- ActiveSupport::Concern
- Includes:
- LegacyControllerMethods
- Defined in:
- lib/blacklight/controller.rb
Overview
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.
Instance Method Summary (collapse)
-
- (Object) access_denied
protected
To handle failed authorization attempts, redirect the user to the login form and persist the current request uri as a parameter.
- - (Object) blacklight_config
-
- (Object) current_or_guest_user
(also: #blacklight_current_or_guest_user)
protected
Here's a stub implementation we'll add if it isn't provided for us.
- - (Object) default_catalog_controller
-
- (Object) discard_flash_if_xhr
protected
We discard flash messages generated by the xhr requests to avoid confusing UX.
- - (Boolean) has_user_authentication_provider? protected
-
- (Boolean) request_is_for_user_resource?
protected
Controller and view helper for determining if the current url is a request for a user resource.
- - (Object) require_user_authentication_provider protected
-
- (Object) searches_from_history
protected
Returns a list of Searches from the ids in the user's history.
-
- (Object) transfer_guest_user_actions_to_current_user
protected
When a user logs in, transfer any saved searches or bookmarks to the current_user.
Methods included from LegacyControllerMethods
#choose_layout, #default_html_head, #extra_head_content, #javascript_includes, #layout_name, #stylesheet_links
Instance Method Details
- (Object) access_denied (protected)
To handle failed authorization attempts, redirect the user to the login form and persist the current request uri as a parameter
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/blacklight/controller.rb', line 115 def access_denied # send the user home if the access was previously denied by the same # request to avoid sending the user back to the login page # (e.g. protected page -> logout -> returned to protected page -> home) redirect_to root_url and flash.discard and return if request.referer and request.referer.ends_with? request.fullpath redirect_to root_url and return unless has_user_authentication_provider? redirect_to new_user_session_url(:referer => request.fullpath) end |
- (Object) blacklight_config
40 41 42 |
# File 'lib/blacklight/controller.rb', line 40 def blacklight_config default_catalog_controller.blacklight_config end |
- (Object) current_or_guest_user (protected) Also known as: blacklight_current_or_guest_user
Here's a stub implementation we'll add if it isn't provided for us
67 68 69 70 71 72 73 |
# File 'lib/blacklight/controller.rb', line 67 def current_or_guest_user if defined? super super else current_user if has_user_authentication_provider? end end |
- (Object) default_catalog_controller
36 37 38 |
# File 'lib/blacklight/controller.rb', line 36 def default_catalog_controller CatalogController end |
- (Object) discard_flash_if_xhr (protected)
We discard flash messages generated by the xhr requests to avoid confusing UX.
79 80 81 |
# File 'lib/blacklight/controller.rb', line 79 def discard_flash_if_xhr flash.discard if request.xhr? end |
- (Boolean) has_user_authentication_provider? (protected)
86 87 88 |
# File 'lib/blacklight/controller.rb', line 86 def has_user_authentication_provider? respond_to? :current_user end |
- (Boolean) request_is_for_user_resource? (protected)
Controller and view helper for determining if the current url is a request for a user resource
54 55 56 |
# File 'lib/blacklight/controller.rb', line 54 def request_is_for_user_resource? request.env['PATH_INFO'] =~ /\/?users\/?/ end |
- (Object) require_user_authentication_provider (protected)
90 91 92 |
# File 'lib/blacklight/controller.rb', line 90 def require_user_authentication_provider raise ActionController::RoutingError.new('Not Found') unless has_user_authentication_provider? end |
- (Object) searches_from_history (protected)
Returns a list of Searches from the ids in the user's history.
47 48 49 |
# File 'lib/blacklight/controller.rb', line 47 def searches_from_history session[:history].blank? ? [] : Search.where(:id => session[:history]).order("updated_at desc") end |
- (Object) transfer_guest_user_actions_to_current_user (protected)
When a user logs in, transfer any saved searches or bookmarks to the current_user
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/blacklight/controller.rb', line 96 def transfer_guest_user_actions_to_current_user return unless respond_to? :current_user and respond_to? :guest_user and current_user and guest_user current_user_searches = current_user.searches.all.collect(&:query_params) current_user_bookmarks = current_user.bookmarks.all.collect(&:document_id) guest_user.searches.all.reject { |s| current_user_searches.include?(s.query_params)}.each do |s| s.user_id = current_user.id s.save end guest_user.bookmarks.all.reject { |b| current_user_bookmarks.include?(b.document_id)}.each do |b| b.user_id = current_user.id b.save end end |