Sha256: 84a1d5f3075fffe02d563dd916ec1d65c90216d684b0635e2522367369752828

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

require_relative '../context'

module Immunio
  module RedirectHook
    extend ActiveSupport::Concern

    included do
      Immunio::Utils.alias_method_chain self, :redirect_to, :immunio if method_defined? :redirect_to
    end

    protected
      def redirect_to_with_immunio(options = {}, response_status = {})
        Immunio.logger.debug { "ActiveSupport checking redirect." }
        Request.time "plugin", "#{Module.nesting[0]}::#{__method__}" do
          # redirect_to excepts a variety of argument types
          # but the only one that creates a absolute URL redirect
          # is a string, so we only call the hook in that case.
          # However we have to call Proc arguments to determine
          # if they return a string...
          loptions = options
          if loptions.is_a? Proc then
            loptions = loptions.call
          end
          if loptions.is_a? String then
            strict_context, loose_context, stack = Immunio::Context.context() # rubocop:disable Lint/UselessAssignment
            Immunio.run_hook! "redirect", "framework_redirect",
                              destination_url: loptions,
                              context_key: loose_context,
                              stack: stack
          end
          Request.pause "plugin", "#{Module.nesting[0]}::#{__method__}" do
            redirect_to_without_immunio( options, response_status )
          end
        end
      end
  end
end

Immunio::Plugin.load 'ActionController (Redirect)', feature: 'redirect' do |plugin|
  ActionController::Base.send :include, Immunio::RedirectHook

  plugin.loaded! ActionPack::VERSION::STRING
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
immunio-1.1.6 lib/immunio/plugins/redirect.rb
immunio-1.1.5 lib/immunio/plugins/redirect.rb
immunio-1.1.2 lib/immunio/plugins/redirect.rb