Class: Avo::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ApplicationHelper, UrlHelpers, Pagy::Backend, Pundit
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, #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, #svg, #turbo_frame_wrap

Instance Method Details

#_current_userObject



68
69
70
# File 'app/controllers/avo/application_controller.rb', line 68

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

#check_avo_licenseObject



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

def check_avo_license
  # Check to see if the path is on a custom tool
  unless on_root_path || on_resources_path || on_api_path
    # Display alert on custom tool page if in development.
    if @license.lacks(:custom_tools) || @license.invalid?
      if Rails.env.development? || Rails.env.test?
        @custom_tools_alert_visible = true
      elsif @license.lacks_with_trial(:custom_tools)
        # Raise error in non-development environments.
        raise Avo::LicenseInvalidError, "Your license is invalid or doesn't support custom tools."
      end
    end
  end
end

#contextObject



72
73
74
# File 'app/controllers/avo/application_controller.rb', line 72

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

#exception_logger(exception) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/avo/application_controller.rb', line 30

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



24
25
26
27
28
# File 'app/controllers/avo/application_controller.rb', line 24

def init_app
  Avo::App.init request: request, context: context, root_path: avo.root_path.delete_suffix("/"), current_user: _current_user, view_context: view_context

  @license = Avo::App.license
end

#render(*args) ⇒ Object



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

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

  super(*args)
end