zuora_connect 2.0.60t → 2.0.60u

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: d7eee2d7cabce6128892afac88428f3c7f77a3318e244bd3becdf521716d0a25
4
- data.tar.gz: 12c07009df449c54d70bec094e16594f0a3ecdb251c59ffed230d64787939cfb
3
+ metadata.gz: 92a983cff8e7ff831929da9496cbb34e728f2033e79135c8bb76fa604bd33e71
4
+ data.tar.gz: 67170a20afb4fee284cc402484e5770b47422ebbeb7652dca39ceab862ca4d20
5
5
  SHA512:
6
- metadata.gz: a45196b2a77449c349e1e1fe4b9853d08e35da763327e2f74134cee20f4ee4af9311a4298b048b937d1d4f5056e047f0db503f57b3b36f2335a963fe4e1f3336
7
- data.tar.gz: d3d14ec18ce3da9ad27776cf2c79ed3b7f9aafa88c331f3a0efa9a2075258cf438e3dd469c50ba1e4d0e46d339ec0ba895632535ab9644dd8cf4a29513d77f7d
6
+ metadata.gz: cb814342311b45d90903a72fff8d7bb9d313b91fb89346e99039276af4aae03ed538841215c9737ebc237d80a3584f3955c6e30e48a8e0c322ba7c7fd145ad78
7
+ data.tar.gz: 8f3d002f881cc6403baaae4f00bb88c8fff0f063c4a6290f4ad2c02c49361afe037717c6a55823a1834a9b29e3f16f11b2339211b992f83c42042133ebe33c55
@@ -25,6 +25,8 @@ module ZuoraConnect
25
25
  CATALOG_LOOKUP_CACHE_TIME_KEY = 'CatalogCachedAt'
26
26
  CATALOG_LOOKUP_TTL = 60.seconds
27
27
  CATALOG_LOOKUP_CACHE_RESULT_KEY = 'CatalogCache'
28
+ TIMEZONE_LOG_RATE_LIMIT_KEY = 'TimezoneLoggedAt'
29
+ TIMEZONE_LOG_PERIOD = 4.hours
28
30
  IGNORED_LOCALS = ['fr', 'ja', 'es', 'zh', 'de']
29
31
  INTERNAL_HOSTS = []
30
32
  LOGIN_TENANT_DESTINATION = 'target_login'
@@ -245,48 +247,7 @@ module ZuoraConnect
245
247
  ZuoraConnect.logger.error(ex) if !IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
246
248
  end
247
249
 
248
- begin
249
- sql = <<-eos
250
- SELECT zuora_users.zuora_identity_response
251
- FROM "#{self.id}".zuora_users
252
- ORDER BY zuora_users.updated_at DESC
253
- LIMIT 1;
254
- eos
255
- user = ActiveRecord::Base.connection.execute(sql).to_a.first
256
-
257
- if user.present?
258
- zuora_identity_response = JSON.parse(user.fetch('zuora_identity_response', '{}'))
259
- self.user_timezone = zuora_identity_response.values.first&.dig('timeZone')
260
- end
261
- rescue => ex
262
- Rails.logger.error('Failed to get users while setting app instance timezone', ex)
263
- end
264
-
265
- if self.user_timezone.present?
266
- # connect instance which has a custom timezone
267
- if !self.auto_deployed? && (
268
- ActiveSupport::TimeZone[self.task_data.dig('user_settings', 'timezone') || '']&.utc_offset !=
269
- ActiveSupport::TimeZone[self.user_timezone]&.utc_offset
270
- )
271
- if self.environment == 'Production'
272
- ZuoraConnect.logger.error(
273
- "Instance and user timezones are different. User has '#{self.user_timezone}' and " \
274
- "instance has '#{self.task_data.dig('user_settings', 'timezone')}'",
275
- app_instance_id: self.id
276
- )
277
- end
278
- self.user_timezone = nil
279
- Time.zone = self.timezone
280
- else
281
- begin
282
- Time.zone = self.user_timezone
283
- rescue ArgumentError
284
- Time.zone = self.timezone
285
- end
286
- end
287
- else
288
- Time.zone = self.timezone
289
- end
250
+ self.set_timezone
290
251
 
