zuora_connect 2.0.5s → 2.0.5t

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: d5f0aee37797f56d7006e8e7aea1e2a708bff45df18c45b95bfcad5227ca1091
4
- data.tar.gz: 1902e2cd7cd8c6eb00ee1be515135fab5a1fd5f468ca675d9ac3b195bfd9ced7
3
+ metadata.gz: 39768dc5cd2950a55c95e3afea3e72ea1e48c8ee2cf2fc340f7b1b71b5585bc5
4
+ data.tar.gz: d13f2e38f8a27ad0b7233771663c23739d368062395ada699fe9802795f612cc
5
5
  SHA512:
6
- metadata.gz: 2693b9d711f338500ffcfe6379a1e1d5cdf00c621c03d46f43c09f9f99a40967adfc139d7f04335cc93f83b1739049ea960197e1b1a23d35cab14bda57c4be46
7
- data.tar.gz: e6dcabf5cc494d01b0b6bbb38c7ce9cd9ebea97cc5c167b507cd19e3afefc4cfb9bd194e63b6124b955a6cca522528c930b4d0c7e6cce1cb8803e6a50fb85e0c
6
+ metadata.gz: 981fa2396d8f297e8018587f00b084795f477eb9f46303a9a01e7b40d72a8ef81d0b8391b6cae803176b8b60e799f5bc534a643c5a3503b517d9134c08f36b20
7
+ data.tar.gz: 001e7fafa0f8baa245e49ef5325b09b34a2715014fc45bb589429efb77df60d6d5bddec45fc438c200cc1ec6462a062af4ccbf91fd37a7809a1f7b8b8761d5a4
@@ -88,25 +88,25 @@ module ZuoraConnect
88
88
  zuora_entity_id = request.headers['ZuoraCurrentEntity'] || cookies['ZuoraCurrentEntity']
89
89
 
90
90
  if zuora_entity_id.present?
91
-
92
- #Do we need to refresh session identity
93
91
  zuora_host = request.headers["HTTP_X_FORWARDED_HOST"] || "apisandbox.zuora.com"
94
- if request.headers["Zuora-Auth-Token"].present?
95
- zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", bearer_token: request.headers["Zuora-Auth-Token"], oauth_session_expires_at: Time.now + 5.minutes )
96
- elsif cookies['ZSession'].present?
97
- zuora_client = ZuoraAPI::Basic.new(url: "https://#{zuora_host}", session: cookies['ZSession'])
98
- else
99
- render "zuora_connect/static/error_handled", :locals => {
100
- :title => "Missing Authorization Token",
101
- :message => "Zuora 'Zuora-Auth-Token' header and 'ZSession' cookie not present."
102
- }
103
- return
104
- end
105
- zuora_instance_id = params[:sidebar_launch].to_bool ? nil : (params[:app_instance_id] || session["appInstance"])
106
92
 
107
- #Identity blank or current entity different
108
- if (session["ZuoraCurrentIdentity"].blank? || (session["ZuoraCurrentEntity"] != zuora_entity_id) || (session["ZSession"] != cookies['ZSession']))
109
- begin
93
+ begin
94
+ #Do we need to refresh session identity
95
+ if request.headers["Zuora-Auth-Token"].present?
96
+ zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", bearer_token: request.headers["Zuora-Auth-Token"], oauth_session_expires_at: Time.now + 5.minutes )
97
+ elsif cookies['ZSession'].present?
98
+ zuora_client = ZuoraAPI::Basic.new(url: "https://#{zuora_host}", session: cookies['ZSession'])
99
+ else
100
+ render "zuora_connect/static/error_handled", :locals => {
101
+ :title => "Missing Authorization Token",
102
+ :message => "Zuora 'Zuora-Auth-Token' header and 'ZSession' cookie not present."
103
+ }
104
+ return
105
+ end
106
+ zuora_instance_id = params[:sidebar_launch].to_bool ? nil : (params[:app_instance_id] || session["appInstance"])
107
+
108
+ #Identity blank or current entity different
109
+ if (session["ZuoraCurrentIdentity"].blank? || (session["ZuoraCurrentEntity"] != zuora_entity_id) || (session["ZSession"] != cookies['ZSession']))
110
110
  identity, response = zuora_client.rest_call(url: zuora_client.rest_endpoint("identity"))
