Class: ZuoraConnect::ZuoraUser

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/zuora_connect/zuora_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



4
5
6
# File 'app/models/zuora_connect/zuora_user.rb', line 4

def session
  @session
end

Class Method Details

.update_id_response(zuora_user_id, zuora_entity_id, zuora_current_identity, app_instance, permissions) ⇒ Object

zuora_user_id/zuora_entity_id both come from cookie or headers zuora_current_identity comes from session app_instance is only needed to try to migrate :/



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/zuora_connect/zuora_user.rb', line 11

def self.update_id_response(zuora_user_id, zuora_entity_id, zuora_current_identity, app_instance, permissions)
  zuora_user = find_or_create_by!(zuora_user_id: zuora_user_id) do |user|
    user.zuora_identity_response = { zuora_entity_id => zuora_current_identity }
    user.app_permissions = permissions
  end

  zuora_user.zuora_identity_response[zuora_entity_id] = zuora_current_identity
  zuora_user.app_permissions = permissions

  if zuora_user.changed?
    zuora_user.save!
  end

  zuora_user
# NOTE(hartley): this rescue is deprecated. We should not be migrating in production
rescue ActiveRecord::StatementInvalid => e
  raise unless e.message.include?('PG::UndefinedTable') && e.message.include?('zuora_users')

  ZuoraConnect.logger.fatal('Error querying zuora_users table: attempting migration to recover')

  app_instance.apartment_switch(nil, true)
  retry
end