Class: Jwtauth::Policy::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/jwtauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, scope) ⇒ Scope

Returns a new instance of Scope.



467
468
469
470
# File 'lib/jwtauth.rb', line 467

def initialize(user, scope)
  @user = user
  @scope = scope
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



465
466
467
# File 'lib/jwtauth.rb', line 465

def scope
  @scope
end

#userObject (readonly)

Returns the value of attribute user.



465
466
467
# File 'lib/jwtauth.rb', line 465

def user
  @user
end

Instance Method Details

#resolveObject



472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/jwtauth.rb', line 472

def resolve
  case get_level_of_access(Privileges::READ)
  when LevelsOfAccess::BUSINESS_UNIT
    scope.where(scope::ForeignKeys::DEPARTMENT_ID => @user.departments[LevelsOfAccess::BUSINESS_UNIT])
  when LevelsOfAccess::FAMILY_BU_TREE
    scope.where(scope::ForeignKeys::DEPARTMENT_ID => @user.departments[LevelsOfAccess::FAMILY_BU_TREE])
  when LevelsOfAccess::ORGANIZATION
    scope.where(scope::ForeignKeys::COMPANY_ID => @user.company_id)
  else
    scope.where(scope::ForeignKeys::USER_ID => @user.id)
  end
end