Sha256: cb5a99fea7b9733c8e8c0898fd0c41d6c8be4e2fc486f482f31a2524e2a25a05

Contents?: true

Size: 1.2 KB

Versions: 61

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Koi
  module Controller
    module HasAdminUsers
      extend ActiveSupport::Concern

      included do
        helper_method :admin_signed_in?
        helper_method :current_admin_user
        helper_method :current_admin
      end

      def admin_signed_in?
        current_admin_user.present?
      end

      def current_admin_user
        @current_admin_user ||= Admin::User.find(session[:admin_user_id]) if session[:admin_user_id].present?
      end

      # @deprecated Use current_admin_user instead
      alias_method :current_admin, :current_admin_user

      module Test
        # Include in view specs to stub out the current admin user
        module ViewHelper
          extend ActiveSupport::Concern

          included do
            before do
              view.singleton_class.module_eval do
                def admin_signed_in?
                  current_admin_user.present?
                end

                def current_admin_user
                  respond_to?(:admin_user) ? admin_user : nil
                end

                alias_method :current_admin, :current_admin_user
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
katalyst-koi-4.14.1 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.14.0 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.13.2 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.13.0 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.6 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.5 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.4 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.3 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.2 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.1 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.12.0 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.11.2 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.11.1 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.11.0 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.10.3 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.10.2 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.10.1 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.10.0 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.9.5 app/controllers/concerns/koi/controller/has_admin_users.rb
katalyst-koi-4.9.4 app/controllers/concerns/koi/controller/has_admin_users.rb