zuora_connect 3.1.5.pre.g → 3.2.0

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: bf4d387450ce6927d341515534491f97406c5ae7a083aa95733db6f78259fa0e
4
- data.tar.gz: b65d9eaf5e74d8cc5ad87fa089504f559454a1aa608b941dafecfc6bccd1e71e
3
+ metadata.gz: d04a0fdede87007e236c944ed42bfc822846276fce78a310d22bb89961ed6bee
4
+ data.tar.gz: fe5e370e36988531ff42f08e493a39118a9e0de078e3334df9c1a3c79ad3460f
5
5
  SHA512:
6
- metadata.gz: 4a4992ccb7dc60276ce8723a97d999b6b046eeba6391c1a080ddda8fd01dbf0e8895ce7194334e3532ba49c996b569d61e3c059fc9ac4529494c570185423a08
7
- data.tar.gz: 66d66669ee2189d94c7f548fa5c48ff3a8c8f349655113b808a7676e0b6d5221d482b1d499b3228e9921e75ab1c178061ce66415c74870c57d462feabcfcab89
6
+ metadata.gz: c8836d2516b37c25dce916ed9f976a5bff9456254378301d7a2d5ca457b6d6fc778eb28a7d73d0c16f27f1adc683c12610f8f5b60461a962abae682a7e8d4a7c
7
+ data.tar.gz: e8f4bff78c8fd8160f5a681743cdefe108d0b9a8a3e4e1e6c96fc72b9990e13c27800d91e8dc3b23db008425d23d5d7d3c53f1473300f5d817dda38e48998332
@@ -519,7 +519,7 @@ module ZuoraConnect
519
519
  rescue ArgumentError, OpenSSL::Cipher::CipherError => ex
520
520
  if (
521
521
  ex.is_a?(ArgumentError) && ['invalid base64', 'data must not be empty'].include?(ex.message) ||
522
- ex.is_a?(OpenSSL::Cipher::CipherError) && ['wrong final block length', 'bad decrypt'].include?(ex.message)
522
+ ex.is_a?(OpenSSL::Cipher::CipherError) && ['wrong final block length', 'bad decrypt'].include?(ex.message)
523
523
  ) && encryption_type == :envelope && (kms_tries += 1) < 3
524
524
  ZuoraConnect.logger.warn("Fallback to encryption 'direct', from '#{encryption_type}'", ex, self.default_ougai_items)
525
525
  encryption_type = :direct
@@ -907,12 +907,6 @@ module ZuoraConnect
907
907
 
908
908
  session["#{self.id}::last_refresh"] = self.last_refresh
909
909
  session["appInstance"] = self.id
910
-
911
- unless ZuoraConnect::ZuoraUser.current_org_child_org_ids.nil?
912
- session["zuora_org_id"] = ZuoraConnect::ZuoraUser.current_org_id
913
- session["zuora_org_child_org_ids"] = ZuoraConnect::ZuoraUser.current_org_child_org_ids
914
- end
915
-
916
910
  return session
917
911
  end
918
912
 
@@ -66,39 +66,6 @@ module ZuoraConnect
66
66
  end
67
67
 
68
68
  @zuora_user = ZuoraConnect::ZuoraUser.find_by(zuora_user_id: ZuoraConnect::ZuoraUser.current_user_id)
69
-
70
- zuora_org_id = request.headers["Zuora-Org-Id"]
71
- zuora_return_nested_orgs_data = request.headers['Zuora-Return-Nested-Orgs-Data'].to_bool
72
- ZuoraConnect::ZuoraUser.current_org_id = zuora_org_id
73
- ZuoraConnect::ZuoraUser.current_org_child_org_ids = nil
74
-
75
- if zuora_return_nested_orgs_data
76
- cached_session = @appinstance.data_lookup(session: session)
77
-
78
- if cached_session['zuora_org_id'] == ZuoraConnect::ZuoraUser.current_org_id &&
79
- cached_session.key?('zuora_org_child_org_ids')
80
- ZuoraConnect::ZuoraUser.current_org_child_org_ids = cached_session['zuora_org_child_org_ids']
81
- else
82
- begin
83
- zuora_client = @appinstance.target_login.client
84
- child_org_list, _ =
85
- zuora_client.rest_call(
86
- url: zuora_client.
87
- rest_endpoint("tenant-registry/listChildOrgsForOrg/#{ZuoraConnect::ZuoraUser.current_org_id}").
88
- gsub('v1/', ''),
89
- session_type: zuora_client.is_a?(ZuoraAPI::Oauth) ? :bearer : :basic,
90
- zuora_track_id: ZuoraConnect::RequestIdMiddleware.zuora_request_id
91
- )
92
- rescue ZuoraAPI::Exceptions::ZuoraAPIError => ex
93
- if ex.message.include?('organization does not exist')
94
- raise ZuoraConnect::Exceptions::OrganizationAccessForbidden
95
- else
96
- raise
97
- end
98
- end
99
- ZuoraConnect::ZuoraUser.current_org_child_org_ids = child_org_list.map { |org| org['id'] }
100
- end
101
- end
102
69
  end
103
70
  end
104
71
 
@@ -260,6 +227,39 @@ module ZuoraConnect
260
227
  return (request.headers['ZuoraCurrentEntity'].present? || cookies['ZuoraCurrentEntity'].present?)
261
228
  end
262
229
 
230
+ def org_relation_mapping(root_org_relation)
231
+ relation = {}
232
+
233
+ return relation if root_org_relation.blank?
234
+
235
+ root_org_id = root_org_relation.dig(0, 'rootOrgId')
236
+ relation[root_org_id] = []
237
+
238
+ root_org_relation.each do |child_org|
239
+ relation[child_org['id']] = []
240
+ end
241
+
242
+ root_org_relation.each do |child_org|
243
+ parent_org_id = child_org['parentOrgId']
244
+ relation[parent_org_id].push(child_org['id'])
245
+ end
246
+
247
+ relation
248
+ end
249
+
250
+ def get_child_orgs_from_relation_mapping(relation_mapping, org_id)
251
+ if relation_mapping.blank? || org_id.blank? || relation_mapping[org_id].blank?
252
+ return []
253
+ end
254
+
255
+ child_orgs = relation_mapping[org_id].dup
256
+ relation_mapping[org_id].each do |child_org_id|
257
+ child_orgs += get_child_orgs_from_relation_mapping(relation_mapping, child_org_id)
258
+ end
259
+
260
+ child_orgs
261
+ end
262
+
263
263
  def create_new_instance
264
264
  ZuoraConnect::AppInstance.read_master_db do
265
265
  Thread.current[:appinstance] = nil
@@ -595,35 +595,53 @@ module ZuoraConnect
595
595
  cookies['Zuora-Return-Nested-Orgs-Data'].to_bool ||
596
596
  request.headers['Zuora-Return-Nested-Orgs-Data'].to_bool
597
597
  ZuoraConnect::ZuoraUser.current_org_id = zuora_org_id
598
- ZuoraConnect::ZuoraUser.current_org_child_org_ids = nil
598
+ ZuoraConnect::ZuoraUser.current_org_child_org_ids = []
599
599
 
600
- if zuora_return_nested_orgs_data
601
- cached_session = @appinstance.data_lookup(session: session)
600
+ if zuora_org_id.present? && zuora_return_nested_orgs_data
601
+ cached_org_relationship = Redis.current.get("MultiOrgRelationship:#{@appinstance.id}")
602
602
 
603
- if cached_session['zuora_org_id'] == ZuoraConnect::ZuoraUser.current_org_id &&
604
- cached_session.key?('zuora_org_child_org_ids')
605
- ZuoraConnect::ZuoraUser.current_org_child_org_ids = cached_session['zuora_org_child_org_ids']
603
+ if cached_org_relationship.present?
604
+ cached_org_relationship = JSON.parse(cached_org_relationship)
605
+ ZuoraConnect::ZuoraUser.current_org_child_org_ids =
606
+ get_child_orgs_from_relation_mapping(cached_org_relationship, ZuoraConnect::ZuoraUser.current_org_id)
606
607
  else
