Class: Panda::Core::Admin::BaseController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Panda::Core::AdminAuthorization, Panda::Core::Authorizable
Defined in:
app/controllers/panda/core/admin/base_controller.rb

Overview

Base controller for all admin interfaces across Panda gems Provides authentication, helpers, and hooks for extending functionality

Instance Method Summary collapse

Methods included from Panda::Core::Authorizable

#authorize!, #authorized_for?, #authorized_for_admin_access?, #can?

Instance Method Details

#add_breadcrumb(name, path = nil) ⇒ Object



42
43
44
# File 'app/controllers/panda/core/admin/base_controller.rb', line 42

def add_breadcrumb(name, path = nil)
  breadcrumbs << Breadcrumb.new(name, path)
end

#authenticate_admin_user!Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/panda/core/admin/base_controller.rb', line 63

def authenticate_admin_user!
  unless user_signed_in?
    # Preserve the requested path so it can be restored after authentication.
    # Skip login/auth paths to avoid redirect loops.
    admin_prefix = Core.config.admin_path
    if request.path.start_with?(admin_prefix) &&
        !request.path.start_with?("#{admin_prefix}/login") &&
        !request.path.start_with?("#{admin_prefix}/auth/")
      session[:post_auth_redirect_path] = request.path
    end

    redirect_to panda_core.,
      flash: {error: "Please login to view this!"}
    return
  end

  return if authorized_for_admin_access?

  redirect_to panda_core.,
    flash: {error: "You are not authorized to access the admin area."}
end

#authenticate_user!Object



59
60
61
# File 'app/controllers/panda/core/admin/base_controller.rb', line 59

def authenticate_user!
  redirect_to main_app.root_path, flash: {error: "Please login to view this!"} unless user_signed_in?
end


38
39
40
# File 'app/controllers/panda/core/admin/base_controller.rb', line 38

def breadcrumbs
  @breadcrumbs ||= []
end

#current_userObject

Required for paper_trail and seems as good as convention these days



86
87
88
# File 'app/controllers/panda/core/admin/base_controller.rb', line 86

def current_user
  Panda::Core::Current.user
end

#set_current_request_detailsvoid

This method returns an undefined value.

Set the current request details



48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/panda/core/admin/base_controller.rb', line 48

def set_current_request_details
  # Set Core current attributes
  Panda::Core::Current.request_id = request.uuid
  Panda::Core::Current.user_agent = request.user_agent
  Panda::Core::Current.ip_address = request.ip
  Panda::Core::Current.root = request.base_url
  Panda::Core::Current.user ||= Panda::Core::User.find_by(id: session[Panda::Core::ADMIN_SESSION_KEY]) if session[Panda::Core::ADMIN_SESSION_KEY]

  track_session_activity if Panda::Core::Current.user
end

#user_signed_in?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/controllers/panda/core/admin/base_controller.rb', line 90

def user_signed_in?
  !!Panda::Core::Current.user
end