maestrano-connector-rails 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -3
- data/.rubocop_todo.yml +1 -18
- data/VERSION +1 -1
- data/app/jobs/maestrano/connector/rails/synchronization_job.rb +13 -2
- data/app/models/maestrano/connector/rails/concerns/complex_entity.rb +4 -2
- data/app/models/maestrano/connector/rails/concerns/entity.rb +13 -7
- data/app/models/maestrano/connector/rails/exceptions/entity_not_found_error.rb +3 -0
- data/app/models/maestrano/connector/rails/organization.rb +20 -0
- data/lib/generators/connector/complex_entity_generator.rb +2 -2
- data/lib/generators/connector/install_generator.rb +3 -3
- data/lib/generators/connector/templates/complex_entity_example/contact.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/contact_and_lead.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/contact_mapper.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/lead.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/lead_mapper.rb +2 -1
- data/lib/generators/connector/templates/complex_entity_example/person.rb +2 -1
- data/lib/generators/connector/templates/entity.rb +1 -0
- data/lib/generators/connector/templates/example_entity.rb +2 -1
- data/lib/generators/connector/templates/example_entity_spec.rb +1 -0
- data/lib/generators/connector/templates/external.rb +2 -1
- data/lib/generators/connector/templates/home_controller.rb +19 -30
- data/lib/generators/connector/templates/home_controller_spec.rb +18 -19
- data/lib/generators/connector/templates/oauth_controller.rb +13 -24
- data/lib/generators/connector/templates/shared_entities_controller.rb +4 -4
- data/lib/generators/connector/templates/shared_entities_controller_spec.rb +5 -5
- data/lib/generators/connector/templates/stylesheets/layout.sass +16 -3
- data/lib/generators/connector/templates/stylesheets/variables.sass +22 -4
- data/lib/generators/connector/templates/synchronizations_controller.rb +4 -4
- data/lib/generators/connector/templates/synchronizations_controller_spec.rb +4 -4
- data/maestrano-connector-rails.gemspec +7 -8
- data/release_notes.md +15 -0
- data/spec/dummy/tmp/cache/.keep +1 -0
- data/spec/factories.rb +7 -8
- data/spec/jobs/synchronization_job_spec.rb +34 -12
- data/spec/models/complex_entity_spec.rb +5 -5
- data/spec/models/entity_spec.rb +18 -12
- data/spec/spec_helper.rb +2 -2
- data/template/{application.yml.sample → application-sample.yml} +0 -0
- data/template/factories.rb +4 -5
- data/template/maestrano.rb +3 -3
- data/template/{maestrano-connector-template.rb → maestrano_connector_template.rb} +27 -25
- data/template/routes.rb +2 -8
- data/template/rubocop.yml +55 -0
- data/template/sidekiq.rb +8 -0
- data/template/spec_helper.rb +4 -3
- metadata +6 -7
- data/spec/dummy/app/controllers/admin_controller.rb +0 -48
- data/spec/dummy/app/controllers/home_controller.rb +0 -17
- data/spec/dummy/app/controllers/oauth_controller.rb +0 -45
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
4
4
|
require 'rspec/rails'
|
5
5
|
require 'factory_girl_rails'
|
6
6
|
require 'shoulda/matchers'
|
@@ -17,7 +17,7 @@ RSpec.configure do |config|
|
|
17
17
|
config.mock_with :rspec
|
18
18
|
config.use_transactional_fixtures = true
|
19
19
|
config.infer_base_class_for_anonymous_controllers = false
|
20
|
-
config.order =
|
20
|
+
config.order = 'random'
|
21
21
|
config.include FactoryGirl::Syntax::Methods
|
22
22
|
config.include Maestrano::Connector::Rails::Engine.routes.url_helpers
|
23
23
|
|
File without changes
|
data/template/factories.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
FactoryGirl.define do
|
2
|
-
|
3
2
|
factory :organization, class: Maestrano::Connector::Rails::Organization do
|
4
|
-
name
|
5
|
-
tenant
|
3
|
+
name 'My company'
|
4
|
+
tenant 'default'
|
6
5
|
sequence(:uid) { |n| "cld-11#{n}" }
|
7
6
|
oauth_uid 'sfuiy765'
|
8
7
|
oauth_provider 'this_app'
|
@@ -12,7 +11,7 @@ FactoryGirl.define do
|
|
12
11
|
connec_entity 'person'
|
13
12
|
external_id '4567ada66'
|
14
13
|
external_entity 'contact'
|
15
|
-
last_push_to_external 2.
|
14
|
+
last_push_to_external 2.days.ago
|
16
15
|
last_push_to_connec 1.day.ago
|
17
16
|
association :organization
|
18
17
|
end
|
@@ -22,4 +21,4 @@ FactoryGirl.define do
|
|
22
21
|
status 'SUCCESS'
|
23
22
|
partial false
|
24
23
|
end
|
25
|
-
end
|
24
|
+
end
|
data/template/maestrano.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
%w(default maestrano-uat).each do |tenant|
|
2
3
|
Maestrano[tenant].configure do |config|
|
3
|
-
|
4
4
|
# ==> Environment configuration
|
5
5
|
# The environment to connect to.
|
6
6
|
# If set to 'production' then all Single Sign-On (SSO) and API requests
|
@@ -140,7 +140,7 @@
|
|
140
140
|
#
|
141
141
|
# == Subscriptions
|
142
142
|
# This is the list of entities (organizations,people,invoices etc.) for which you want to be
|
143
|
-
# notified upon creation/update in Connec
|
143
|
+
# notified upon creation/update in Connec!
|
144
144
|
config.webhook.connec.subscriptions = {
|
145
145
|
accounts: false,
|
146
146
|
company: false,
|
@@ -171,4 +171,4 @@
|
|
171
171
|
work_locations: false
|
172
172
|
}
|
173
173
|
end
|
174
|
-
end
|
174
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
def current_directory
|
2
2
|
@current_directory ||=
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
if __FILE__ =~ %r{\Ahttps?://}
|
4
|
+
tempdir = Dir.mktmpdir('maestrano-connector-rails-')
|
5
|
+
at_exit { FileUtils.remove_entry(tempdir) }
|
6
|
+
git clone: "--quiet https://github.com/maestrano/maestrano-connector-rails/ #{tempdir}"
|
7
|
+
|
8
|
+
"#{tempdir}/template"
|
9
|
+
else
|
10
|
+
File.expand_path(File.dirname(__FILE__))
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
# def current_directory
|
@@ -29,7 +29,7 @@ run 'touch Gemfile'
|
|
29
29
|
|
30
30
|
add_source 'https://rubygems.org'
|
31
31
|
|
32
|
-
if yes?(
|
32
|
+
if yes?('Use JRuby? [y/n]')
|
33
33
|
run 'echo "ruby \'2.2.3\', :engine => \'jruby\', :engine_version => \'9.0.5.0\'" | cat - Gemfile > temp && mv temp Gemfile'
|
34
34
|
end
|
35
35
|
|
@@ -43,14 +43,15 @@ gem 'uglifier', '>= 1.3.0'
|
|
43
43
|
gem 'maestrano-connector-rails'
|
44
44
|
|
45
45
|
gem_group :production, :uat do
|
46
|
-
gem 'activerecord-jdbcpostgresql-adapter', :
|
47
|
-
gem 'pg', :
|
46
|
+
gem 'activerecord-jdbcpostgresql-adapter', platforms: :jruby
|
47
|
+
gem 'pg', platforms: :ruby
|
48
48
|
gem 'rails_12factor'
|
49
49
|
end
|
50
50
|
|
51
51
|
gem_group :test, :develpment do
|
52
|
-
gem 'activerecord-jdbcsqlite3-adapter', :
|
53
|
-
gem 'sqlite3', :
|
52
|
+
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
53
|
+
gem 'sqlite3', platforms: :ruby
|
54
|
+
gem 'rubocop'
|
54
55
|
end
|
55
56
|
|
56
57
|
gem_group :test do
|
@@ -63,7 +64,7 @@ end
|
|
63
64
|
|
64
65
|
remove_file '.gitignore'
|
65
66
|
copy_file 'gitignore', '.gitignore'
|
66
|
-
|
67
|
+
copy_file 'rubocop.yml', '.rubocop.yml'
|
67
68
|
|
68
69
|
#
|
69
70
|
# Cleanup
|
@@ -100,15 +101,16 @@ after_bundle do
|
|
100
101
|
end
|
101
102
|
copy_file 'settings/settings.yml', 'config/settings.yml'
|
102
103
|
|
103
|
-
copy_file 'application.yml
|
104
|
+
copy_file 'application-sample.yml', 'config/application-sample.yml'
|
104
105
|
|
105
|
-
application do
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
106
|
+
application do
|
107
|
+
<<-RUBY
|
108
|
+
config.generators do |g|
|
109
|
+
g.test_framework :rspec, fixture: false
|
110
|
+
g.view_specs false
|
111
|
+
g.helper_specs false
|
112
|
+
end
|
113
|
+
RUBY
|
112
114
|
end
|
113
115
|
|
114
116
|
run 'bundle exec rails g connector:install'
|
@@ -121,6 +123,6 @@ after_bundle do
|
|
121
123
|
|
122
124
|
# Init repo and commit
|
123
125
|
git :init
|
124
|
-
git add:
|
126
|
+
git add: '.'
|
125
127
|
git commit: "-a -m 'Initial commit'"
|
126
|
-
end
|
128
|
+
end
|
data/template/routes.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
mount Maestrano::Connector::Rails::Engine, at: '/'
|
3
|
+
mount Sidekiq::Web => '/sidekiq'
|
3
4
|
|
4
5
|
root 'home#index'
|
5
6
|
get 'home/index' => 'home#index'
|
@@ -10,11 +11,4 @@ Rails.application.routes.draw do
|
|
10
11
|
|
11
12
|
get 'synchronizations/index' => 'synchronizations#index'
|
12
13
|
get 'shared_entities/index' => 'shared_entities#index'
|
13
|
-
|
14
|
-
# Sidekiq Admin
|
15
|
-
require 'sidekiq/web'
|
16
|
-
Sidekiq::Web.use Rack::Auth::Basic do |username, password|
|
17
|
-
username == ENV['SIDEKIQ_USERNAME'] && password == ENV['SIDEKIQ_PASSWORD']
|
18
|
-
end
|
19
|
-
mount Sidekiq::Web => '/sidekiq'
|
20
|
-
end
|
14
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Rails:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.3
|
6
|
+
Exclude:
|
7
|
+
- 'db/schema.rb'
|
8
|
+
- 'db/migrate/*'
|
9
|
+
- 'db/seeds.rb'
|
10
|
+
- 'bin/*'
|
11
|
+
- 'Gemfile'
|
12
|
+
- 'Rakefile'
|
13
|
+
- 'config.ru'
|
14
|
+
- 'spec/**/*'
|
15
|
+
- 'config/**/*'
|
16
|
+
- 'app/helpers/application_helper.rb'
|
17
|
+
- 'app/controllers/application_controller.rb'
|
18
|
+
|
19
|
+
# Enabled disabled Cops
|
20
|
+
Style/CollectionMethods:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
Metrics/LineLength:
|
24
|
+
Max: 320
|
25
|
+
|
26
|
+
Style/IndentationConsistency:
|
27
|
+
EnforcedStyle: rails
|
28
|
+
|
29
|
+
# Missing top-level class documentation comment
|
30
|
+
Style/Documentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/ClassAndModuleChildren:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# Space inside braces => only for blocks (not for literal)
|
37
|
+
Style/SpaceInsideHashLiteralBraces:
|
38
|
+
EnforcedStyle: no_space
|
39
|
+
|
40
|
+
# Checks for unused block arguments
|
41
|
+
Lint/UnusedBlockArgument:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
# Checks for unused method arguments.
|
45
|
+
Lint/UnusedMethodArgument:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Metrics/AbcSize:
|
49
|
+
# The ABC size is a calculated magnitude, so this number can be a Fixnum or
|
50
|
+
# a Float.
|
51
|
+
Max: 27
|
52
|
+
|
53
|
+
# RSpec/FilePath:
|
54
|
+
# Exclude:
|
55
|
+
# - 'spec/routing/**/*_routing_spec.rb'
|
data/template/sidekiq.rb
CHANGED
@@ -1 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'sidekiq/web'
|
3
|
+
|
1
4
|
Sidekiq::Cron::Job.create(name: 'AllSynchronizationsJob runs every hour', cron: '0 * * * *', class: 'Maestrano::Connector::Rails::AllSynchronizationsJob')
|
5
|
+
|
6
|
+
# Sidekiq Admin
|
7
|
+
Sidekiq::Web.use Rack::Auth::Basic do |username, password|
|
8
|
+
username == ENV['SIDEKIQ_USERNAME'] && password == ENV['SIDEKIQ_PASSWORD']
|
9
|
+
end
|
data/template/spec_helper.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'simplecov'
|
2
3
|
SimpleCov.start
|
3
4
|
|
4
5
|
ENV['RAILS_ENV'] ||= 'test'
|
5
6
|
|
6
|
-
require File.expand_path(
|
7
|
+
require File.expand_path('../../config/environment', __FILE__)
|
7
8
|
require 'rspec/rails'
|
8
9
|
require 'factory_girl_rails'
|
9
10
|
require 'shoulda/matchers'
|
@@ -17,6 +18,6 @@ RSpec.configure do |config|
|
|
17
18
|
config.mock_with :rspec
|
18
19
|
config.use_transactional_fixtures = true
|
19
20
|
config.infer_base_class_for_anonymous_controllers = false
|
20
|
-
config.order =
|
21
|
+
config.order = 'random'
|
21
22
|
config.include FactoryGirl::Syntax::Methods
|
22
|
-
end
|
23
|
+
end
|
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: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Berard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -407,6 +407,7 @@ files:
|
|
407
407
|
- app/models/maestrano/connector/rails/connector_logger.rb
|
408
408
|
- app/models/maestrano/connector/rails/entity.rb
|
409
409
|
- app/models/maestrano/connector/rails/entity_base.rb
|
410
|
+
- app/models/maestrano/connector/rails/exceptions/entity_not_found_error.rb
|
410
411
|
- app/models/maestrano/connector/rails/external.rb
|
411
412
|
- app/models/maestrano/connector/rails/id_map.rb
|
412
413
|
- app/models/maestrano/connector/rails/organization.rb
|
@@ -472,11 +473,8 @@ files:
|
|
472
473
|
- spec/dummy/app/assets/images/.keep
|
473
474
|
- spec/dummy/app/assets/javascripts/application.js
|
474
475
|
- spec/dummy/app/assets/stylesheets/application.css
|
475
|
-
- spec/dummy/app/controllers/admin_controller.rb
|
476
476
|
- spec/dummy/app/controllers/application_controller.rb
|
477
477
|
- spec/dummy/app/controllers/concerns/.keep
|
478
|
-
- spec/dummy/app/controllers/home_controller.rb
|
479
|
-
- spec/dummy/app/controllers/oauth_controller.rb
|
480
478
|
- spec/dummy/app/helpers/application_helper.rb
|
481
479
|
- spec/dummy/app/mailers/.keep
|
482
480
|
- spec/dummy/app/models/.keep
|
@@ -548,13 +546,14 @@ files:
|
|
548
546
|
- spec/routing/connec_routing_spec.rb
|
549
547
|
- spec/spec_helper.rb
|
550
548
|
- template/Procfile
|
551
|
-
- template/application.yml
|
549
|
+
- template/application-sample.yml
|
552
550
|
- template/database.yml
|
553
551
|
- template/factories.rb
|
554
552
|
- template/gitignore
|
555
|
-
- template/maestrano-connector-template.rb
|
556
553
|
- template/maestrano.rb
|
554
|
+
- template/maestrano_connector_template.rb
|
557
555
|
- template/routes.rb
|
556
|
+
- template/rubocop.yml
|
558
557
|
- template/settings/development.yml
|
559
558
|
- template/settings/production.yml
|
560
559
|
- template/settings/settings.yml
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# TODO
|
2
|
-
# This controller is given as an example of a possible admin implementation
|
3
|
-
# The admin functions should be restricted to admin users
|
4
|
-
# Admin funcitons :
|
5
|
-
# * Link account to external application
|
6
|
-
# * Disconnect account from external application
|
7
|
-
# * Launch a manual syncrhonization for all entities or a sub-part of them
|
8
|
-
# * Chose which entities are synchronized by the connector
|
9
|
-
# * Access a list of the organization's idmaps
|
10
|
-
class AdminController < ApplicationController
|
11
|
-
|
12
|
-
def index
|
13
|
-
if is_admin
|
14
|
-
@organization = current_organization
|
15
|
-
@idmaps = Maestrano::Connector::Rails::IdMap.where(organization_id: @organization.id).order(:connec_entity)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def update
|
20
|
-
organization = Maestrano::Connector::Rails::Organization.find_by_id(params[:id])
|
21
|
-
|
22
|
-
if organization && is_admin?(current_user, organization)
|
23
|
-
organization.synchronized_entities.keys.each do |entity|
|
24
|
-
if !!params["#{entity}"]
|
25
|
-
organization.synchronized_entities[entity] = true
|
26
|
-
else
|
27
|
-
organization.synchronized_entities[entity] = false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
organization.save
|
31
|
-
end
|
32
|
-
|
33
|
-
redirect_to admin_index_path
|
34
|
-
end
|
35
|
-
|
36
|
-
def synchronize
|
37
|
-
if is_admin
|
38
|
-
Maestrano::Connector::Rails::SynchronizationJob.perform_later(current_organization, params['opts'] || {})
|
39
|
-
end
|
40
|
-
|
41
|
-
redirect_to root_path
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
def is_admin
|
46
|
-
current_user && current_organization && is_admin?(current_user, current_organization)
|
47
|
-
end
|
48
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# TODO
|
2
|
-
# This controller is given as an example of a possible home
|
3
|
-
# Admin funcitons :
|
4
|
-
# * Display generic information about the connector (mostly for not connected users)
|
5
|
-
# * Link the connector to a Maestrano organization
|
6
|
-
# * Acces the last synchronization and a synchronization history (with their status)
|
7
|
-
class HomeController < ApplicationController
|
8
|
-
def index
|
9
|
-
if current_user
|
10
|
-
@organization = current_organization
|
11
|
-
|
12
|
-
if @organization
|
13
|
-
@synchronizations = Maestrano::Connector::Rails::Synchronization.where(organization_id: @organization.id).order(updated_at: :desc).limit(40)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
class OauthController < ApplicationController
|
2
|
-
|
3
|
-
# TODO
|
4
|
-
# Routes for this controller are not provided by the gem and
|
5
|
-
# should be set according to your needs
|
6
|
-
|
7
|
-
def request_omniauth
|
8
|
-
org_uid = params[:org_uid]
|
9
|
-
organization = Maestrano::Connector::Rails::Organization.find_by_uid(org_uid)
|
10
|
-
|
11
|
-
if organization && is_admin?(current_user, organization)
|
12
|
-
# TODO
|
13
|
-
# Perform oauth request here. The oauth process should be able to
|
14
|
-
# remember the organization, either by a param in the request or using
|
15
|
-
# a session
|
16
|
-
else
|
17
|
-
redirect_to root_url
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_omniauth
|
22
|
-
org_uid = '' # TODO
|
23
|
-
organization = Maestrano::Connector::Rails::Organization.find_by_uid(org_uid)
|
24
|
-
|
25
|
-
if organization && is_admin?(current_user, organization)
|
26
|
-
# TODO
|
27
|
-
# Update organization with oauth params
|
28
|
-
end
|
29
|
-
|
30
|
-
redirect_to root_url
|
31
|
-
end
|
32
|
-
|
33
|
-
def destroy_omniauth
|
34
|
-
organization = Maestrano::Connector::Rails::Organization.find(params[:organization_id])
|
35
|
-
|
36
|
-
if organization && is_admin?(current_user, organization)
|
37
|
-
organization.oauth_uid = nil
|
38
|
-
organization.oauth_token = nil
|
39
|
-
organization.refresh_token = nil
|
40
|
-
organization.save
|
41
|
-
end
|
42
|
-
|
43
|
-
redirect_to root_url
|
44
|
-
end
|
45
|
-
end
|