maestrano-connector-rails 2.2.1 → 2.3.0

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
- SHA1:
3
- metadata.gz: f491d86e8ed4f633f60495e2ef8e6ee1ace82e33
4
- data.tar.gz: e03029e37868143e5ab4fd702d186634c19124fb
2
+ SHA256:
3
+ metadata.gz: fe9997e4a9fafbf461eb15e54a2dc5d0fd39eeb76452cb33949145b3bc7a8f88
4
+ data.tar.gz: 771eae938809e8aeb51b0d9250ebf560b565b02b1b5c28e6de5d173e810c1a2b
5
5
  SHA512:
6
- metadata.gz: 39326123a05567be519a51ed368a99c4f68c31b8a335d66292237cbccc18962a5bdd5c8d3c0db6fa6977cb8f7abe838e985e8ce5ecb64aa63aacd5b5c8d4f8bf
7
- data.tar.gz: 62bd51a19f67246467d223080f40f016a46f43e14c3db8036b630ef4ad2ca69dece8238ba260fd0f604d99ce7b3b5aa3b3ef89205165521fc9da891d004d4048
6
+ metadata.gz: c587dc91ddbf6f32455fcd0e2000dc91d5f5591a3490af4421ae964650705f7c1d78a4d74ed29a1d5f8be1d2e4a86c1fdea870493fcfb8ffadbdf4579d15bced
7
+ data.tar.gz: 87e3b05e86736f355859921020f5d4bf18140cf914d6896953614a5e83fb90b2ca5dc586d9f58ef55cfe395949ed0724ae40cf6da5575c93f0243cdd1ef62e08
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-01-12 09:49:01 +1100 using RuboCop version 0.52.1.
3
+ # on 2018-03-12 13:56:34 +1100 using RuboCop version 0.53.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -12,12 +12,7 @@ Lint/AssignmentInCondition:
12
12
  Exclude:
13
13
  - 'app/jobs/maestrano/connector/rails/push_to_connec_job.rb'
14
14
 
15
- # Offense count: 1
16
- Lint/UriEscapeUnescape:
17
- Exclude:
18
- - 'app/models/maestrano/connector/rails/concerns/organization.rb'
19
-
20
- # Offense count: 29
15
+ # Offense count: 28
21
16
  Metrics/AbcSize:
22
17
  Max: 69
23
18
 
@@ -62,13 +57,6 @@ Performance/FlatMap:
62
57
  Exclude:
63
58
  - 'app/models/maestrano/connector/rails/concerns/complex_entity.rb'
64
59
 
65
- # Offense count: 2
66
- # Cop supports --auto-correct.
67
- # Configuration parameters: AutoCorrect.
68
- Performance/HashEachMethods:
69
- Exclude:
70
- - 'app/resources/maestrano/api/base_resource.rb'
71
-
72
60
  # Offense count: 1
73
61
  # Cop supports --auto-correct.
74
62
  # Configuration parameters: Whitelist.
@@ -154,7 +142,7 @@ Style/RegexpLiteral:
154
142
  Exclude:
155
143
  - 'app/models/maestrano/connector/rails/concerns/entity.rb'
156
144
 
157
- # Offense count: 8
145
+ # Offense count: 10
158
146
  # Cop supports --auto-correct.
159
147
  # Configuration parameters: EnforcedStyle.
160
148
  # SupportedStyles: implicit, explicit
@@ -166,10 +154,3 @@ Style/RescueStandardError:
166
154
  - 'app/models/maestrano/connector/rails/concerns/entity.rb'
167
155
  - 'app/models/maestrano/connector/rails/concerns/organization.rb'
168
156
  - 'app/resources/maestrano/api/base_resource.rb'
169
-
170
- # Offense count: 2
171
- # Cop supports --auto-correct.
172
- # Configuration parameters: ConvertCodeThatCanStartToReturnNil.
173
- Style/SafeNavigation:
174
- Exclude:
175
- - 'app/models/maestrano/connector/rails/concerns/entity.rb'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1@maestrano-connector-rails
1
+ 2.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## 2.3.0
2
+
3
+ * Send data to Connec! even if the push/pull parameters are disabled (Transac! integration)
4
+ * Randomise cron jobs time to avoid connectors crowding
5
+ * Fix duplicated Sidekiq UI configuration and time based attack
6
+
7
+ ## 2.2.1
8
+
9
+ * Fix a bug where the CreationMapper was used to map updates coming from external
10
+
11
+ ## 2.2.0
12
+
13
+ * New applications workflow
14
+ * JSON API / Pundit introduced to manage resources
15
+
16
+ ### Migration Guide
17
+ * Add this Gems to the Gemfile
18
+ * `jsonapi-resources`, `pundit`, `pundit-resources`
19
+
1
20
  ## 2.1.3
2
21
 
3
22
  ### Features
data/DEVELOPER.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ## Release gem
2
2
 
3
3
  Edit `lib/maestrano/connector/rails/version.rb` with the new version.
4
+ Update CHANGELOG.md with the changes and the migration guide (if needed)
4
5
 
