Sha256: 4392942118a0017b1f828f5195fdb0c9e03b077cb8f4e37c8ed9ef32e5e9255f

Contents?: true

Size: 923 Bytes

Versions: 18

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

require 'devise/strategies/authenticatable'
require 'devise/strategies/base'

module Devise
  module Strategies
    class ImpersonateStrategy < Authenticatable
      include ::G5Authenticatable::ImpersonateSessionable

      # Prevents unauthorized users to impersonate another user when visiting
      # the correct URL
      def valid?
        allowed = user_to_impersonate.present? &&
                  able_to_impersonate?(impersonation_user, user_to_impersonate)
        return allowed if allowed
        clear_impersonation_keys
        true
      rescue # Safety net
        clear_impersonation_keys
        false
      end

      def authenticate!
        if user_to_impersonate.present?
          success!(user_to_impersonate)
        else
          clear_impersonation_keys
          fail('You do not have sufficient access to this account')
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
g5_authenticatable-1.1.4 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.4.rc.3 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.4.rc.2 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.4.rc.1 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2.pre.1 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2.rc.5 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2.rc.4 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2.rc.3 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2.rc.2 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.2.rc.1 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.1 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.1.0 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.0.0 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.0.0.pre.4 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.0.0.pre.3 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.0.0.pre.2 config/initializers/impersonate_strategy.rb
g5_authenticatable-1.0.0.pre.1 config/initializers/impersonate_strategy.rb