Sha256: e8eb6def11a8ef29b1e6e273452798b411666d07d2306617df9f396801c35648

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

module Guts
  # Main inherited controller class
  # @abstract
  class ApplicationController < ActionController::Base
    include SessionsHelper
    include MultisiteConcern
    
    protect_from_forgery with: :exception
    before_action :firewall
    
    private
    
    # Checks if a user is logged in and an admin
    # If they are not, they are redirected to login
    # @private
    # @note This is a `before_action` method
    def firewall
      # Only run if not on session pages
      unless params[:controller].include? 'session'
        # Only run if logged in
        if logged_in?
          # Check between current user's group and approved groups from configuration
          intersect = current_user.groups.map(&:title) & Guts.configuration.admin_groups
          if !Guts.configuration.admin_groups.empty? && intersect.empty?
            # Logged in user, but not approved for admin panel
            redirect_to new_session_path
          end
        else
          # Not logged in, go to login page
          redirect_to new_session_path
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
guts-1.3.6 app/controllers/guts/application_controller.rb
guts-1.3.5 app/controllers/guts/application_controller.rb
guts-1.3.4 app/controllers/guts/application_controller.rb
guts-1.3.3 app/controllers/guts/application_controller.rb
guts-1.3.2 app/controllers/guts/application_controller.rb
guts-1.3.1 app/controllers/guts/application_controller.rb
guts-1.3.0 app/controllers/guts/application_controller.rb
guts-1.2.2 app/controllers/guts/application_controller.rb
guts-1.2.1 app/controllers/guts/application_controller.rb
guts-1.2.0 app/controllers/guts/application_controller.rb
guts-1.1.1 app/controllers/guts/application_controller.rb
guts-1.1.0 app/controllers/guts/application_controller.rb