zuora_connect 2.0.60h → 2.0.60m

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: f42f8d9aa43845b520355af09e97e78350733a04f0585aeb04fafc7f5ed6a1d6
4
- data.tar.gz: 7dfd646a3fa29e7ddbc57ecc461c9d0789a44fecd9eca7a17bdde0e8e037396b
3
+ metadata.gz: ea7bbbca4b37f1429f97fd4f2d173efba916f3b72616bbd5713b610b5269c7e1
4
+ data.tar.gz: 1fa5fd61bb859cf74b669eab6f6e1cc94672a46d5b261d73fa43fd6bde126751
5
5
  SHA512:
6
- metadata.gz: 504efdf52062062981373b857b4ff520473e065a4b9d59f1b4282e4c10de2f06285ba2a80790d810362ad62b011d5ffba7f0fb3235e40fc94b629ea59eff2119
7
- data.tar.gz: 210ed53a545c3b86beaf0d7dfa08d567f53b88d0f2d711008bf73b15ebb14b38cdb2c310d4dd9cac891364877856c0b9e9b232bd39838fca5a786f896db6ccbb
6
+ metadata.gz: dd9b858b6e5478d7131b4b1119769c7dc95c881eca6439fa651711c87104d7cb3a656a6731a01090c99b5b6841b93d1b6c539b9218efa2a691b46d9912eff680
7
+ data.tar.gz: ecd6b793f756cc670d4c38d0366edd54d7eceb1a67d50b1dbff20b81b9da343b0da9dc978e0a9d88ff30c1aae040822491c07179da2d6f5d1ceef1607f491049
@@ -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
+ attr_accessor :current_user
6
6
  end
7
7
  end
@@ -1,9 +1,15 @@
1
1
  module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  class PostgreSQLAdapter < AbstractAdapter
4
+
5
+ SCHEMA_ADDITIONAL_TYPES = 'SchemaAdditionalTypes'.freeze
6
+
4
7
  private
5
8
  def load_additional_types_latest(oids = nil)
6
9
  initializer = OID::TypeMapInitializer.new(type_map)
10
+
11
+ return if loaded_from_cache?(initializer)
12
+
7
13
  if supports_ranges?
8
14
  query = <<-SQL
9
15
  SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
@@ -20,16 +26,20 @@ module ActiveRecord
20
26
  if oids
21
27
  query += "WHERE t.oid::integer IN (%s)" % oids.join(", ")
22
28
  else
23
- query += initializer.query_conditions_for_initial_load
29
+ query += initializer.query_conditions_for_initial_load(type_map)
24
30
  end
25
31
 
26
32
  execute_and_clear(query, "SCHEMA", []) do |records|
33
+ cache_additional_types(records)
27
34
  initializer.run(records)
28
35
  end
29
36
  end
30
37
 
31
38
  def load_additional_types_deprecated(type_map, oids = nil)
32
39
  initializer = OID::TypeMapInitializer.new(type_map)
40
+
41
+ return if loaded_from_cache?(initializer)
42
+
33
43
  if supports_ranges?
34
44
  query = <<-SQL
35
45
  SELECT DISTINCT on (t.typname) t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype
@@ -50,10 +60,37 @@ module ActiveRecord
50
60
  end
51
61
 
52
62
  execute_and_clear(query, "SCHEMA", []) do |records|
63
+ cache_additional_types(records)
53
64
  initializer.run(records)
54
65
  end
55
66
  end
56
67
 
68
+ def loaded_from_cache?(initializer)
69
+ if defined?(Redis.current)
70
+ begin
71
+ if Redis.current.exists(SCHEMA_ADDITIONAL_TYPES)
72
+ initializer.run(JSON.parse(Redis.current.get(SCHEMA_ADDITIONAL_TYPES)))
73
+ return true
74
+ end
75
+ rescue => ex
76
+ Rails.logger.warn('Exception occurred while loading additional types', ex)
77
+ end
78
+ end
79
+
80
+ false
81
+ end
82
+
83
+ def cache_additional_types(records)
84
+ if defined?(Redis.current)
85
+ begin
86
+ Redis.current.setex(SCHEMA_ADDITIONAL_TYPES, 1.hour.to_i, records.to_json)
87
+ rescue => ex
88
+ Rails.logger.warn('Exception occurred while caching additional types', ex)
89
+ end
90
+ end
91
+ end
92
+
93
+
57
94
  rails_version = Rails.version.split('.').map { |x| x.to_i }
58
95
  if (rails_version <=> [5, 2, 0]) >= 1
59
96
  alias :load_additional_types :load_additional_types_latest
@@ -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.60h"
2
+ VERSION = "2.0.60m"
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.60h
4
+ version: 2.0.60m
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-19 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