Class: Core::Abilities::Application

Inherits:
Base
  • Object
show all
Defined in:
app/api/core/abilities.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Methods included from Base::ClassMethods

#recorder_helper

Constructor Details

#initialize(request) ⇒ Application

Returns a new instance of Application.


139
140
141
142
# File 'app/api/core/abilities.rb', line 139

def initialize(request)
  @api_application = ApiApplication.find_by(key: request.authorisation_code)
  super
end

Instance Method Details

#authenticate!(user_ability) ⇒ Object

The decision as to whether the application requires the user to be authenticated is made by the application. If it does, however, then the user abilities may need to be changed so we need to modify that too.


179
180
181
182
183
184
185
186
187
188
189
# File 'app/api/core/abilities.rb', line 179

def authenticate!(user_ability)
  single_sign_on_cookie = @request.authentication_code
  if single_sign_on_cookie.blank? && cannot?(:authenticate, :nil)
    Core::Service::Authentication::UnauthenticatedError.no_cookie!
  elsif single_sign_on_cookie.present?
    user = ::User.find_by(api_key: single_sign_on_cookie) or Core::Service::Authentication::UnauthenticatedError.unauthenticated!
    @request.service.instance_variable_set(:@user, user)
  end

  user_ability.authenticated!
end

#privilegeObject


144
145
146
# File 'app/api/core/abilities.rb', line 144

def privilege
  @api_application.privilege.to_sym
end