Sha256: 2825bb250894836634ddfe9f831e15f236ce2e656a162400ad78153e193a8c72

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

#*************************************************************************************
# Insert methods in the Action Controller of a Rails project.
#*************************************************************************************
module Portier::Implants::ActionControllerImplant
  extend ActiveSupport::Concern

  included do
    helper_method :access_denied_message, :can?, :can_view?

    rescue_from Portier::AccessDenied, with: :render_access_denied
  end

  def access_denied_message
    @portier.access_denied_message
  end

  def can?(action, object, options={})
    @portier.can? action, object, options
  end

  def can_view?(tag, options={})
    @portier.can_view? tag, options
  end

  def permitted_params
    @portier.permitted_params
  end

  def protect_app
    @portier = Portier::Base.new(self, current_user)
    @portier.authorize_action
  end

  def render_access_denied
    render plain: "access_denied", status: 401
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
portier-1.1.1 lib/portier/implants/action_controller_implant.rb
portier-1.1.0 lib/portier/implants/action_controller_implant.rb