zuora_connect 2.0.5m → 2.0.5n

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec7aaf21ffc4ce6c8191902f11d033184441e28776d26d6d584c1cb7779e41ee
4
- data.tar.gz: 46c45ce14414834608d1b406652295e0d5414411c06ed5c1d68a64466e5972d7
3
+ metadata.gz: 4fbd8460fb918735b2137693cfbd429c23bda6feb0da4f95282260dc096a2b7e
4
+ data.tar.gz: 78d63c2593390b1e74113f51d634506a6a52df4a327d410a4930d77cc3d0f0d9
5
5
  SHA512:
6
- metadata.gz: ebb686cc5ac165695facfe6da598765a0fc5e5ba06f529c51b3811faa74d8f38eb740c3682746ecf46e86089f9bf7e983762adb551420ee545b7ee93b07b4ca1
7
- data.tar.gz: 77409aaa4fdc0260405997dbd34ffe7aec6b2e643aa7723bd4625b4a9fc415ffb61153bd225bcbe0a557d8fa3a296e641c4044ddb3f1e1cdef6e2f6393454713
6
+ metadata.gz: e5a0b78587de5d76cfa05e9a76ec6a4227d1881148dde1d78890b17428b53d17b2f03da49b5c21956ba4fc9bce96b0d45894fcb5ce35f594a3bfce4f07c5f60d
7
+ data.tar.gz: 74d83f48ec8d18f65601dd63a9dc4514e074b5a6efb16fea26453b1cf45eabf686c3ece124c3259ae0e8c4a822ebb61442db1e7b4844da43dc4a784484bb797d
@@ -196,10 +196,10 @@ module ZuoraConnect
196
196
  self.logitem(item: {tenant_ids: tenants, organization: organizations})
197
197
  params = {
198
198
  :name => self.task_data.dig('name'),
199
- :zuora_domain => self.target_login.client.rest_domain,
200
199
  :zuora_entity_ids => (self.task_data.dig(LOGIN_TENANT_DESTINATION,'entities') || []).map{|e| e['id']},
201
200
  :zuora_tenant_ids => self.task_data.fetch('tenant_ids', []).map(&:to_s),
202
201
  }
202
+ params.merge!({:zuora_domain => self.send(LOGIN_TENANT_DESTINATION).client.rest_domain }))
203
203
  params = params.reject{|k,v| !self.attributes.keys.member?(k.to_s) || self[k] == v}
204
204
  self.update_columns(params) if params.present?
205
205
  end
@@ -196,58 +196,68 @@ module ZuoraConnect
196
196
  }
197
197
  return
198
198
  end
199
-
200
- user = (ENV['DEIS_APP'] || "Application").split('-').map(&:capitalize).join(' ')
201
199
 
202
- body = {
203
- 'userId' => zuora_user_id,
204
- 'entityIds' => [zuora_entity_id.unpack("a8a4a4a4a12").join('-')],
205
- 'customAuthorities' => [],
206
- 'additionalInformation' => {
207
- 'description' => "This user is for #{user} application.",
208
- 'name' => "#{user} API User"
200
+ ActiveRecord::Base.transaction do
201
+ ActiveRecord::Base.connection.execute('LOCK public.zuora_users IN ACCESS EXCLUSIVE MODE')
202
+
203
+ 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)
204
+ if appinstances.size > 0
205
+ ZuoraConnect.logger.warn("Double tenant create for '#{zuora_client.rest_domain}' - 'zuora_entity_id'")
206
+ redirect_to "https://#{zuora_host}/apps/newlogin.do?retURL=#{CGI.escape(request.fullpath)}"
207
+ return
208
+ end
209
+
210
+ user = (ENV['DEIS_APP'] || "Application").split('-').map(&:capitalize).join(' ')
211
+ body = {
212
+ 'userId' => zuora_user_id,
213
+ 'entityIds' => [zuora_entity_id.unpack("a8a4a4a4a12").join('-')],
214
+ 'customAuthorities' => [],
215
+ 'additionalInformation' => {
216
+ 'description' => "This user is for #{user} application.",
217
+ 'name' => "#{user} API User"
218
+ }
209
219
  }
210
- }
211
-
212
- oauth_response, response = zuora_client.rest_call(method: :post, body: body.to_json, url: zuora_client.rest_endpoint("genesis/clients").gsub('v1/', ''), session_type: zuora_client.class == ZuoraAPI::Oauth ? :bearer : :basic, headers: zuora_client.class == ZuoraAPI::Oauth ? {} : {'Authorization' => "ZSession-a3N2w #{zuora_client.get_session(prefix: false, auth_type: :basic)}"})
213
220
 
