Class: G5Authenticatable::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/g5_authenticatable/user.rb

Overview

Cache of local user data, populated based on G5 Auth

Constant Summary collapse

GLOBAL_ROLE =
'GLOBAL'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_client_urnObject

helpful for authorizing in Pudit



12
13
14
# File 'app/models/g5_authenticatable/user.rb', line 12

def current_client_urn
  @current_client_urn
end

Instance Method Details

#attributes_from_auth(auth_data) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'app/models/g5_authenticatable/user.rb', line 16

def attributes_from_auth(auth_data)
  super(auth_data).merge(
    first_name: auth_data.info.first_name,
    last_name: auth_data.info.last_name,
    phone_number: auth_data.info.phone,
    title: auth_data.extra.title,
    organization_name: auth_data.extra.organization_name
  )
end

#clientsObject



38
39
40
41
# File 'app/models/g5_authenticatable/user.rb', line 38

def clients
  G5Updatable::ClientPolicy::Scope.new(self, G5Updatable::Client)
                                  .resolve
end

#locationsObject



43
44
45
46
# File 'app/models/g5_authenticatable/user.rb', line 43

def locations
  G5Updatable::LocationPolicy::Scope.new(self, G5Updatable::Location)
                                    .resolve
end

#selectable_clientsObject



33
34
35
36
# File 'app/models/g5_authenticatable/user.rb', line 33

def selectable_clients
  G5Updatable::SelectableClientPolicy::Scope.new(self, G5Updatable::Client)
                                            .resolve
end

#update_roles_from_auth(auth_data) ⇒ Object



26
27
28
29
30
31
# File 'app/models/g5_authenticatable/user.rb', line 26

def update_roles_from_auth(auth_data)
  roles.clear
  auth_data.extra.roles.each do |role|
    role.type == GLOBAL_ROLE ? add_role(role.name) : add_scoped_role(role)
  end
end