zuora_connect 2.0.60i → 2.0.60n

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: 1fc4afe6a78f90d6c87cfa73da32a7b129a5e584672886cad408368694aad1aa
4
- data.tar.gz: bdfcffca2d8ec4eb224408b25c6b14248bde1623265cca5be7a6e46ea2c63931
3
+ metadata.gz: 97f4f62548850bb29aa5afe9dabfd967279d0900771599bac82cc67ea44b73f2
4
+ data.tar.gz: cebd295e51df06156e5e054e15c681b83cdec69d39a42dfd267fcd2d6f094f42
5
5
  SHA512:
6
- metadata.gz: 45fbd12da62db03d87bfb2879efe01a531bb23560785145d296b68e5d06d97dbd31d6e382f2c7f53d48267a91bbaf64ca907c10d0d009c1e21bd1b13ca442acc
7
- data.tar.gz: 433893af604861265c826253fb5d40236f1662ef78506bac6c87d82c315552a42297668f393c73b32e7bcdb8ce501a33ae0fc0b48dd9dff95fb43ad61c16fde2
6
+ metadata.gz: a77a8dacf8c09f5dd3aec37fe1cbb597574588e44ead312d3af0d42d2f80c59ee3fd4d123aeca5d5c60d5faf73d9d5dbe57575d2c83aa37b58f303efc6b502ca
7
+ data.tar.gz: 49123c079c3561c3a406358192c9289dbe438d4f9b4687c8686a92b10d828825d47dfbe939f0c84eab89e15ee2662ecea5b0c4b47af08326897e7f2bcfb30887
@@ -11,7 +11,7 @@ module ZuoraConnect
11
11
  before_destroy :prune_data
12
12
 
13
13
  self.table_name = "zuora_connect_app_instances"
14
- attr_accessor :options, :mode, :logins, :task_data, :last_refresh, :username, :password, :s3_client, :api_version, :drop_message, :new_session_message, :connect_user, :logitems
14
+ attr_accessor :options, :mode, :logins, :task_data, :last_refresh, :username, :password, :s3_client, :api_version, :drop_message, :new_session_message, :connect_user, :logitems, :user_timezone
15
15
  @@telegraf_host = nil
16
16
  REFRESH_TIMEOUT = 2.minute #Used to determine how long to wait on current refresh call before executing another
17
17
  INSTANCE_REFRESH_WINDOW = 1.hours #Used to set how how long till app starts attempting to refresh cached task connect data
@@ -240,7 +240,50 @@ module ZuoraConnect
240
240
  rescue I18n::InvalidLocale => ex
241
241
  ZuoraConnect.logger.error(ex) if !IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
242
242
  end
243
- Time.zone = self.timezone
243
+
244
+ begin
245
+ sql = <<-eos
246
+ SELECT zuora_users.zuora_identity_response
247
+ FROM "#{self.id}".zuora_users
248
+ ORDER BY zuora_users.updated_at DESC
249
+ LIMIT 1;
250
+ eos
251
+ user = ActiveRecord::Base.connection.execute(sql).to_a.first
252
+
253
+ if user.present?
254
+ zuora_identity_response = JSON.parse(user.fetch('zuora_identity_response', '{}'))
255
+ self.user_timezone = zuora_identity_response.values.first&.dig('timeZone')
256
+ end
257
+ rescue => ex
258
+ Rails.logger.error('Failed to get users while setting app instance timezone', ex)
259
+ end
260
+
261
+ if self.user_timezone.present?
262
+ # connect instance which has a custom timezone
263
+ if !self.auto_deployed? && (
264
+ ActiveSupport::TimeZone[self.task_data.dig('user_settings', 'timezone') || '']&.utc_offset !=
265
+ ActiveSupport::TimeZone[self.user_timezone]&.utc_offset
266
+ )
267
+ if self.environment == 'Production'
268
+ ZuoraConnect.logger.error(
269
+ "Instance and user timezones are different. User has '#{self.user_timezone}' and " \
270
+ "instance has '#{self.task_data.dig('user_settings', 'timezone')}'",
271
+ app_instance_id: self.id
272
+ )
273
+ end
274
+ self.user_timezone = nil
275
+ Time.zone = self.timezone
276
+ else
277
+ begin
278
+ Time.zone = self.user_timezone
279
+ rescue ArgumentError
280
+ Time.zone = self.timezone
281
+ end
282
+ end
283
+ else
284
+ Time.zone = self.timezone
285
+ end
286
+
244
287
  if self.task_data.present?
245
288
  tenants = self.task_data.fetch('tenant_ids', [])
246
289
  organizations = self.task_data.fetch('organizations', [])
@@ -272,6 +315,10 @@ module ZuoraConnect
272
315
  end
273
316
  end
274
317
 