214
- new_zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", oauth_client_id: oauth_response["clientId"], oauth_secret: oauth_response["clientSecret"] )
215
- if session["ZuoraCurrentUserInfo"].blank?
216
- client_describe, response = new_zuora_client.rest_call(url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''), session_type: :bearer)
217
- else
218
- client_describe = session["ZuoraCurrentUserInfo"]
219
- end
221
+ oauth_response, response = zuora_client.rest_call(method: :post, body: body.to_json, url: zuora_client.rest_endpoint("genesis/clients").gsub('v1/', ''), session_type: zuora_client.class == ZuoraAPI::Oauth ? :bearer : :basic, headers: zuora_client.class == ZuoraAPI::Oauth ? {} : {'Authorization' => "ZSession-a3N2w #{zuora_client.get_session(prefix: false, auth_type: :basic)}"})
222
+
223
+ new_zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", oauth_client_id: oauth_response["clientId"], oauth_secret: oauth_response["clientSecret"] )
224
+ if session["ZuoraCurrentUserInfo"].blank?
225
+ client_describe, response = new_zuora_client.rest_call(url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''), session_type: :bearer)
226
+ else
227
+ client_describe = session["ZuoraCurrentUserInfo"]
228
+ end
229
+
230
+ Apartment::Tenant.switch!("public")
231
+ next_id = (ZuoraConnect::AppInstance.all.where(:access_token => nil).order(id: :desc).limit(1).pluck(:id).first || 24999999) + 1
232
+ begin
233
+ Apartment::Tenant.create(next_id.to_s)
234
+ rescue Apartment::TenantExists => ex
235
+ ZuoraConnect.logger.debug("Tenant Already Exists")
236
+ end
237
+ available_entities = client_describe["accessibleEntities"].select {|entity| entity['id'] == client_describe['defaultEntityId']}
238
+ task_data = {
239
+ "id": next_id,
240
+ "name": client_describe["tenantName"],
241
+ "mode": "Collections",
242
+ "status": "Running",
243
+ ZuoraConnect::AppInstance::LOGIN_TENANT_DESTINATION => {
244
+ "tenant_type": "Zuora",
245
+ "username": session["ZuoraCurrentIdentity"]["username"],
246
+ "url": new_zuora_client.url,
247
+ "status": "Active",
248
+ "oauth_client_id": oauth_response['clientId'],
249
+ "oauth_secret": oauth_response['clientSecret'],
250
+ "authentication_type": "OAUTH",
251
+ "entities": available_entities.map {|e| e.merge({'displayName' => client_describe["tenantName"]})}
252
+ },
253
+ "tenant_ids": available_entities.map{|e| e['entityId'] }.push(client_describe["tenantId"]).uniq,
254
+ }
220
255
 
221
- Apartment::Tenant.switch!("public")
222
- next_id = (ZuoraConnect::AppInstance.all.where(:access_token => nil).order(id: :desc).limit(1).pluck(:id).first || 24999999) + 1
223
- begin
224
- Apartment::Tenant.create(next_id.to_s)
225
- rescue Apartment::TenantExists => ex
226
- ZuoraConnect.logger.debug("Tenant Already Exists")
256
+ @appinstance = ZuoraConnect::AppInstance.new(:id => next_id, :zuora_logins => task_data, :oauth_expires_at => Time.now + 1000.years)
257
+ @appinstance.save(:validate => false)
258
+ @appinstance.refresh
259
+ session["appInstance"] = @appinstance.id
227
260
  end
228
- available_entities = client_describe["accessibleEntities"].select {|entity| entity['id'] == client_describe['defaultEntityId']}
229
- task_data = {
230
- "id": next_id,
231
- "name": client_describe["tenantName"],
232
- "mode": "Collections",
233
- "status": "Running",
234
- ZuoraConnect::AppInstance::LOGIN_TENANT_DESTINATION => {
235
- "tenant_type": "Zuora",
236
- "username": session["ZuoraCurrentIdentity"]["username"],
237
- "url": new_zuora_client.url,
238
- "status": "Active",
239
- "oauth_client_id": oauth_response['clientId'],
240
- "oauth_secret": oauth_response['clientSecret'],
241
- "authentication_type": "OAUTH",
242
- "entities": available_entities.map {|e| e.merge({'displayName' => client_describe["tenantName"]})}
243
- },
244
- "tenant_ids": available_entities.map{|e| e['entityId'] }.push(client_describe["tenantId"]).uniq,
245
- }
246
-
247
- @appinstance = ZuoraConnect::AppInstance.new(:id => next_id, :zuora_logins => task_data, :oauth_expires_at => Time.now + 1000.years)
248
- @appinstance.save(:validate => false)
249
- @appinstance.refresh
250
- session["appInstance"] = @appinstance.id
251
261
  rescue => ex
252
262
  ZuoraConnect.logger.error(ex)
253
263
  render "zuora_connect/static/error_unhandled", :locals => {:exception => ex}
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.5m"
2
+ VERSION = "2.0.5n"
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.5m
4
+ version: 2.0.5n
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-12 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment