zuora_connect 2.0.4 → 2.0.5a
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daee0106cd93ca1eca1bfa9a6b1a469b43c77c86a036af8044c23686f65ab5d5
|
4
|
+
data.tar.gz: ce11751c99ea5023ccd64eed8f8aaa4ae796b2a1347c0e6b3e321b62008d51ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bab8cd6389935c844276c90787acde6ac8cef9cf9c85d4a6ee9ad1ea2fd9755e3140d3d53f4b6843cfc0f94d2516fe994faf64e547195607b2e2836a51d46bf
|
7
|
+
data.tar.gz: a992917b603be6db6e6af1f3a429b9197b89cc4be7cc17cf68a6e95bc42d88d736bffb017407fc83e2fd98a255ffabcaf206a892f8fe9d13575b1b8c001ff0ef
|
@@ -66,13 +66,8 @@
|
|
66
66
|
<body style='background: white;'>
|
67
67
|
<div class="dialog">
|
68
68
|
<div>
|
69
|
-
<h1>
|
70
|
-
<p style='text-align:left'>Please contact
|
71
|
-
<ul style='text-align:left'>
|
72
|
-
<% admins.each do |admin| %>
|
73
|
-
<li><%= admin.username %></li>
|
74
|
-
<% end %>
|
75
|
-
</ul>
|
69
|
+
<h1>Application can only complete its initial setup via platform administrator.</h1>
|
70
|
+
<p style='text-align:left'>Please contact admin of tenant and have them click on link again to launch application.</p>
|
76
71
|
</div>
|
77
72
|
</div>
|
78
73
|
|
@@ -62,168 +62,170 @@ module ZuoraConnect
|
|
62
62
|
def authenticate_connect_app_request
|
63
63
|
ElasticAPM.set_tag(:trace_id, request.uuid) if defined?(ElasticAPM) && ElasticAPM.running?
|
64
64
|
Thread.current[:appinstance] = nil
|
65
|
+
start_time = Time.now
|
66
|
+
if ZuoraConnect.configuration.mode == "Production"
|
67
|
+
if request.headers['ZuoraCurrentEntity'].present?
|
65
68
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
else
|
75
|
-
raise ZuoraConnect::Exceptions::Error.new("Neither the ZSession cookie nor the Zuora-Auth-Token are present in payload.")
|
76
|
-
end
|
77
|
-
zuora_entity_id = request.headers['ZuoraCurrentEntity']
|
78
|
-
zuora_instance_id = params[:sidebar_launch].to_bool ? nil : (params[:app_instance_id] || session["appInstance"])
|
79
|
-
|
80
|
-
#Identity blank or current entity different
|
81
|
-
if (session["ZuoraCurrentIdentity"].blank? || session["ZuoraCurrentEntity"] != zuora_entity_id)
|
82
|
-
begin
|
83
|
-
identity, response = zuora_client.rest_call(url: zuora_client.rest_endpoint("identity"))
|
84
|
-
session["ZuoraCurrentIdentity"] = identity
|
85
|
-
session["ZuoraCurrentEntity"] = identity['entityId']
|
86
|
-
|
87
|
-
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']
|
88
|
-
rescue => ex
|
89
|
-
ZuoraConnect.logger.error(ex)
|
90
|
-
render "zuora_connect/static/invalid_launch_request", :locals => {:exception => ex}
|
91
|
-
return
|
69
|
+
#Do we need to refresh session identity
|
70
|
+
zuora_host = request.headers["HTTP_X_FORWARDED_HOST"] || "apisandbox.zuora.com"
|
71
|
+
if request.headers["Zuora-Auth-Token"].present?
|
72
|
+
zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", bearer_token: request.headers["Zuora-Auth-Token"], oauth_session_expires_at: Time.now + 5.minutes )
|
73
|
+
elsif cookies['ZSession'].present?
|
74
|
+
zuora_client = ZuoraAPI::Basic.new(url: "https://#{zuora_host}", session: cookies['ZSession'])
|
75
|
+
else
|
76
|
+
raise ZuoraConnect::Exceptions::Error.new("Neither the ZSession cookie nor the Zuora-Auth-Token are present in payload.")
|
92
77
|
end
|
93
|
-
|
78
|
+
zuora_entity_id = request.headers['ZuoraCurrentEntity']
|
79
|
+
zuora_instance_id = params[:sidebar_launch].to_bool ? nil : (params[:app_instance_id] || session["appInstance"])
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
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)
|
98
|
-
else
|
99
|
-
#if app_instance_ids is present then permissions still controlled by connect
|
100
|
-
if params[:app_instance_ids].present?
|
81
|
+
#Identity blank or current entity different
|
82
|
+
if (session["ZuoraCurrentIdentity"].blank? || session["ZuoraCurrentEntity"] != zuora_entity_id)
|
101
83
|
begin
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
84
|
+
identity, response = zuora_client.rest_call(url: zuora_client.rest_endpoint("identity"))
|
85
|
+
session["ZuoraCurrentIdentity"] = identity
|
86
|
+
session["ZuoraCurrentEntity"] = identity['entityId']
|
87
|
+
|
88
|
+
begin
|
89
|
+
client_describe, response = new_zuora_client.rest_call(url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''))
|
90
|
+
session["ZuoraCurrentUserInfo"] = client_describe
|
91
|
+
rescue => ex
|
92
|
+
ZuoraConnect.logger.error(ex)
|
93
|
+
end
|
94
|
+
|
95
|
+
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']
|
109
96
|
rescue => ex
|
110
97
|
ZuoraConnect.logger.error(ex)
|
111
98
|
render "zuora_connect/static/invalid_launch_request", :locals => {:exception => ex}
|
112
|
-
return
|
99
|
+
return
|
113
100
|
end
|
101
|
+
end
|
102
|
+
|
103
|
+
#Find matching app instances.
|
104
|
+
if zuora_instance_id.present?
|
105
|
+
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)
|
114
106
|
else
|
115
|
-
|
107
|
+
#if app_instance_ids is present then permissions still controlled by connect
|
108
|
+
if params[:app_instance_ids].present?
|
109
|
+
begin
|
110
|
+
navbar, response = zuora_client.rest_call(url: zuora_client.rest_endpoint("navigation"))
|
111
|
+
urls = navbar['menus'].map {|x| x['url']}
|
112
|
+
app_env = ENV["DEIS_APP"] || "xyz123"
|
113
|
+
url = urls.compact.select {|url| File.basename(url).start_with?(app_env + '?')}.first
|
114
|
+
task_ids = JSON.parse(Base64.urlsafe_decode64(CGI.parse(URI.parse(url).query)["app_instance_ids"][0]))
|
115
|
+
|
116
|
+
appinstances = ZuoraConnect::AppInstance.where(:id => task_ids).pluck(:id, :name)
|
117
|
+
rescue => ex
|
118
|
+
ZuoraConnect.logger.error(ex)
|
119
|
+
render "zuora_connect/static/invalid_launch_request", :locals => {:exception => ex}
|
120
|
+
return
|
121
|
+
end
|
122
|
+
else
|
123
|
+
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)
|
124
|
+
end
|
116
125
|
end
|
117
|
-
end
|
118
126
|
|
119
|
-
|
127
|
+
zuora_user_id = cookies['Zuora-User-Id'] || session["ZuoraCurrentIdentity"]['userId']
|
120
128
|
|
121
|
-
|
122
|
-
|
123
|
-
|
129
|
+
#One deployed instance
|
130
|
+
if appinstances.size == 10
|
131
|
+
ZuoraConnect.logger.debug("Instance is #{appinstances.to_h.keys.first}")
|
132
|
+
@appinstance = ZuoraConnect::AppInstance.find(appinstances.to_h.keys.first)
|
124
133
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@user.app_permissions['access'] = true
|
140
|
-
@user.save!
|
141
|
-
end
|
134
|
+
#Add user/update
|
135
|
+
@user = ZuoraConnect::ZuoraUser.where(:zuora_user_id => zuora_user_id).first
|
136
|
+
if @user.present?
|
137
|
+
ZuoraConnect.logger.debug("Current zuora user #{zuora_user_id}")
|
138
|
+
if @user.updated_at < Time.now - 1.day
|
139
|
+
@user.zuora_identity_response[zuora_entity_id] = session["ZuoraCurrentIdentity"]
|
140
|
+
@user.save!
|
141
|
+
end
|
142
|
+
else
|
143
|
+
ZuoraConnect.logger.debug("New zuora user object for #{zuora_user_id}")
|
144
|
+
@user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
|
145
|
+
end
|
146
|
+
@user.session = session
|
147
|
+
session["appInstance"] = @appinstance.id
|
142
148
|
|
143
|
-
#
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
Thread.current[:appinstance] = nil
|
148
|
-
session["appInstance"] = nil
|
149
|
-
admin_users = ZuoraConnect::ZuoraUser.select("zuora_identity_response #>> '{#{zuora_entity_id},username}' as username").where("zuora_identity_response #>> :selector = 'ADMIN' ", :selector => "{#{zuora_entity_id},platformRole}")
|
150
|
-
render "zuora_connect/static/permission_error", :locals => {:admins => admin_users}
|
149
|
+
#We have multiple, user must pick
|
150
|
+
elsif appinstances.size > 1
|
151
|
+
ZuoraConnect.logger.debug("User must select instance. #{@names}")
|
152
|
+
render "zuora_connect/static/launch", :locals => {:names => appinstances.to_h}
|
151
153
|
return
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
'description' => 'This user is for workflow application.',
|
171
|
-
'name' => 'Workflow API User'
|
154
|
+
else
|
155
|
+
begin
|
156
|
+
#Ensure user can access oauth creation API
|
157
|
+
if session["ZuoraCurrentIdentity"]['platformRole'] != 'ADMIN' || true
|
158
|
+
Thread.current[:appinstance] = nil
|
159
|
+
session["appInstance"] = nil
|
160
|
+
render "zuora_connect/static/cant_deploy"
|
161
|
+
return
|
162
|
+
end
|
163
|
+
|
164
|
+
body = {
|
165
|
+
'userId' => zuora_user_id,
|
166
|
+
'entityIds' => [zuora_entity_id.unpack("a8a4a4a4a12").join('-')],
|
167
|
+
'customAuthorities' => [],
|
168
|
+
'additionalInformation' => {
|
169
|
+
'description' => 'This user is for workflow application.',
|
170
|
+
'name' => 'Workflow API User'
|
171
|
+
}
|
172
172
|
}
|
173
|
-
}
|
174
173
|
|
175
|
-
|
174
|
+
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)}"})
|
176
175
|
|
177
|
-
|
178
|
-
|
179
|
-
|
176
|
+
new_zuora_client = ZuoraAPI::Oauth.new(url: "https://#{zuora_host}", oauth_client_id: oauth_response["clientId"], oauth_secret: oauth_response["clientSecret"] )
|
177
|
+
if session["ZuoraCurrentUserInfo"].blank?
|
178
|
+
client_describe, response = new_zuora_client.rest_call(url: zuora_client.rest_endpoint("genesis/user/info").gsub('v1/', ''), session_type: :bearer)
|
179
|
+
else
|
180
|
+
client_describe = session["ZuoraCurrentUserInfo"]
|
181
|
+
end
|
180
182
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
183
|
+
Apartment::Tenant.switch!("public")
|
184
|
+
next_id = (ZuoraConnect::AppInstance.all.where(:access_token => nil).order(id: :desc).limit(1).pluck(:id).first || 24999999) + 1
|
185
|
+
begin
|
186
|
+
Apartment::Tenant.create(next_id.to_s)
|
187
|
+
rescue Apartment::TenantExists => ex
|
188
|
+
ZuoraConnect.logger.debug("Tenant Already Exists")
|
189
|
+
end
|
188
190
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
191
|
+
task_data = {
|
192
|
+
"id": next_id,
|
193
|
+
"name": client_describe["tenantName"],
|
194
|
+
"mode": "Collections",
|
195
|
+
"status": "Running",
|
196
|
+
"target_login": {
|
197
|
+
"tenant_type": "Zuora",
|
198
|
+
"username": session["ZuoraCurrentIdentity"]["username"],
|
199
|
+
"url": new_zuora_client.url,
|
200
|
+
"status": "Active",
|
201
|
+
"oauth_client_id": oauth_response['clientId'],
|
202
|
+
"oauth_secret": oauth_response['clientSecret'],
|
203
|
+
"authentication_type": "OAUTH",
|
204
|
+
"entities": client_describe["accessibleEntities"].map {|e| e.merge({'displayName' => client_describe["tenantName"]})} #needs work
|
205
|
+
},
|
206
|
+
"tenant_ids": client_describe["accessibleEntities"].map{|e| e['entityId'] }.push(client_describe["tenantId"]).uniq,
|
207
|
+
}
|
206
208
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
209
|
+
@appinstance = ZuoraConnect::AppInstance.new(:id => next_id, :zuora_logins => task_data.to_json, :oauth_expires_at => Time.now + 1000.years)
|
210
|
+
@appinstance.save(:validate => false)
|
211
|
+
# @appinstance = ZuoraConnect::AppInstance.find(appinstance.id)
|
212
|
+
# @appinstance.apartment_switch(method = nil, migrate = true)
|
211
213
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
214
|
+
session["appInstance"] = @appinstance.id
|
215
|
+
rescue => ex
|
216
|
+
ZuoraConnect.logger.error(ex)
|
217
|
+
render "zuora_connect/static/invalid_launch_request", :locals => {:exception => ex}
|
218
|
+
return
|
219
|
+
end
|
217
220
|
end
|
218
|
-
|
219
|
-
end
|
220
|
-
|
221
|
-
start_time = Time.now
|
222
|
-
if ZuoraConnect.configuration.mode == "Production"
|
223
|
-
if 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)
|
221
|
+
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)
|
224
222
|
setup_instance_via_data
|
225
223
|
else
|
226
|
-
|
224
|
+
if session["appInstance"].present?
|
225
|
+
@appinstance = ZuoraConnect::AppInstance.where(:id => session["appInstance"]).first
|
226
|
+
else
|
227
|
+
raise ZuoraConnect::Exceptions::SessionInvalid.new("Session Blank -- Relaunch Application")
|
228
|
+
end
|
227
229
|
end
|
228
230
|
else
|
229
231
|
setup_instance_via_dev_mode
|
@@ -309,14 +311,6 @@ module ZuoraConnect
|
|
309
311
|
end
|
310
312
|
end
|
311
313
|
|
312
|
-
def setup_instance_via_session
|
313
|
-
if session["appInstance"].present?
|
314
|
-
@appinstance = ZuoraConnect::AppInstance.where(:id => session["appInstance"]).first
|
315
|
-
else
|
316
|
-
raise ZuoraConnect::Exceptions::SessionInvalid.new("Session Blank -- Relaunch Application")
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
314
|
def setup_instance_via_dev_mode
|
321
315
|
session["appInstance"] = ZuoraConnect.configuration.dev_mode_appinstance
|
322
316
|
user = ZuoraConnect.configuration.dev_mode_user
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuora_connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5a
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connect Team
|
@@ -308,10 +308,10 @@ files:
|
|
308
308
|
- app/models/zuora_connect/zuora_user.rb
|
309
309
|
- app/views/layouts/zuora_connect/application.html.erb
|
310
310
|
- app/views/sql/refresh_aggregate_table.txt
|
311
|
+
- app/views/zuora_connect/static/cant_deploy.html.erb
|
311
312
|
- app/views/zuora_connect/static/invalid_app_instance_error.html.erb
|
312
313
|
- app/views/zuora_connect/static/invalid_launch_request.html.erb
|
313
314
|
- app/views/zuora_connect/static/launch.html.erb
|
314
|
-
- app/views/zuora_connect/static/permission_error.html.erb
|
315
315
|
- app/views/zuora_connect/static/session_error.html.erb
|
316
316
|
- config/initializers/apartment.rb
|
317
317
|
- config/initializers/aws.rb
|
@@ -409,9 +409,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
409
409
|
version: '0'
|
410
410
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
411
411
|
requirements:
|
412
|
-
- - "
|
412
|
+
- - ">"
|
413
413
|
- !ruby/object:Gem::Version
|
414
|
-
version:
|
414
|
+
version: 1.3.1
|
415
415
|
requirements: []
|
416
416
|
rubygems_version: 3.0.3
|
417
417
|
signing_key:
|