111
111
  session["ZuoraCurrentIdentity"] = identity
112
112
  session["ZuoraCurrentEntity"] = identity['entityId']
@@ -120,24 +120,14 @@ module ZuoraConnect
120
120
  end
121
121
 
122
122
  raise ZuoraConnect::Exceptions::Error.new("Header entity id, '#{zuora_entity_id}' does not match identity call entity id, '#{identity['entityId']}'.") if zuora_entity_id != identity['entityId']
123
-
124
- rescue ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError => ex
125
- redirect_to "https://#{zuora_host}/apps/newlogin.do?retURL=#{CGI.escape(request.fullpath)}"
126
- return
127
- rescue => ex
128
- ZuoraConnect.logger.error(ex)
129
- render "zuora_connect/static/error_unhandled", :locals => {:exception => ex}
130
- return
131
123
  end
132
- end
133
124
 
134
- #Find matching app instances.
135
- if zuora_instance_id.present?
136
- appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host AND id = :id", entities: [zuora_entity_id], host: zuora_client.rest_domain, id: zuora_instance_id).pluck(:id, :name)
137
- else
138
- #if app_instance_ids is present then permissions still controlled by connect
139
- if params[:app_instance_ids].present?
140
- begin
125
+ #Find matching app instances.
126
+ if zuora_instance_id.present?
127
+ appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host AND id = :id", entities: [zuora_entity_id], host: zuora_client.rest_domain, id: zuora_instance_id).pluck(:id, :name)
128
+ else
129
+ #if app_instance_ids is present then permissions still controlled by connect
130
+ if params[:app_instance_ids].present?
141
131
  navbar, response = zuora_client.rest_call(url: zuora_client.rest_endpoint("navigation"))
142
132
  urls = navbar['menus'].map {|x| x['url']}
143
133
  app_env = ENV["DEIS_APP"] || "xyz123"
@@ -145,48 +135,44 @@ module ZuoraConnect
145
135
  task_ids = JSON.parse(Base64.urlsafe_decode64(CGI.parse(URI.parse(url).query)["app_instance_ids"][0]))
146
136
 
147
137
  appinstances = ZuoraConnect::AppInstance.where(:id => task_ids).pluck(:id, :name)
148
- rescue => ex
149
- ZuoraConnect.logger.error(ex)
150
- render "zuora_connect/static/error_unhandled", :locals => {:exception => ex}
151
- return
138
+ else
139
+ appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
152
140
  end
153
- else
154
- appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
155
141
  end
156
- end
157
142
 
158
- zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId']
143
+ zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId']
159
144
 
160
- #One deployed instance
161
- if appinstances.size == 1
162
- ZuoraConnect.logger.debug("Instance is #{appinstances.to_h.keys.first}")
163
- @appinstance = ZuoraConnect::AppInstance.find(appinstances.to_h.keys.first)
145
+ #One deployed instance
146
+ if appinstances.size == 1
147
+ ZuoraConnect.logger.debug("Instance is #{appinstances.to_h.keys.first}")
148
+ @appinstance = ZuoraConnect::AppInstance.find(appinstances.to_h.keys.first)
164
149
 