5
6
  ``` bash
6
7
  bundle exec rake release
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'bundler/gem_tasks'
8
8
  require 'rspec/core/rake_task'
9
9
  require 'rubocop/rake_task'
10
10
 
11
- APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
11
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
12
12
  load 'rails/tasks/engine.rake'
13
13
 
14
14
  RuboCop::RakeTask.new
@@ -24,12 +24,12 @@ class Maestrano::ConnecController < Maestrano::Rails::WebHookController
24
24
  entity_instance.push_entities_to_external(mapped_entity[:connec_entities])
25
25
  entity_instance.after_sync(last_synchronization_date)
26
26
  rescue => e
27
- Maestrano::Connector::Rails::ConnectorLogger.log('warn', organization, "error processing notification entity_name=\"#{entity_name}\", message=\"#{e.message}\", #{e.backtrace.join("\n")}")
27
+ Maestrano::Connector::Rails::ConnectorLogger.log('warn', organization, "error processing notification entity_name=\"#{entity_name}\", message=\"#{e.message}\", trace=\"#{e.backtrace}\"")
28
28
  end
29
29
  end
30
30
  end
31
31
  rescue => e
32
- Maestrano::Connector::Rails::ConnectorLogger.log('warn', nil, "error processing notification #{e.message} - #{e.backtrace.join("\n")}")
32
+ Maestrano::Connector::Rails::ConnectorLogger.log('warn', nil, "error processing notification #{e.message} - #{e.backtrace}")
33
33
  end
34
34
 
35
35
  head 200, content_type: 'application/json'
@@ -13,13 +13,23 @@ module Maestrano::Connector::Rails::Concerns::SynchronizationJob
13
13
  def find_job(organization_id)
14
14
  queue = Sidekiq::Queue.new(:default)
15
15
  queue.find do |job|
16
- organization_id == job.item['args'][0]['arguments'].first
16
+ job_organization_id = begin
17
+ job.item['args'][0]['arguments'].first
18
+ rescue
19
+ false
20
+ end
21
+ organization_id == job_organization_id
17
22
  end
18
23
  end
19
24
 
20
25
  def find_running_job(organization_id)
21
26
  Sidekiq::Workers.new.find do |_, _, work|
22
- work['queue'] == 'default' && work['payload']['args'][0]['arguments'].first == organization_id
27
+ job_organization_id = begin
28
+ work['payload']['args'][0]['arguments'].first
29
+ rescue
30
+ false
31
+ end
32
+ work['queue'] == 'default' && organization_id == job_organization_id
23
33
  end
24
34
  rescue
25
35
  nil
@@ -87,7 +97,7 @@ module Maestrano::Connector::Rails::Concerns::SynchronizationJob
87
97
  Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Finished synchronization, organization=#{organization.uid}, status=success")
88
98
  current_synchronization.mark_as_success
89
99
  rescue => e
90
- Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Finished synchronization, organization=#{organization.uid}, status=error, message=#{e.message} backtrace=#{e.backtrace.join("\n\t")}")
100
+ Maestrano::Connector::Rails::ConnectorLogger.log('warn', organization, "Finished synchronization, organization=#{organization.uid}, status=error, message=\"#{e.message}\" backtrace=\"#{e.backtrace}\"")
91
101
  current_synchronization.mark_as_error(e.message)
92
102
  end
93
103
  end
@@ -0,0 +1,16 @@
1
+ # Periodically fetch the developer platform configuration
2
+ module Maestrano::Connector::Rails::Concerns::UpdateConfigurationJob
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ queue_as :default
7
+ end
8
+
9
+ def perform
10
+ return if ENV['SKIP_CONFIGURATION']
11
+ Maestrano.reset!
12
+ Maestrano.auto_configure
13
+ rescue StandardError => e
14
+ Rails.logger.warn "Cannot load configuration #{e.message}"
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Maestrano::Connector::Rails
2
+ class UpdateConfigurationJob < ::ActiveJob::Base
3
+ include Maestrano::Connector::Rails::Concerns::UpdateConfigurationJob
4
+ end
5
+ end
@@ -388,7 +388,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
388
388
  else
389
389
  # Store External error
390
390
  Maestrano::Connector::Rails::ConnectorLogger.log('error', @organization, "Error while pushing to #{Maestrano::Connector::Rails::External.external_name}: #{e}")
391
- Maestrano::Connector::Rails::ConnectorLogger.log('debug', @organization, "Error while pushing backtrace: #{e.backtrace.join("\n\t")}")
391
+ Maestrano::Connector::Rails::ConnectorLogger.log('debug', @organization, "Error while pushing backtrace: #{e.backtrace}")
392
392
  idmap.update(message: e.message.truncate(255))
393
393
  end
394
394
  end
@@ -13,9 +13,6 @@ module Maestrano::Connector::Rails::Concerns::Organization
13
13
  # group.some_required_field = 'some-appropriate-default-value'
14
14
  end
15
15
 
16
- # Callbacks
17
- before_save :update_metadata
18
-
19
16
  #===================================
20
17
  # Encryptions
21
18
  #===================================
@@ -53,7 +50,19 @@ module Maestrano::Connector::Rails::Concerns::Organization
53
50
 
54
51
  self.synchronized_entities = {}
55
52
  Maestrano::Connector::Rails::External.entities_list.each do |entity|
56
- synchronized_entities[entity.to_sym] = {can_push_to_connec: !pull_disabled, can_push_to_external: !push_disabled}
53
+ begin
54
+ # Transform entity name from entities_list to class name
55
+ # ex. :item => Entities::Item
56
+ clazz = "Entities::#{entity.to_s.titleize.tr(' ', '')}".constantize
57
+ rescue
58
+ clazz = nil
59
+ end
60
+
61
+ # Check if Entity or ComplexEntity and set entity_push_to_connec and entity_push_to_external
62
+ entity_push_to_connec = clazz && clazz < Maestrano::Connector::Rails::Entity ? clazz.can_write_connec? : true
63
+ entity_push_to_external = clazz && clazz < Maestrano::Connector::Rails::Entity ? clazz.can_write_external? : true
64
+
65
+ synchronized_entities[entity.to_sym] = {can_push_to_connec: !pull_disabled && entity_push_to_connec, can_push_to_external: !push_disabled && entity_push_to_external}
57
66
  end
58
67
  end
59
68
 
@@ -61,7 +70,9 @@ module Maestrano::Connector::Rails::Concerns::Organization
61
70
  result = {}
62
71
  synchronized_entities.each do |entity, hash|
63
72
  begin
64
- clazz = "Entities::#{entity.to_s.titleize.split.join}".constantize
73
+ # Transform entity name from entities_list to class name
74
+ # ex. :item => Entities::Item
75
+ clazz = "Entities::#{entity.to_s.titleize.tr(' ', '')}".constantize
65
76
  rescue
66
77
  next
67
78
  end
@@ -138,7 +149,7 @@ module Maestrano::Connector::Rails::Concerns::Organization
138
149
  can_push_to_external = synchronized_entities[entity.to_sym]
139
150
  can_push_to_connec = synchronized_entities[entity.to_sym]
140
151
  end
141
- synchronized_entities[entity.to_sym] = {can_push_to_connec: (can_push_to_connec || default) && !pull_disabled, can_push_to_external: (can_push_to_external || default) && !push_disabled}
152
+ synchronized_entities[entity.to_sym] = {can_push_to_connec: (can_push_to_connec || default), can_push_to_external: (can_push_to_external || default)}
142
153
  end
143
154
  save
144
155
  end
@@ -150,17 +161,4 @@ module Maestrano::Connector::Rails::Concerns::Organization
150
161
  def push_to_external_enabled?(entity)
151
162
  synchronized_entities.dig(Maestrano::Connector::Rails::EntityHelper.snake_name(entity), :can_push_to_external) && entity&.class&.can_write_external?
152
163
  end
153
-
154
- def set_instance_metadata
155
- auth = {username: Maestrano[tenant].param('api.id'), password: Maestrano[tenant].param('api.key')}
156
- res = HTTParty.get(URI.encode("#{Maestrano[tenant].param('api.host')}/api/v1/account/groups/#{uid}"), basic_auth: auth)
157
- response = JSON.parse(res.body)
158
- self.push_disabled = response.dig('data', 'metadata', 'push_disabled')
159
- self.pull_disabled = response.dig('data', 'metadata', 'pull_disabled')
160
- end
161
-
162
- def update_metadata
163
- set_instance_metadata
164
- enable_historical_data(true) if push_disabled
165
- end
166
164
  end
@@ -36,15 +36,15 @@ module Maestrano::Connector::Rails::Concerns::Synchronization
36
36
  end
37
37
 
38
38
  def mark_as_success
39
- update_attributes(status: SUCCESS_STATUS)
39
+ update(status: SUCCESS_STATUS)
40
40
  end
41
41
 
42
42
  def mark_as_error(msg)
43
- update_attributes(status: ERROR_STATUS, message: msg)
43
+ update(status: ERROR_STATUS, message: msg)
44
44
  end
45
45
 
46
46
  def mark_as_partial
47
- update_attributes(partial: true)
47
+ update(partial: true)
48
48
  end
49
49
 
50
50
  def clean_synchronizations
@@ -1,7 +1,7 @@
1
1
  module Connector
2
2
  module Generators
3
3
  class ComplexEntityGenerator < ::Rails::Generators::Base
4
- source_root File.expand_path('../templates', __FILE__)
4
+ source_root File.expand_path('templates', __dir__)
5
5
 
6
6
  def copy_example_files
7
7
  copy_file 'complex_entity_example/contact_and_lead.rb', 'app/models/entities/example_contact_and_lead.rb'
@@ -2,7 +2,7 @@ require 'fileutils'
2
2
 
3
3
  module Connector
4
4
  class InstallGenerator < ::Rails::Generators::Base
5
- source_root File.expand_path('../templates', __FILE__)
5
+ source_root File.expand_path('templates', __dir__)
6
6
  desc 'Creating a Maestrano Connector application'
7
7
 
8
8
  def maestrano_generator
@@ -5,6 +5,7 @@ class HomeController < ApplicationController
5
5
 
6
6
  # Update list of entities to synchronize
7
7
  current_organization.synchronized_entities.keys.each do |entity|
8
+ next unless params[entity.to_s]
8
9
  current_organization.synchronized_entities[entity][:can_push_to_connec] = params[entity.to_s]["to_connec"] == "1"
9
10
  current_organization.synchronized_entities[entity][:can_push_to_external] = params[entity.to_s]["to_external"] == "1"
10
11
  end
@@ -64,9 +64,9 @@
64
64
  - current_organization.displayable_synchronized_entities.each do |k, v|
65
65
  .row.sync-entity
66
66
  .col-md-1.link-step-action
67
- #{check_box("#{k}", "to_connec", {checked: (v[:can_push_to_connec] || v[:can_push_to_external]) && !current_organization.pull_disabled, onclick: "return !#{k}_to_external.checked;", disabled: current_organization.pull_disabled})}
67
+ #{check_box("#{k}", "to_connec", {checked: (v[:can_push_to_connec] || v[:can_push_to_external]) && !current_organization.pull_disabled, onclick: "return !#{k}_to_external.checked;", disabled: current_organization.pull_disabled || !v[:can_push_to_connec]})}
68
68
  .col-md-1.link-step-action
69
- #{check_box("#{k}", "to_external", {checked: v[:can_push_to_external] && !current_organization.push_disabled, onchange: "#{k}_to_connec.checked = #{!current_organization.pull_disabled};", disabled: current_organization.push_disabled})}
69
+ #{check_box("#{k}", "to_external", {checked: v[:can_push_to_external] && !current_organization.push_disabled, onchange: "#{k}_to_connec.checked = #{!current_organization.pull_disabled};", disabled: current_organization.push_disabled || !v[:can_push_to_external]})}
70
70
  %label.col-md-7{:for => "#{k}", style: 'padding-top: 5px;'}
71
71
  .col-md-6
72
72
  #{v[:external_name]}
@@ -14,7 +14,6 @@ require 'attr_encrypted'
14
14
  require 'sidekiq'
15
15
  require 'sidekiq-cron'
16
16
  require 'sidekiq-unique-jobs'
17
- require 'sinatra'
18
17
  require 'slim'
19
18
 
20
19
  module Maestrano
@@ -1,7 +1,7 @@
1
1
  module Maestrano
2
2
  module Connector
3
3
  module Rails
4
- VERSION = '2.2.1'.freeze
4
+ VERSION = '2.3.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -40,7 +40,6 @@ Gem::Specification.new do |s|
40
40
  s.add_runtime_dependency('sidekiq', '~> 4.2.9')
41
41
  s.add_runtime_dependency('sidekiq-cron')
42
42
  s.add_runtime_dependency('sidekiq-unique-jobs')
43
- s.add_runtime_dependency('sinatra')
44
43
  s.add_runtime_dependency('slim')
45
44
 
46
45
  s.add_development_dependency('bundler')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maestrano-connector-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maestrano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-16 00:00:00.000000000 Z
11
+ date: 2018-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -234,20 +234,6 @@ dependencies:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
- - !ruby/object:Gem::Dependency
238
- name: sinatra
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - ">="
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
- type: :runtime
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - ">="
249
- - !ruby/object:Gem::Version
250
- version: '0'
251
237
  - !ruby/object:Gem::Dependency
252
238
  name: slim
253
239
  requirement: !ruby/object:Gem::Requirement
@@ -458,9 +444,11 @@ files:
458
444
  - app/helpers/maestrano/connector/rails/session_helper.rb
459
445
  - app/jobs/maestrano/connector/rails/all_synchronizations_job.rb
460
446
  - app/jobs/maestrano/connector/rails/concerns/synchronization_job.rb
447
+ - app/jobs/maestrano/connector/rails/concerns/update_configuration_job.rb
461
448
  - app/jobs/maestrano/connector/rails/push_to_connec_job.rb
462
449
  - app/jobs/maestrano/connector/rails/push_to_connec_worker.rb
463
450
  - app/jobs/maestrano/connector/rails/synchronization_job.rb
451
+ - app/jobs/maestrano/connector/rails/update_configuration_job.rb
464
452
  - app/models/maestrano/connector/rails/complex_entity.rb
465
453
  - app/models/maestrano/connector/rails/concerns/complex_entity.rb
466
454
  - app/models/maestrano/connector/rails/concerns/connec_helper.rb
@@ -575,7 +563,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
575
563
  version: '0'
576
564
  requirements: []
577
565
  rubyforge_project:
578
- rubygems_version: 2.5.1
566
+ rubygems_version: 2.7.6
579
567
  signing_key:
580
568
  specification_version: 4
581
569
  summary: Rails framework to build connector with Maestrano