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


137
138
139
140
# File 'app/api/core/abilities.rb', line 137

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.


175
176
177
178
179
180
181
182
183
184
185
# File 'app/api/core/abilities.rb', line 175

def authenticate!(user_ability)
  single_sign_on_cookie = @request.authentication_code
  if single_sign_on_cookie.blank? and cannot?(:authenticate, :nil)
    Core::Service::Authentication::UnauthenticatedError.no_cookie!
  elsif not single_sign_on_cookie.blank?
    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


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

def privilege
  @api_application.privilege.to_sym
end