165
- #Add user/update
166
- @zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
167
- if @zuora_user.present?
168
- ZuoraConnect.logger.debug("Current zuora user #{zuora_user_id}")
169
- if @zuora_user.updated_at < Time.now - 1.day
170
- @zuora_user.zuora_identity_response[zuora_entity_id] = session["ZuoraCurrentIdentity"]
171
- @zuora_user.save!
172
- end
173
- else
174
- ZuoraConnect.logger.debug("New zuora user object for #{zuora_user_id}")
175
- @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
176
- end
177
- @zuora_user.session = session
178
- session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
179
- session["#{@appinstance.id}::user::timezone"] = session['ZuoraCurrentIdentity']["timeZone"]
180
- session["#{@appinstance.id}::user::locale"] = session['ZuoraCurrentIdentity']["language"]
181
- session["appInstance"] = @appinstance.id
182
-
183
- #We have multiple, user must pick
184
- elsif appinstances.size > 1
185
- ZuoraConnect.logger.debug("User must select instance. #{@names}")
186
- render "zuora_connect/static/launch", :locals => {:names => appinstances.to_h}
187
- return
188
- else
189
- begin
150
+ #Add user/update
151
+ @zuora_user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
152
+ if @zuora_user.present?
153
+ ZuoraConnect.logger.debug("Current zuora user #{zuora_user_id}")
154
+ if @zuora_user.updated_at < Time.now - 1.day
155
+ @zuora_user.zuora_identity_response[zuora_entity_id] = session["ZuoraCurrentIdentity"]
156
+ @zuora_user.save!
157
+ end
158
+ else
159
+ ZuoraConnect.logger.debug("New zuora user object for #{zuora_user_id}")
160
+ @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
161
+ end
162
+ @zuora_user.session = session
163
+ session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
164
+ session["#{@appinstance.id}::user::timezone"] = session['ZuoraCurrentIdentity']["timeZone"]
165
+ session["#{@appinstance.id}::user::locale"] = session['ZuoraCurrentIdentity']["language"]
166
+ session["appInstance"] = @appinstance.id
167
+
168
+ #We have multiple, user must pick
169
+ elsif appinstances.size > 1
170
+ ZuoraConnect.logger.debug("User must select instance. #{@names}")
171
+ render "zuora_connect/static/launch", :locals => {:names => appinstances.to_h}
172
+ return
173
+
174
+ #We have no deployed instance for this tenant
175
+ else
190
176
  #Ensure user can access oauth creation API
191
177
  if session["ZuoraCurrentIdentity"]['platformRole'] != 'ADMIN'
192
178
  Thread.current[:appinstance] = nil
@@ -200,7 +186,7 @@ module ZuoraConnect
200
186
 
201
187
  ActiveRecord::Base.transaction do
202
188
  ActiveRecord::Base.connection.execute('LOCK public.zuora_users IN ACCESS EXCLUSIVE MODE')
203
- sleep(2) #Sleep needed to wait for instance insertion
189
+ sleep(5) #Sleep needed to wait for instance insertion
204
190
  appinstances = ZuoraConnect::AppInstance.where("zuora_entity_ids ?& array[:entities] = true AND zuora_domain = :host", entities: [zuora_entity_id], host: zuora_client.rest_domain).pluck(:id, :name)
205
191
  if appinstances.size > 0
206
192
  ZuoraConnect.logger.warn("Double tenant create for '#{zuora_client.rest_domain}' - '#{zuora_entity_id}' - '#{session["ZuoraCurrentIdentity"]["username"]}'")
@@ -276,12 +262,16 @@ module ZuoraConnect
276
262
  end
277
263
  @appinstance.refresh
278
264
  session["appInstance"] = @appinstance.id
279
-
280
- rescue => ex
281
- ZuoraConnect.logger.error(ex)
282
- render "zuora_connect/static/error_unhandled", :locals => {:exception => ex}
283
- return
284
265
  end
266
+
267
+ rescue ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError => ex
268
+ session.clear
269
+ redirect_to "https://#{zuora_host}/apps/newlogin.do?retURL=#{request.fullpath}"
270
+ return
271
+ rescue => ex
272
+ ZuoraConnect.logger.error(ex)
273
+ render "zuora_connect/static/error_unhandled", :locals => {:exception => ex}
274
+ return
285
275
  end
286
276
  elsif request["data"] && /^([A-Za-z0-9+\/\-\_]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)$/.match(request["data"].to_s)
287
277
  setup_instance_via_data
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.5s"
2
+ VERSION = "2.0.5t"
3
3
  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.5s
4
+ version: 2.0.5t
5
5
  platform: ruby
6
6
  authors:
7
7
  - Connect Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-24 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -44,20 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.6.43
47
+ version: 1.6.48
48
48
  - - "~>"
49
49
  - !ruby/object:Gem::Version
50
- version: 1.6.43
50
+ version: 1.6.48
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: 1.6.43
57
+ version: 1.6.48
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: 1.6.43
60
+ version: 1.6.48
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: httparty
63
63
  requirement: !ruby/object:Gem::Requirement