Module: CurationConcerns::ApplicationControllerBehavior
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/curation_concerns/application_controller_behavior.rb
Overview
Inherit from the host app’s ApplicationController This will configure e.g. the layout used by the host
Instance Method Summary collapse
-
#deny_access(exception) ⇒ Object
Called by Hydra::Controller::ControllerBehavior when CanCan::AccessDenied is caught.
- #render_404 ⇒ Object
-
#render_json_response(response_type: :success, message: nil, options: {}) ⇒ Object
render a json response for
response_type
.
Instance Method Details
#deny_access(exception) ⇒ Object
Called by Hydra::Controller::ControllerBehavior when CanCan::AccessDenied is caught
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/concerns/curation_concerns/application_controller_behavior.rb', line 23 def deny_access(exception) # For the JSON message, we don't want to display the default CanCan messages, # just custom Hydra messages such as "This item is under embargo.", etc. = exception. if exception.is_a? Hydra::AccessDenied if current_user && current_user.persisted? respond_to do |wants| wants.html do if [:show, :edit, :create, :update, :destroy].include? exception.action render 'curation_concerns/base/unauthorized', status: :unauthorized else redirect_to main_app.root_url, alert: exception. end end wants.json { render_json_response(response_type: :forbidden, message: ) } end else session['user_return_to'.freeze] = request.url respond_to do |wants| wants.html { redirect_to main_app.new_user_session_path, alert: exception. } wants.json { render_json_response(response_type: :unauthorized, message: ) } end end end |
#render_404 ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/controllers/concerns/curation_concerns/application_controller_behavior.rb', line 13 def render_404 # use standard, possibly locally overridden, 404.html file. Even for # possibly non-html formats, this is consistent with what Rails does # on raising an ActiveRecord::RecordNotFound. Rails.root IS needed # for it to work under testing, without worrying about CWD. render file: "#{Rails.root}/public/404.html", status: :not_found, layout: false end |
#render_json_response(response_type: :success, message: nil, options: {}) ⇒ Object
render a json response for response_type
49 50 51 52 |
# File 'app/controllers/concerns/curation_concerns/application_controller_behavior.rb', line 49 def render_json_response(response_type: :success, message: nil, options: {}) json_body = CurationConcerns::API.generate_response_body(response_type: response_type, message: , options: ) render json: json_body, status: response_type end |