Class: Panda::Core::Admin::BaseController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Panda::Core::Admin::BaseController
- 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
Direct Known Subclasses
DashboardController, Editor::SearchController, FeatureFlagsController, FileCategoriesController, FilesController, ImportSessionsController, MyProfile::LoginsController, MyProfileController, SearchController, SessionsController, TagsController, UsersController
Instance Method Summary collapse
- #add_breadcrumb(name, path = nil) ⇒ Object
- #authenticate_admin_user! ⇒ Object
- #authenticate_user! ⇒ Object
- #breadcrumbs ⇒ Object
-
#current_user ⇒ Object
Required for paper_trail and seems as good as convention these days.
-
#set_current_request_details ⇒ void
Set the current request details.
- #user_signed_in? ⇒ Boolean
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 (name, path = nil) << 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.admin_login_path, flash: {error: "Please login to view this!"} return end return if redirect_to panda_core.admin_login_path, 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 |
#breadcrumbs ⇒ Object
38 39 40 |
# File 'app/controllers/panda/core/admin/base_controller.rb', line 38 def @breadcrumbs ||= [] end |
#current_user ⇒ Object
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_details ⇒ void
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 |