Class: UffizziCore::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Pundit::Authorization, AuthManagement, AuthorizationConcern, DependencyInjectionConcern, ResponseService
Defined in:
app/controllers/uffizzi_core/application_controller.rb

Constant Summary collapse

DEFAULT_PAGE =
1
DEFAULT_PER_PAGE =
20
RESCUABLE_EXCEPTIONS =
[RuntimeError, TypeError, NameError, ArgumentError, SyntaxError].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DependencyInjectionConcern

#ci_module, #ci_session, #controller_settings_service, #deployment_memory_module, #domain_module, #find_build_parser_module, #find_ingress_parser_module, #find_volume_parser_module, #notification_module, #password_protection_module, #template_memory_module, #user_access_module

Methods included from AuthorizationConcern

#init_authorize, #pundit_user

Methods included from AuthManagement

#auth_token, #authenticate_request!, #current_user, #current_user_id, #sign_in, #sign_out, #signed_in?

Methods included from ResponseService

#meta

Class Method Details

.responderObject



38
39
40
# File 'app/controllers/uffizzi_core/application_controller.rb', line 38

def self.responder
  UffizziCore::JsonResponder
end

Instance Method Details

#pageObject



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

def page
  params[:page] || DEFAULT_PAGE
end

#per_pageObject



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

def per_page
  params[:per_page] || DEFAULT_PER_PAGE
end

#policy_contextObject



34
35
36
# File 'app/controllers/uffizzi_core/application_controller.rb', line 34

def policy_context
  UffizziCore::BaseContext.new(current_user, user_access_module, params)
end

#q_paramObject



57
58
59
# File 'app/controllers/uffizzi_core/application_controller.rb', line 57

def q_param
  params[:q] || ActionController::Parameters.new
end

#render_errors(errors) ⇒ Object



51
52
53
54
55
# File 'app/controllers/uffizzi_core/application_controller.rb', line 51

def render_errors(errors)
  json = { errors: errors }

  render json: json, status: :unprocessable_entity
end

#render_not_authorizedObject



30
31
32
# File 'app/controllers/uffizzi_core/application_controller.rb', line 30

def render_not_authorized
  render json: { errors: { title: [I18n.t('session.unauthorized')] } }, status: :forbidden
end

#render_not_found(exception) ⇒ Object



42
43
44
45
# File 'app/controllers/uffizzi_core/application_controller.rb', line 42

def render_not_found(exception)
  resource = exception.model || 'Resource'
  render json: { errors: { title: ["#{resource} Not Found"] } }, status: :not_found
end

#render_server_error(error) ⇒ Object



47
48
49
# File 'app/controllers/uffizzi_core/application_controller.rb', line 47

def render_server_error(error)
  render json: { errors: { title: [error] } }, status: :internal_server_error
end