607
- begin
608
- child_org_list, _ =
608
+ child_org_list, _ =
609
+ zuora_client.rest_call(
610
+ url: zuora_client.
611
+ rest_endpoint("tenant-registry/listChildOrgsForOrg/#{ZuoraConnect::ZuoraUser.current_org_id}").
612
+ gsub('v1/', ''),
613
+ session_type: zuora_client.is_a?(ZuoraAPI::Oauth) ? :bearer : :basic,
614
+ headers: auth_headers,
615
+ zuora_track_id: ZuoraConnect::RequestIdMiddleware.zuora_request_id
616
+ )
617
+
618
+ root_org_id = (child_org_list || {}).dig(0, 'rootOrgId').to_s
619
+ if root_org_id.present?
620
+ root_child_org_list, _ =
609
621
  zuora_client.rest_call(
610
622
  url: zuora_client.
611
- rest_endpoint("tenant-registry/listChildOrgsForOrg/#{ZuoraConnect::ZuoraUser.current_org_id}").
623
+ rest_endpoint("tenant-registry/listChildOrgsForOrg/#{root_org_id}").
612
624
  gsub('v1/', ''),
613
625
  session_type: zuora_client.is_a?(ZuoraAPI::Oauth) ? :bearer : :basic,
614
626
  headers: auth_headers,
615
627
  zuora_track_id: ZuoraConnect::RequestIdMiddleware.zuora_request_id
616
628
  )
617
- rescue ZuoraAPI::Exceptions::ZuoraAPIError => ex
618
- if ex.message.include?('organization does not exist')
619
- raise ZuoraConnect::Exceptions::OrganizationAccessForbidden
620
- else
621
- raise
622
- end
629
+
630
+ org_relationship = org_relation_mapping(root_child_org_list)
631
+ Redis.current.setex(
632
+ "MultiOrgRelationship:#{@appinstance.id}",
633
+ 1.day,
634
+ org_relationship.to_json
635
+ )
636
+
637
+ ZuoraConnect::ZuoraUser.current_org_child_org_ids =
638
+ get_child_orgs_from_relation_mapping(org_relationship, ZuoraConnect::ZuoraUser.current_org_id)
639
+ else
640
+ ZuoraConnect.logger.info("Failed to get root org id for #{@appinstance.id}")
623
641
  end
624
- ZuoraConnect::ZuoraUser.current_org_child_org_ids = child_org_list.map { |org| org['id'] }
625
642
  end
626
643
  end
644
+
627
645
  rescue ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError => ex
628
646
  output_xml, input_xml, response = zuora_client.soap_call(errors: [], z_session: false, zuora_track_id: ZuoraConnect::RequestIdMiddleware.zuora_request_id) do |xml|
629
647
  xml['api'].getUserInfo
@@ -640,17 +658,6 @@ module ZuoraConnect
640
658
  redirect_to "https://#{zuora_host}/apps/newlogin.do?retURL=#{request.fullpath}&pos=1"
641
659
  return
642
660
 
643
- rescue ZuoraConnect::Exceptions::OrganizationAccessForbidden => ex
644
- locals = {
645
- title: "You cannot operate with the current organization",
646
- message: "Please switch the organization and try again"
647
- }
648
- respond_to do |format|
649
- format.html { render "zuora_connect/static/error_handled", locals: locals, status: 403, layout: false }
650
- format.js { render "zuora_connect/static/error_handled", locals: locals, status: 202, layout: false }
651
- format.json { render json: {'errors' => ex.message}, status: 403 }
652
- format.all { render json: ex.message, status: 403 }
653
- end
654
661
  rescue ZuoraAPI::Exceptions::ZuoraAPIError, Exception => ex
655
662
  if ex.message.include?("Referenced User resource(s) not found") && ex.class == ZuoraAPI::Exceptions::ZuoraAPIError
656
663
  locals = {title: "Provisioning Error", message: "New tenants need to be provisioned by API Gateway('#{ex.message}'). Please contact support."}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZuoraConnect
4
- VERSION = "3.1.5-g"
4
+ VERSION = "3.2.0"
5
5
  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: 3.1.5.pre.g
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-08 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -452,9 +452,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
452
452
  version: '0'
453
453
  required_rubygems_version: !ruby/object:Gem::Requirement
454
454
  requirements:
455
- - - ">"
455
+ - - ">="
456
456
  - !ruby/object:Gem::Version
457
- version: 1.3.1
457
+ version: '0'
458
458
  requirements: []
459
459
  rubygems_version: 3.3.7
460
460
  signing_key: