Skip to content

Commit

Permalink
Break out rescue_from blocks to named methods
Browse files Browse the repository at this point in the history
  • Loading branch information
atz committed Nov 23, 2016
1 parent 6d411b1 commit 9b339a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
Expand Up @@ -6,14 +6,8 @@ module ApplicationControllerBehavior

included do
helper CurationConcerns::MainAppHelpers

rescue_from ActiveFedora::ObjectNotFoundError do |exception|
not_found_response(exception)
end

rescue_from Blacklight::Exceptions::InvalidSolrID do |exception|
not_found_response(exception)
end
rescue_from ActiveFedora::ObjectNotFoundError, with: :not_found_response
rescue_from Blacklight::Exceptions::InvalidSolrID, with: :not_found_response
end

def render_404
Expand Down
Expand Up @@ -15,16 +15,7 @@ module CollectionsControllerBehavior
copy_blacklight_config_from(::CatalogController)

# Catch permission errors
rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
if exception.action == :edit
redirect_to(url_for(action: 'show'), alert: 'You do not have sufficient privileges to edit this document')
elsif current_user && current_user.persisted?
redirect_to root_url, alert: exception.message
else
session['user_return_to'] = request.url
redirect_to new_user_session_url, alert: exception.message
end
end
rescue_from Hydra::AccessDenied, CanCan::AccessDenied, with: :deny_collection_access

# actions: audit, index, create, new, edit, show, update, destroy, permissions, citation
before_action :authenticate_user!, except: [:show, :index]
Expand Down Expand Up @@ -56,6 +47,17 @@ module CollectionsControllerBehavior
self.member_search_builder_class = CurationConcerns::CollectionMemberSearchBuilder
end

def deny_collection_access(exception)
if exception.action == :edit
redirect_to(url_for(action: 'show'), alert: 'You do not have sufficient privileges to edit this document')
elsif current_user && current_user.persisted?
redirect_to root_url, alert: exception.message
else
session['user_return_to'] = request.url
redirect_to new_user_session_url, alert: exception.message
end
end

def index
# run the solr query to find the collections
query = list_search_builder.with(params).query
Expand Down Expand Up @@ -90,7 +92,6 @@ def after_create

def after_create_error
form

respond_to do |format|
format.html { render action: 'new' }
format.json { render json: @collection.errors, status: :unprocessable_entity }
Expand Down Expand Up @@ -120,7 +121,6 @@ def after_update
def after_update_error
form
query_collection_members

respond_to do |format|
format.html { render action: 'edit' }
format.json { render json: @collection.errors, status: :unprocessable_entity }
Expand Down
Expand Up @@ -8,13 +8,15 @@ module SingleUseLinksControllerBehavior
before_action :authenticate_user!
before_action :authorize_user!
# Catch permission errors
rescue_from Hydra::AccessDenied, CanCan::AccessDenied do |exception|
if current_user && current_user.persisted?
redirect_to main_app.root_url, alert: "You do not have sufficient privileges to create links to this document"
else
session["user_return_to"] = request.url
redirect_to new_user_session_url, alert: exception.message
end
rescue_from Hydra::AccessDenied, CanCan::AccessDenied, with: :deny_link_access
end

def deny_link_access(exception)
if current_user && current_user.persisted?
redirect_to main_app.root_url, alert: "You do not have sufficient privileges to create links to this document"
else
session["user_return_to"] = request.url
redirect_to new_user_session_url, alert: exception.message
end
end

Expand Down

0 comments on commit 9b339a3

Please sign in to comment.