Class: Panda::CMS::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ApplicationHelper, ApplicationHelper
Defined in:
app/controllers/panda/cms/application_controller.rb

Instance Method Summary collapse

Methods included from ApplicationHelper

#active_link?, #block_link_to, #component, #level_indent, #menu_indent, #nav_class, #nav_highlight_colour_classes, #panda_cms_collection, #panda_cms_collection_items, #panda_cms_editor, #panda_cms_feature_enabled?, #panda_cms_form_with, #selected_nav_highlight_colour_classes, #table_indent, #title_tag

Instance Method Details

#add_breadcrumb(name, path = nil) ⇒ Object



24
25
26
# File 'app/controllers/panda/cms/application_controller.rb', line 24

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

#authenticate_admin_user!Object



53
54
55
56
57
58
# File 'app/controllers/panda/cms/application_controller.rb', line 53

def authenticate_admin_user!
  return if user_signed_in? && current_user.admin?

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

#authenticate_user!Object



49
50
51
# File 'app/controllers/panda/cms/application_controller.rb', line 49

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


20
21
22
# File 'app/controllers/panda/cms/application_controller.rb', line 20

def breadcrumbs
  @breadcrumbs ||= []
end

#current_userObject

Required for paper_trail and seems as good as convention these days



61
62
63
# File 'app/controllers/panda/cms/application_controller.rb', line 61

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

#set_current_request_detailsvoid

This method returns an undefined value.

Set the current request details



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/panda/cms/application_controller.rb', line 30

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[:user_id]) if session[:user_id]

  # Set CMS current attributes (inherits from Core so has access to all Core attributes)
  Panda::CMS::Current.request_id = request.uuid
  Panda::CMS::Current.user_agent = request.user_agent
  Panda::CMS::Current.ip_address = request.ip
  Panda::CMS::Current.root = request.base_url
  Panda::CMS::Current.user = Panda::Core::Current.user
  Panda::CMS::Current.page = nil

  Panda::CMS.config.url ||= Panda::Core::Current.root
end

#user_signed_in?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/controllers/panda/cms/application_controller.rb', line 65

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