Class: OktaRedis::App

Inherits:
Model show all
Defined in:
app/models/okta_redis/app.rb

Constant Summary collapse

CLASS_NAME =
'AppService'
REDIS_CONFIG_KEY =
:okta_response_app

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Instance Attribute Summary collapse

Attributes inherited from Model

#id, #user

Instance Method Summary collapse

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger

Methods included from Common::CacheAside

#cache, #cached?, #do_cached_with

Methods inherited from Common::RedisStore

create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ App

Returns a new instance of App.



9
10
11
12
# File 'app/models/okta_redis/app.rb', line 9

def initialize(attributes = {}, persisted = false)
  super(attributes, persisted)
  @grants = []
end

Instance Attribute Details

#grantsObject

Returns the value of attribute grants.



7
8
9
# File 'app/models/okta_redis/app.rb', line 7

def grants
  @grants
end

Instance Method Details

#delete_grantsObject

rubocop:enable Rails/FindEach



50
51
52
53
54
55
56
57
# File 'app/models/okta_redis/app.rb', line 50

def delete_grants
  raise 'Requires user set!' unless @user

  fetch_grants if @grants.length.zero?
  @user.okta_grants.delete_grants(
    @grants.map { |grant| grant['id'] }
  )
end

#fetch_grantsObject

rubocop:disable Rails/FindEach



37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/okta_redis/app.rb', line 37

def fetch_grants
  raise 'Requires user set!' unless @user

  @user.okta_grants.all.each do |grant|
    links = grant['_links']
    app_id = links['app']['href'].split('/').last
    @grants << grant if app_id == @id
  end

  @grants
end

#logoObject



22
23
24
# File 'app/models/okta_redis/app.rb', line 22

def 
  okta_response.body['_links']['logo'].last['href']
end

#privacy_urlObject



26
27
28
29
30
31
32
33
34
# File 'app/models/okta_redis/app.rb', line 26

def privacy_url
  app_name = okta_response.body['label']
  app_data = DirectoryApplication.find_by(name: app_name)
  if app_data
    app_data.privacy_url
  else
    ''
  end
end