318
+ def auto_deployed?
319
+ self.id >= 25000000
320
+ end
321
+
275
322
  def refresh(session: {})
276
323
  refresh_count ||= 0
277
324
  skip_connect ||= false
@@ -2,6 +2,6 @@ module ZuoraConnect
2
2
  class ZuoraUser < ActiveRecord::Base
3
3
  self.table_name = "zuora_users"
4
4
  attr_accessor :session
5
-
5
+ cattr_accessor :current_user
6
6
  end
7
7
  end
@@ -13,6 +13,9 @@ require 'logging/connect_formatter'
13
13
  require 'metrics/influx/point_value'
14
14
  require 'metrics/net'
15
15
  require 'mono_logger'
16
+ require 'zuora_connect/zuora_audit'
17
+ require 'active_record'
18
+ ::ActiveRecord::Base.send :include, ZuoraConnect::ZuoraAudit
16
19
 
17
20
  module ZuoraConnect
18
21
  class << self
@@ -132,11 +132,16 @@ module ZuoraConnect
132
132
  if locale.include?("-")
133
133
  locale = locale.split("-").first
134
134
  retry
135
+ elsif locale != session["#{@appinstance.id}::user::language"]
136
+ locale = session["#{@appinstance.id}::user::language"]
137
+ retry
135
138
  end
136
139
  ZuoraConnect.logger.error(ex) if !ZuoraConnect::AppInstance::IGNORED_LOCALS.include?(ex.locale.to_s.downcase)
137
140
  end
138
141
  begin
139
- Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
142
+ if @appinstance.user_timezone.blank?
143
+ Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone
144
+ end
140
145
  rescue
141
146
  ZuoraConnect.logger.error(ex)
142
147
  end
@@ -437,6 +442,7 @@ module ZuoraConnect
437
442
  @zuora_user = ZuoraConnect::ZuoraUser.create!(:zuora_user_id => zuora_user_id, :zuora_identity_response => {zuora_entity_id => session["ZuoraCurrentIdentity"]})
438
443
  end
439
444
  @zuora_user.session = session
445
+ ZuoraConnect::ZuoraUser.current_user = @zuora_user
440
446
  session["#{@appinstance.id}::user::localUserId"] = @zuora_user.id
441
447
  session["#{@appinstance.id}::user::email"] = session['ZuoraCurrentIdentity']["username"]
442
448
  session["#{@appinstance.id}::user::timezone"] = session['ZuoraCurrentIdentity']["timeZone"]
@@ -679,6 +685,7 @@ module ZuoraConnect
679
685
  key = ZuoraConnect.configuration.dev_mode_pass
680
686
  values = {:user => user , :key => key, :appinstance => session["appInstance"]}
681
687
  @appinstance = ZuoraConnect::AppInstance.find_by(:id => values[:appinstance].to_i)
688
+ ZuoraConnect::ZuoraUser.current_user = user
682
689
  if @appinstance.blank?
683
690
  Apartment::Tenant.switch!("public")
684
691
  begin
@@ -1,3 +1,3 @@
1
1
  module ZuoraConnect
2
- VERSION = "2.0.60i"
2
+ VERSION = "2.0.60n"
3
3
  end
@@ -0,0 +1,31 @@
1
+ # Added by @Vina
2
+ # Description: This automatically stamp user created/updated the record for DataQuery Audit
3
+ # Usage: add 'zuora_audit' to your model.rb that you would like to track
4
+
5
+ module ZuoraConnect
6
+ module ZuoraAudit
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ def zuora_audit
11
+ include ZuoraConnect::ZuoraAudit::ZuoraAuditInstanceMethods
12
+ after_create :set_created_by_id
13
+ before_update :set_updated_by_id
14
+ end
15
+ end
16
+
17
+ module ZuoraAuditInstanceMethods
18
+ def set_created_by_id
19
+ self.created_by_id = current_user_id if defined?(self.created_by_id)
20
+ end
21
+
22
+ def set_updated_by_id
23
+ self.updated_by_id = current_user_id if defined?(self.updated_by_id)
24
+ end
25
+
26
+ def current_user_id
27
+ return ZuoraConnect::ZuoraUser.current_user
28
+ end
29
+ end
30
+ end
31
+ 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.60i
4
+ version: 2.0.60n
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-10-28 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apartment
@@ -374,6 +374,7 @@ files:
374
374
  - lib/zuora_connect/exceptions.rb
375
375
  - lib/zuora_connect/railtie.rb
376
376
  - lib/zuora_connect/version.rb
377
+ - lib/zuora_connect/zuora_audit.rb
377
378
  - test/controllers/zuora_connect/api/v1/app_instance_controller_test.rb
378
379
  - test/dummy/README.rdoc
379
380
  - test/dummy/Rakefile