module FatModelAuth::ControllerHelpers

Protected Instance Methods

access_denied?() click to toggle source
# File lib/fat_model_auth/controller_helpers.rb, line 14
def access_denied?
  authority = get_authority

  access_granted = authority.allows(current_user).send "to_#{params[:action]}?"
  if access_granted
    false
  else
    respond_with_404_page
    true
  end
end
auth_required() click to toggle source
# File lib/fat_model_auth/controller_helpers.rb, line 7
def auth_required
  authority = get_authority

  access_granted = authority.allows(current_user).send "to_#{params[:action]}?"
  respond_with_404_page unless access_granted
end

Private Instance Methods

get_authority() click to toggle source
# File lib/fat_model_auth/controller_helpers.rb, line 28
def get_authority
  if self.respond_to?(:override_authority, true)
    authority = override_authority
    raise FatModelAuth::AuthException, "override_authority defined but nil" if authority.nil?
  else
    authority_name = controller_name.singularize
    authority = instance_variable_get("@#{authority_name}")
    raise FatModelAuth::AuthException, "#{authority_name} is nil" if authority.nil?
  end

  return authority
end
respond_with_404_page() click to toggle source
# File lib/fat_model_auth/controller_helpers.rb, line 41
def respond_with_404_page
  if defined?(Rails)
    render file: "#{Rails.root}/public/404.html", status: 404, layout: false
  else
    render nothing: true, status: 404, layout: false
  end
end