Sha256: 6e2b84bb14ed13b1daef6bdeeab4bb88a9c3f65b019a1cda1ce38b65084c6aa1

Contents?: true

Size: 1.21 KB

Versions: 16

Compression:

Stored size: 1.21 KB

Contents

# Include this module into any of your Controller classes to add Hydra functionality
#
# The primary function of this module is to mix in a number of other Hydra Modules, including 
#   Hydra::AccessControlsEnforcement
#
# @example 
#  class CustomHydraController < ApplicationController  
#    include Hydra::Controller::ControllerBehavior
#  end
#
module Hydra::Controller::ControllerBehavior
  extend ActiveSupport::Concern

  included do
    # Other modules to auto-include
    include Hydra::AccessControlsEnforcement
  
    # Catch permission errors
    rescue_from Hydra::AccessDenied do |exception|
      if (exception.action == :edit)
        redirect_to({:action=>'show'}, :alert => exception.message)
      elsif current_user and 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
  end
  
  
  # get the currently configured user identifier.  Can be overridden to return whatever (ie. login, email, etc)
  # defaults to using whatever you have set as the Devise authentication_key
  def user_key
    current_user.user_key if current_user
  end
  
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hydra-core-5.4.1 lib/hydra/controller/controller_behavior.rb
hydra-core-5.4.0 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre7 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre6 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre5 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre4 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre3 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre2 lib/hydra/controller/controller_behavior.rb
hydra-core-6.0.0.pre1 lib/hydra/controller/controller_behavior.rb
hydra-core-5.4.0.pre1 lib/hydra/controller/controller_behavior.rb
hydra-core-5.3.0 lib/hydra/controller/controller_behavior.rb
hydra-core-5.2.0 lib/hydra/controller/controller_behavior.rb
hydra-core-5.1.0 lib/hydra/controller/controller_behavior.rb
hydra-core-5.0.1 lib/hydra/controller/controller_behavior.rb
hydra-core-5.0.0 lib/hydra/controller/controller_behavior.rb
hydra-core-5.0.0.rc1 lib/hydra/controller/controller_behavior.rb