Class: Dune::Api::BaseController

Inherits:
ActionController::Metal
  • Object
show all
Defined in:
app/controllers/dune/api/base_controller.rb

Constant Summary collapse

MODULES =
[
  AbstractController::Rendering,
  ActionController::Redirecting,
  ActionView::Rendering, # This is needed because of respond_with
  ActionController::Rendering,
  ActionController::Renderers::All,
  ActionController::ConditionalGet,
  ActionController::MimeResponds,
  ActionController::ImplicitRender,
  ActionController::StrongParameters,
  ActionController::ForceSSL,
  ActionController::HttpAuthentication::Token::ControllerMethods,
  ActionController::Serialization,
  ActionController::Instrumentation,
  ActionController::ParamsWrapper,
  ActionController::Rescue,
  HasScope,
  Pundit,
  Dune::Api::Engine.routes.url_helpers,
  Rails.application.routes.url_helpers,
  Pundit,

  #ActionController::Helpers,
  #ActionController::UrlFor,
  #ActionController::RackDelegation,
  #AbstractController::Callbacks,
]

Instance Method Summary collapse

Instance Method Details

#access_tokenObject



45
46
47
# File 'app/controllers/dune/api/base_controller.rb', line 45

def access_token
  @access_token
end

#check_authorization!Object



57
58
59
60
61
62
# File 'app/controllers/dune/api/base_controller.rb', line 57

def check_authorization!
  authenticate_or_request_with_http_token do |token, options|
    @access_token = AccessToken.find_by(code: token)
  end
  @access_token.is_a?(AccessToken) or handle_unauthorized
end

#current_userObject



49
50
51
# File 'app/controllers/dune/api/base_controller.rb', line 49

def current_user
  @current_user ||= access_token.user
end

#handle_forbiddenObject



41
42
43
# File 'app/controllers/dune/api/base_controller.rb', line 41

def handle_forbidden
  head :forbidden
end

#handle_unauthorizedObject



64
65
66
# File 'app/controllers/dune/api/base_controller.rb', line 64

def handle_unauthorized
  head :unauthorized
end

#require_admin!Object



53
54
55
# File 'app/controllers/dune/api/base_controller.rb', line 53

def require_admin!
  handle_unauthorized unless current_user.admin?
end