Class: Avo::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ApplicationHelper, UrlHelpers, Pagy::Backend, Pundit, Pundit::Authorization
Defined in:
app/controllers/avo/application_controller.rb

Instance Method Summary collapse

Methods included from UrlHelpers

#edit_resource_path, #new_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resource_view_path, #resources_path

Methods included from ApplicationHelper

#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg, #white_panel_classes

Instance Method Details

#_current_userObject



95
96
97
# File 'app/controllers/avo/application_controller.rb', line 95

def _current_user
  instance_eval(&Avo.configuration.current_user)
end

#check_avo_licenseObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/avo/application_controller.rb', line 70

def check_avo_license
  # Check to see if the path is a custom tool
  if on_custom_tool_page
    if @license.lacks(:custom_tools) || @license.invalid?
      message = "Your license is invalid or doesn't support custom tools."
    end
  end

  # Check to see if the path is a dashboard
  if on_dashboards_path
    if @license.lacks(:dashboards) || @license.invalid?
      message = "Your license is invalid or doesn't support dashboards."
    end
  end

  if message.present?
    if Rails.env.development? || Rails.env.test?
      @custom_tools_alert_visible = message
    elsif @license.lacks_with_trial(:custom_tools)
      # Raise error in non-development environments.
      raise Avo::LicenseInvalidError, message
    end
  end
end

#contextObject



99
100
101
# File 'app/controllers/avo/application_controller.rb', line 99

def context
  instance_eval(&Avo.configuration.context)
end

#exception_logger(exception) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/avo/application_controller.rb', line 39

def exception_logger(exception)
  respond_to do |format|
    format.html { raise exception }
    format.json {
      render json: {
        errors: exception.respond_to?(:record) && exception.record.present? ? exception.record.errors : [],
        message: exception.message,
        traces: exception.backtrace
      }, status: ActionDispatch::ExceptionWrapper.status_code_for_exception(exception.class.name)
    }
  end
end

#init_appObject



33
34
35
36
37
# File 'app/controllers/avo/application_controller.rb', line 33

def init_app
  Avo::App.init request: request, context: context, current_user: _current_user, view_context: view_context, params: params

  @license = Avo::App.license
end

#render(*args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/avo/application_controller.rb', line 52

def render(*args)
  raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:check_avo_license).source_location.first.match?(/.*\/app\/controllers\/avo\/application_controller\.rb/)

  if params[:controller] == "avo/search" && params[:action] == "index"
    raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:index).source_location.first.match?(/.*\/app\/controllers\/avo\/search_controller\.rb/)
  end

  if params[:controller] == "avo/dashboards" && params[:action] == "show"
    raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:show).source_location.first.match?(/.*\/app\/controllers\/avo\/dashboards_controller\.rb/)
  end

  if params[:controller] == "avo/dashboards" && params[:action] == "card"
    raise Avo::LicenseVerificationTemperedError, "License verification mechanism tempered with." unless method(:card).source_location.first.match?(/.*\/app\/controllers\/avo\/dashboards_controller\.rb/)
  end

  super(*args)
end

#turbo_frame_request?Boolean

This is coming from Turbo::Frames::FrameRequest module. Exposing it as public method

Returns:

  • (Boolean)


105
106
107
# File 'app/controllers/avo/application_controller.rb', line 105

def turbo_frame_request?
  super
end