Sha256: 774887446eaf108158706224706b36e3c9d4c51d084bc3dfbea5618b1ff6fac9

Contents?: true

Size: 1.26 KB

Versions: 28

Compression:

Stored size: 1.26 KB

Contents

module ZuoraConnect
  class ZuoraUser < ActiveRecord::Base
    self.table_name = "zuora_users"
    attr_accessor :session

    cattr_accessor :current_user_id

    # 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 :/
    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
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
zuora_connect-3.1.5.pre.d app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.5.pre.c app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.5.pre.b app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.5.pre.a app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.5 app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.4 app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.3 app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.2.pre.a app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.2 app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.1.pre.c app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.1.pre.b app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.1.pre.a app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.1 app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0 app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0.pre.g app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0.pre.e app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0.pre.d app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0.pre.c app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0.pre.b app/models/zuora_connect/zuora_user.rb
zuora_connect-3.1.0.pre.a app/models/zuora_connect/zuora_user.rb