Class: Core::Abilities::Application

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

Instance Method Summary collapse

Methods included from Base::ClassMethods

#recorder_helper

Constructor Details

#initialize(request) ⇒ Application

Returns a new instance of Application.



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

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.



184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/api/core/abilities.rb', line 184

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



148
149
150
# File 'app/api/core/abilities.rb', line 148

def privilege
  @api_application.privilege.to_sym
end