291
252
  if self.task_data.present?
292
253
  tenants = self.task_data.fetch('tenant_ids', [])
@@ -319,6 +280,67 @@ module ZuoraConnect
319
280
  end
320
281
  end
321
282
 
283
+ def set_timezone(timezone: self.timezone, type: :default)
284
+ if timezone.blank?
285
+ timezone = self.timezone
286
+ end
287
+
288
+ if type == :default
289
+ Time.zone = timezone
290
+ elsif type == :user
291
+ begin
292
+ sql = <<-eos
293
+ SELECT zuora_users.zuora_identity_response
294
+ FROM "#{self.id}".zuora_users
295
+ ORDER BY zuora_users.updated_at DESC
296
+ LIMIT 1;
297
+ eos
298
+ user = ActiveRecord::Base.connection.execute(sql).to_a.first
299
+
300
+ if user.present?
301
+ zuora_identity_response = JSON.parse(user.fetch('zuora_identity_response', '{}'))
302
+ self.user_timezone = zuora_identity_response.values.first&.dig('timeZone')
303
+ else
304
+ Rails.logger.error('Cannot find any user to set the timezone', app_instance_id: self.id)
305
+ end
306
+ rescue => ex
307
+ Rails.logger.error('There is an error while getting timezone users', ex)
308
+ end
309
+
310
+ if self.user_timezone.present?
311
+ # connect instance which has a custom timezone
312
+ if !self.auto_deployed? && (
313
+ ActiveSupport::TimeZone[self.task_data.dig('user_settings', 'timezone') || '']&.utc_offset !=
314
+ ActiveSupport::TimeZone[self.user_timezone]&.utc_offset
315
+ )
316
+ if self.environment == 'Production' &&
317
+ (Redis.current.hget(TIMEZONE_LOG_RATE_LIMIT_KEY, self.id).to_i + TIMEZONE_LOG_PERIOD.to_i) <= Time.now.to_i
318
+ ZuoraConnect.logger.error(
319
+ "Instance and user timezones are different. User has '#{self.user_timezone}' and " \
320
+ "instance has '#{self.task_data.dig('user_settings', 'timezone')}'",
321
+ app_instance_id: self.id
322
+ )
323
+ Redis.current.hset(TIMEZONE_LOG_RATE_LIMIT_KEY, self.id, Time.now.to_i)
324
+ end
325
+ self.user_timezone = nil
326
+ Time.zone = timezone
327
+ else
328
+ begin
329
+ Time.zone = self.user_timezone
330
+ rescue ArgumentError
331
+ Rails.logger.error('Malformed user timezone', app_instance_id: self.id)
332
+ Time.zone = timezone
333
+ end
334
+ end
335
+ else
336
+ Time.zone = timezone
337
+ end
338
+ end
339
+ rescue => e
340
+ Rails.logger.error('Malformed timezone used', e, app_instance_id: self.id)
341
+ Time.zone = self.timezone
342
+ end
343
+
322
344
  def auto_deployed?
323
345
  self.id >= 25000000
324
346
  end
@@ -138,12 +138,8 @@ module ZuoraConnect
138
138
  end
139
139
  ZuoraConnect.logger.error(ex) if !ZuoraConnect::AppInstance::IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
140
140
  end
141
- begin
142
- if @appinstance.user_timezone.blank?
143
- Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
144
- end
145
- rescue
146
- ZuoraConnect.logger.error(ex)
141
+ if @appinstance.user_timezone.blank?
142
+ @appinstance.set_timezone(timezone: session["#{@appinstance.id}::user::timezone"], type: :default)
147
143
  end
148
144
  end
149
145
  rescue ZuoraConnect::Exceptions::InvalidCredentialSet => ex
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.60t"
2
+ VERSION = "2.0.60u"
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.60t
4
+ version: 2.0.60u
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-16 00:00:00.000000000 Z
11
+ date: 2020-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment