zuora_connect 2.0.60l → 2.0.60q

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00f68595c6354e9924c2e73bdb81246bdc858874f49830f94111e0d46b6e8298
4
- data.tar.gz: 1b01b3c05190970c9ad92c461f64b89787b790f3e2ffb6394831ccce425e0d1a
3
+ metadata.gz: 3a9478b4c078e02402f100894a54bac2b08c1a89465e83ec55cb9f1bbe3f5dff
4
+ data.tar.gz: e0d5c40113abe3b72ef867ca59f620ce19dc1dee778a7e4e531aedae68a6812c
5
5
  SHA512:
6
- metadata.gz: e58fc8cd5b36a2be218afab342507a78acb5221001cdc712e61a7e80ad0615797ed42c7ae413d4d5dc179d14784e91eb621ea5be9466a45e904ed97bd5996076
7
- data.tar.gz: df3730519a5b2b1e8b3778866bd6ac59255633666522fe7ec8522e6815a1c87d5aba89fd733ec1eaecf6caeccf74fde010ea40a9d882b20d6fe2cfc4f1ee46a2
6
+ metadata.gz: 2c8392e166c5bad4c990c00344476adec37e7dff8176865202a8fedc47e853222197fc2837dd5ea780b96c7fbb92922bcb482206079d376c29c1fadee90a18d9
7
+ data.tar.gz: 66a9558d6ba34f591a82d1c1f5a92d8930fffde9258afc142e7dd68abbffbfbfdf830bbb2576cfe01e74bef6248ce2bc65b347c16cd08d434b69328fcc407c0b
@@ -21,6 +21,10 @@ module ZuoraConnect
21
21
  HOLDING_PATTERN_SLEEP = 5.seconds
22
22
  CONNECT_APPLICATION_ID = 0
23
23
  CONNECT_COMMUNICATION_SLEEP = Rails.env.test? ? 0.seconds : 5.seconds
24
+ CATALOG_LOOKUP_PAGE_SIZE = 10_000
25
+ CATALOG_LOOKUP_CACHE_TIME_KEY = 'CatalogCachedAt'
26
+ CATALOG_LOOKUP_TTL = 60.seconds
27
+ CATALOG_LOOKUP_CACHE_RESULT_KEY = 'CatalogCache'
24
28
  IGNORED_LOCALS = ['fr', 'ja', 'es', 'zh', 'de']
25
29
  INTERNAL_HOSTS = []
26
30
  LOGIN_TENANT_DESTINATION = 'target_login'
@@ -1006,13 +1010,81 @@ module ZuoraConnect
1006
1010
  # object_id: The id or id's of the object/objects to be returned.
1007
1011
  # child_objects: Whether to include child objects of the object in question.
1008
1012
  # cache: Store individual "1" object lookup in redis for caching.
1009
- def catalog_lookup(entity_id: nil, object: :product, object_id: nil, child_objects: false, cache: false)
1013
+ def catalog_lookup(entity_id: nil, object: :product, object_id: nil, child_objects: false, cache: false, source: 'DB')
1010
1014
  entity_reference = entity_id.blank? ? 'Default' : entity_id
1011
1015
 
1012
1016
  if object_id.present? && ![Array, String].include?(object_id.class)
1013
1017
  raise "Object Id can only be a string or an array of strings"
1014
1018
  end
1015
1019
 
1020
+ if source == 'API'
1021
+ catalog_container = {}
1022
+
1023
+ if (Redis.current.hget(CATALOG_LOOKUP_CACHE_TIME_KEY, self.id).to_i + CATALOG_LOOKUP_TTL.to_i) > Time.now.to_i
1024
+ begin
1025
+ catalog_container = JSON.parse(Redis.current.hget(CATALOG_LOOKUP_CACHE_RESULT_KEY, self.id))
1026
+ rescue JSON::ParserError => ex
1027
+ Rails.logger.warn('Failed to parse catalog cache', ex)
1028
+ end
1029
+ else
1030
+ zuora_login = self.login_lookup(type: 'Zuora').first
1031
+ login = zuora_login.client(entity_reference)
1032
+
1033
+ response = {
1034
+ 'nextPage' => login.rest_endpoint("catalog/products?pageSize=#{CATALOG_LOOKUP_PAGE_SIZE}")
1035
+ }
1036
+
1037
+ while response['nextPage'].present?
1038
+ url = login.rest_endpoint(response['nextPage'].split('/v1/').last)
1039
+ output_json, response = login.rest_call(debug: false, url: url, timeout_retry: true)
1040
+
1041
+ case object
1042
+ when :product
1043
+ output_json.fetch('products', []).each do |product|
1044
+ rate_plans = {}
1045
+ product['productRatePlans'].each do |rate_plan|
1046
+ charges = {}
1047
+ rate_plan['productRatePlanCharges'].each do |charge|
1048
+ charges[charge['id']] = charge.merge(
1049
+ {
1050
+ 'productId' => product['id'],
1051
+ 'productName' => product['name'],
1052
+ 'productRatePlanId' => rate_plan['id'],
1053
+ 'productRatePlanName' => rate_plan['name'],
1054
+ }
1055
+ )
1056
+ end
1057
+
1058
+ rate_plan['productRatePlanCharges'] = charges
1059
+ rate_plans[rate_plan['id']] = rate_plan.merge(
1060
+ {
1061
+ 'productId' => product['id'],
1062
+ 'productName' => product['name']
1063
+ }
1064
+ )
1065
+ end
1066
+
1067
+ product['productRatePlans'] = rate_plans
1068
+ catalog_container[product['id']] = product
1069
+ end
1070
+ else
1071
+ raise "Available objects include [:product]"
1072
+ end
1073
+ end
1074
+
1075
+ Redis.current.hset(CATALOG_LOOKUP_CACHE_RESULT_KEY, self.id, catalog_container.to_json)
1076
+ Redis.current.hset(CATALOG_LOOKUP_CACHE_TIME_KEY, self.id, Time.now.to_i)
1077
+ end
1078
+
1079
+ if object_id.nil?
1080
+ catalog_container.transform_values! { |v| v.except('productRatePlans') }
1081
+ elsif object_id.is_a?(String)
1082
+ catalog_container = catalog_container[object_id]
1083
+ end
1084
+
1085
+ return catalog_container
1086
+ end
1087
+
1016
1088
  if defined?(Redis.current) && object_id.present? && object_id.class == String && object_id.present?
1017
1089
  stub_catalog = cache ? decrypt_data(data: Redis.current.get("Catalog:#{self.id}:#{object_id}:Children:#{child_objects}")) : nil
1018
1090
  object_hierarchy = decrypt_data(data: Redis.current.get("Catalog:#{self.id}:#{object_id}:Hierarchy"))
@@ -2,6 +2,6 @@ module ZuoraConnect
2
2
  class ZuoraUser < ActiveRecord::Base
3
3
  self.table_name = "zuora_users"
4
4
  attr_accessor :session
5
-
5
+ cattr_accessor :current_user_id
6
6
  end
7
7
  end
@@ -13,6 +13,9 @@ require 'logging/connect_formatter'
13
13
  require 'metrics/influx/point_value'
14
14
  require 'metrics/net'
15
15
  require 'mono_logger'
16
+ require 'zuora_connect/zuora_audit'
17
+ require 'active_record'
18
+ ::ActiveRecord::Base.send :include, ZuoraConnect::ZuoraAudit
16
19
 
17
20
  module ZuoraConnect
18
21
  class << self
@@ -442,6 +442,7 @@ module ZuoraConnect
442
442
  @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
443
443
  end
444
444
  @zuora_user.session = session
445
+ ZuoraConnect::ZuoraUser.current_user_id = zuora_user_id
445
446
  session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
446
447
  session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
447
448
  session["#{@appinstance.id}::user::timezone"] = session['ZuoraCurrentIdentity']["timeZone"]
@@ -684,6 +685,7 @@ module ZuoraConnect
684
685
  key = ZuoraConnect.configuration.dev_mode_pass
685
686
  values = {:user => user , :key => key, :appinstance => session["appInstance"]}
686
687
  @appinstance = ZuoraConnect::AppInstance.find_by(:id => values[:appinstance].to_i)
688
+ ZuoraConnect::ZuoraUser.current_user_id = 0
687
689
  if @appinstance.blank?
688
690
  Apartment::Tenant.switch!("public")
689
691
  begin
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.60l"
2
+ VERSION = "2.0.60q"
3
3
  end
@@ -0,0 +1,31 @@
1
+ # Added by @Vina
2
+ # Description: This automatically stamp user created/updated the record for DataQuery Audit
3
+ # Usage: add 'zuora_audit' to your model.rb that you would like to track
4
+
5
+ module ZuoraConnect
6
+ module ZuoraAudit
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ def zuora_audit
11
+ include ZuoraConnect::ZuoraAudit::ZuoraAuditInstanceMethods
12
+ before_create :set_created_by_id
13
+ before_update :set_updated_by_id
14
+ end
15
+ end
16
+
17
+ module ZuoraAuditInstanceMethods
18
+ def set_created_by_id
19
+ self.created_by_id = current_user_id if defined?(self.created_by_id)
20
+ end
21
+
22
+ def set_updated_by_id
23
+ self.updated_by_id = current_user_id if defined?(self.updated_by_id)
24
+ end
25
+
26
+ def current_user_id
27
+ return ZuoraConnect::ZuoraUser.current_user_id
28
+ end
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.60l
4
+ version: 2.0.60q
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -374,6 +374,7 @@ files:
374
374
  - lib/zuora_connect/exceptions.rb
375
375
  - lib/zuora_connect/railtie.rb
376
376
  - lib/zuora_connect/version.rb
377
+ - lib/zuora_connect/zuora_audit.rb
377
378
  - test/controllers/zuora_connect/api/v1/app_instance_controller_test.rb
378
379
  - test/dummy/README.rdoc
379
380
  - test/dummy/Rakefile