maestrano-connector-rails 0.2.0 → 0.2.2
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 +4 -4
- data/DEVELOPER.md +1 -1
- data/README.md +5 -3
- data/VERSION +1 -1
- data/app/controllers/maestrano/connec_controller.rb +62 -0
- data/app/jobs/maestrano/connector/rails/synchronization_job.rb +1 -0
- data/app/models/maestrano/connector/rails/id_map.rb +0 -1
- data/app/models/maestrano/connector/rails/organization.rb +0 -1
- data/app/models/maestrano/connector/rails/synchronization.rb +0 -1
- data/app/models/maestrano/connector/rails/user.rb +0 -1
- data/app/models/maestrano/connector/rails/user_organization_rel.rb +0 -1
- data/config/routes.rb +3 -22
- data/db/migrate/20151122162100_create_users.rb +16 -0
- data/db/migrate/{20151122162414_create_maestrano_connector_rails_organizations.rb → 20151122162414_create_organizations.rb} +3 -3
- data/db/migrate/20151122162613_create_user_organization_rels.rb +12 -0
- data/db/migrate/20151122163325_create_synchronizations.rb +13 -0
- data/db/migrate/20151122163449_create_id_maps.rb +18 -0
- data/db/migrate/20160205132857_add_sync_enabled_to_organizations.rb +5 -0
- data/lib/generators/connector/install_generator.rb +2 -1
- data/lib/generators/connector/templates/admin_controller.rb +10 -0
- data/lib/generators/connector/templates/admin_index.html.erb +6 -2
- data/lib/generators/connector/templates/home_index.html.erb +6 -0
- data/maestrano-connector-rails.gemspec +23 -9
- data/spec/controllers/connec_controller_spec.rb +144 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20160204223447_create_users.maestrano_connector_rails_engine.rb +17 -0
- data/spec/dummy/db/migrate/20160204223448_create_organizations.maestrano_connector_rails_engine.rb +22 -0
- data/spec/dummy/db/migrate/20160204223449_create_user_organization_rels.maestrano_connector_rails_engine.rb +13 -0
- data/spec/dummy/db/migrate/20160204223450_create_synchronizations.maestrano_connector_rails_engine.rb +14 -0
- data/spec/dummy/db/migrate/20160204223451_create_id_maps.maestrano_connector_rails_engine.rb +19 -0
- data/spec/dummy/db/migrate/20160205133024_add_sync_enabled_to_organizations.maestrano_connector_rails_engine.rb +6 -0
- data/spec/dummy/db/schema.rb +17 -16
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/jobs/syncrhonization_job_spec.rb +33 -18
- data/spec/routing/connec_routing_spec.rb +12 -0
- data/spec/spec_helper.rb +3 -0
- data/template/factories.rb +23 -0
- data/template/gitignore +20 -0
- data/template/maestrano-connector-template.rb +85 -0
- data/template/spec_helper.rb +22 -0
- metadata +21 -7
- data/db/migrate/20151122162100_create_maestrano_connector_rails_users.rb +0 -16
- data/db/migrate/20151122162613_create_maestrano_connector_rails_user_organization_rels.rb +0 -12
- data/db/migrate/20151122163325_create_maestrano_connector_rails_synchronizations.rb +0 -13
- data/db/migrate/20151122163449_create_maestrano_connector_rails_id_maps.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb050d36d97af9d68812330c80a035c9c91fb28b
|
4
|
+
data.tar.gz: ebe39a369c26144236473fc9a9da62c381c95c62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0680266b20d2ceed8569d483d38788bd42afc935af499b1e94cfd3aa9534b066deca706d98ee60355b35321cd153cc6d30e238b3f517e2bff1ac73d4a0284ab
|
7
|
+
data.tar.gz: 1bdc3afa7d0e70a3b8752d1a0ba7650074249ecd1b17d7d2cd02ebf3efdf7f836f4ce90820a995064c4d3635f7ee51b070c792e669a75fb153102a7e1c19e8db
|
data/DEVELOPER.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
[ ](https://codeship.com/projects/132645)
|
2
|
+
|
1
3
|
<p align="center">
|
2
|
-
<img src="https://raw.github.com/
|
4
|
+
<img src="https://raw.github.com/maestrano/maestrano-connector-rails/master/maestrano.png" alt="Maestrano Logo">
|
3
5
|
<br/>
|
4
6
|
<br/>
|
5
7
|
</p>
|
@@ -29,7 +31,7 @@ Before integrating with us you will need an Connec!™ API ID and Connec!™ API
|
|
29
31
|
## Getting Started
|
30
32
|
Create a new rails application using the connector template
|
31
33
|
```console
|
32
|
-
rails new <project_name> -m https://raw.githubusercontent.com/Berardpi/maestrano-connector-
|
34
|
+
rails new <project_name> -m https://raw.githubusercontent.com/Berardpi/maestrano-connector-rails/master/template/maestrano-connector-template.rb
|
33
35
|
```
|
34
36
|
|
35
37
|
If and only if you have an error in the template's rails generate step, you'll need to re-run the following command in your project folder:
|
@@ -135,4 +137,4 @@ rails g connector:complex_entity
|
|
135
137
|
|
136
138
|
This will generate some example files demonstrating a 1 to 2 correspondance between Connec!™ person and external contact and lead data models.
|
137
139
|
|
138
|
-
The complex entities workflow uses two methods to pre-process data which you have to implements for each complex entity (see contact_and_lead.rb). They are called before the mapping step, and you can use them to perform any data model specific operations.
|
140
|
+
The complex entities workflow uses two methods to pre-process data which you have to implements for each complex entity (see contact_and_lead.rb). They are called before the mapping step, and you can use them to perform any data model specific operations.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Maestrano::ConnecController < Maestrano::Rails::WebHookController
|
2
|
+
|
3
|
+
def notifications
|
4
|
+
Rails.logger.debug "Received notification from Connec!: #{params}"
|
5
|
+
|
6
|
+
begin
|
7
|
+
params['notification'].each do |entity_name, entities|
|
8
|
+
if entity_instance_hash = find_entity_instance(entity_name)
|
9
|
+
entity_instance = entity_instance_hash[:instance]
|
10
|
+
|
11
|
+
entities.each do |entity|
|
12
|
+
if (organization = Maestrano::Connector::Rails::Organization.find_by(uid: entity[:group_id], tenant: params[:tenant])) && organization.oauth_uid
|
13
|
+
Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Received entity from Connec! webhook: Entity=#{entity_name}, Data=#{entity}")
|
14
|
+
if organization.sync_enabled && organization.synchronized_entities[entity_instance_hash[:name].to_sym]
|
15
|
+
external_client = Maestrano::Connector::Rails::External.get_client(organization)
|
16
|
+
|
17
|
+
# Build expected input for consolidate_and_map_data
|
18
|
+
if entity_instance_hash[:is_complex]
|
19
|
+
entity = Hash[ *entity_instance.connec_entities_names.collect{|name| name == entity_name.singularize ? [name, [entity]] : [ name, []]}.flatten(1) ]
|
20
|
+
entity_instance.consolidate_and_map_data(entity, Hash[ *entity_instance.external_entities_names.collect{|name| [ name, []]}.flatten(1) ], organization, {})
|
21
|
+
else
|
22
|
+
entity = [entity]
|
23
|
+
entity_instance.consolidate_and_map_data(entity, [], organization, {})
|
24
|
+
end
|
25
|
+
|
26
|
+
entity_instance.push_entities_to_external(external_client, entity, organization)
|
27
|
+
end
|
28
|
+
|
29
|
+
else
|
30
|
+
Rails.logger.warn "Received notification from Connec! for unknown group or group without oauth: #{entity['group_id']} (tenant: #{params[:tenant]})"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
else
|
34
|
+
Rails.logger.warn "Received notification from Connec! for unknow entity: #{entity_name}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
rescue => e
|
38
|
+
Rails.logger.warn("error processing notification #{e.message} - #{e.backtrace.join("\n")}")
|
39
|
+
end
|
40
|
+
|
41
|
+
head 200, content_type: "application/json"
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
def find_entity_instance(entity_name)
|
48
|
+
if Maestrano::Connector::Rails::Entity.entities_list.include?(entity_name.singularize)
|
49
|
+
return {instance: "Entities::#{entity_name.singularize.titleize.split.join}".constantize.new, is_complex: false, name: entity_name.singularize}
|
50
|
+
else
|
51
|
+
Maestrano::Connector::Rails::Entity.entities_list.each do |entity_name_from_list|
|
52
|
+
instance = "Entities::#{entity_name_from_list.singularize.titleize.split.join}".constantize.new
|
53
|
+
if instance.methods.include?('connec_entities_names'.to_sym)
|
54
|
+
return {instance: instance, is_complex: true, name: entity_name_from_list} if instance.connec_entities_names.include?(entity_name.singularize)
|
55
|
+
elsif instance.methods.include?('connec_entity_name'.to_sym)
|
56
|
+
return {instance: instance, is_complex: false, name: entity_name_from_list} if instance.connec_entity_name == entity_name.singularize
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
@@ -8,6 +8,7 @@ module Maestrano::Connector::Rails
|
|
8
8
|
# * :full_sync => true synchronization is performed without date filtering
|
9
9
|
# * :connec_preemption => true|false : preemption is always|never given to connec in case of conflict (if not set, the most recently updated entity is kept)
|
10
10
|
def perform(organization, opts)
|
11
|
+
return unless organization.sync_enabled
|
11
12
|
ConnectorLogger.log('info', organization, "Start synchronization, opts=#{opts}")
|
12
13
|
current_synchronization = Synchronization.create_running(organization)
|
13
14
|
|
data/config/routes.rb
CHANGED
@@ -1,28 +1,9 @@
|
|
1
1
|
Maestrano::Connector::Rails::Engine.routes.draw do
|
2
2
|
maestrano_routes
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# get '/maestrano/metadata', to: '/maestrano/rails/metadata#index'
|
8
|
-
# get '/maestrano/metadata/:tenant', to: '/maestrano/rails/metadata#index', as: 'tenant'
|
9
|
-
|
10
|
-
# namespace :maestrano do
|
11
|
-
# namespace :auth do
|
12
|
-
# resources :saml, only:[] do
|
13
|
-
# get 'init', on: :collection
|
14
|
-
# get 'init/:tenant', on: :collection, to: 'saml#init', as: 'tenant'
|
15
|
-
# post 'consume', on: :collection
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
|
19
|
-
# namespace :account do
|
20
|
-
# resources :groups, only: [:destroy] do
|
21
|
-
# resources :users, only: [:destroy], controller: 'group_users'
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
# end
|
25
|
-
#--------------------------------------------------------------------
|
4
|
+
namespace :maestrano do
|
5
|
+
post 'connec/notifications/:tenant' => 'connec#notifications'
|
6
|
+
end
|
26
7
|
|
27
8
|
match 'signout', to: 'sessions#destroy', as: 'signout', via: [:get, :post]
|
28
9
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :users do |t|
|
4
|
+
t.string :provider
|
5
|
+
t.string :uid
|
6
|
+
t.string :first_name
|
7
|
+
t.string :last_name
|
8
|
+
t.string :email
|
9
|
+
t.string :tenant
|
10
|
+
|
11
|
+
t.timestamps null: false
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :users, [:uid, :tenant], name: 'user_uid_index'
|
15
|
+
end
|
16
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class CreateOrganizations < ActiveRecord::Migration
|
2
2
|
def change
|
3
|
-
create_table :
|
3
|
+
create_table :organizations do |t|
|
4
4
|
t.string :provider
|
5
5
|
t.string :uid
|
6
6
|
t.string :name
|
@@ -16,6 +16,6 @@ class CreateMaestranoConnectorRailsOrganizations < ActiveRecord::Migration
|
|
16
16
|
|
17
17
|
t.timestamps null: false
|
18
18
|
end
|
19
|
-
add_index :
|
19
|
+
add_index :organizations, [:uid, :tenant], name: 'orga_uid_index'
|
20
20
|
end
|
21
21
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateUserOrganizationRels < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :user_organization_rels do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.integer :organization_id
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :user_organization_rels, :organization_id, name: 'rels_orga_index'
|
10
|
+
add_index :user_organization_rels, :user_id, name: 'rels_user_index'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSynchronizations < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :synchronizations do |t|
|
4
|
+
t.integer :organization_id
|
5
|
+
t.string :status
|
6
|
+
t.text :message
|
7
|
+
t.boolean :partial, default: false
|
8
|
+
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
add_index :synchronizations, :organization_id, name: 'synchronization_orga_id_index'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateIdMaps < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :id_maps do |t|
|
4
|
+
t.string :connec_id
|
5
|
+
t.string :connec_entity
|
6
|
+
t.string :external_id
|
7
|
+
t.string :external_entity
|
8
|
+
t.integer :organization_id
|
9
|
+
t.datetime :last_push_to_connec
|
10
|
+
t.datetime :last_push_to_external
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
add_index :id_maps, [:connec_id, :connec_entity, :organization_id], name: 'idmap_connec_index'
|
15
|
+
add_index :id_maps, [:external_id, :external_entity, :organization_id], name: 'idmap_external_index'
|
16
|
+
add_index :id_maps, :organization_id, name: 'idmap_organization_index'
|
17
|
+
end
|
18
|
+
end
|
@@ -30,7 +30,8 @@ module Connector
|
|
30
30
|
"get 'home/index' => 'home#index'",
|
31
31
|
"get 'admin/index' => 'admin#index'",
|
32
32
|
"put 'admin/update' => 'admin#update'",
|
33
|
-
"post 'admin/synchronize' => 'admin#synchronize'"
|
33
|
+
"post 'admin/synchronize' => 'admin#synchronize'",
|
34
|
+
"put 'admin/toggle_sync' => 'admin#toggle_sync'"
|
34
35
|
]
|
35
36
|
|
36
37
|
in_root do
|
@@ -41,6 +41,16 @@ class AdminController < ApplicationController
|
|
41
41
|
redirect_to root_path
|
42
42
|
end
|
43
43
|
|
44
|
+
def toggle_sync
|
45
|
+
if is_admin
|
46
|
+
current_organization = Maestrano::Connector::Rails::Organization.first
|
47
|
+
current_organization.update(sync_enabled: !current_organization.sync_enabled)
|
48
|
+
flash[:notice] = current_organization.sync_enabled ? 'Synchronization enabled' : 'Synchronization disabled'
|
49
|
+
end
|
50
|
+
|
51
|
+
redirect_to admin_index_path
|
52
|
+
end
|
53
|
+
|
44
54
|
private
|
45
55
|
def is_admin
|
46
56
|
current_user && current_organization && is_admin?(current_user, current_organization)
|
@@ -26,14 +26,18 @@ and functions available on the admin panel -->
|
|
26
26
|
</li>
|
27
27
|
</ul>
|
28
28
|
|
29
|
+
<h3>Enable or disable synchronizations</h3>
|
30
|
+
<%= "Synchronizations are currently #{@organization.sync_enabled ? 'enabled' : 'disabled'}." %>
|
31
|
+
<%= link_to "#{@organization.sync_enabled ? 'Disable' : 'Enable'} them", admin_toggle_sync_path, method: :put %>
|
32
|
+
|
29
33
|
<h3>Synchronized entities</h3>
|
30
|
-
<p>You can customize which entities are synchronized by the connector
|
34
|
+
<p>You can customize which entities are synchronized by the connector</p>
|
31
35
|
<%= form_tag admin_update_path(id: @organization.id), method: :put do %>
|
32
36
|
<% @organization.synchronized_entities.each do |k, v| %>
|
33
37
|
<label for="<%= k %>">#{k.to_s.humanize}</label>
|
34
38
|
<input checked="<%= v %>" id="<%= k %>" name="<%= k %>" type="checkbox"></input>
|
35
39
|
<% if v && @organization.oauth_uid %>
|
36
|
-
<%= link_to "Force a synchronization for #{k.to_s.pluralize} only", admin_synchronize_path(opts: {only_entities: [k.to_s]}), method: :post %>
|
40
|
+
<%= link_to "Force a synchronization for #{k.to_s.humanize.pluralize} only", admin_synchronize_path(opts: {only_entities: [k.to_s]}), method: :post %>
|
37
41
|
<% end %>
|
38
42
|
<% end %>
|
39
43
|
<%= submit_tag :Update%>
|
@@ -18,6 +18,12 @@ can be displayed on the home page -->
|
|
18
18
|
Linked to external app
|
19
19
|
<% end %>
|
20
20
|
|
21
|
+
<% if !@organization.sync_enabled %>
|
22
|
+
Synchronizations are currently disabled. Go to the
|
23
|
+
<%= link_to " admin panel", admin_index_path %>
|
24
|
+
to enable them.
|
25
|
+
<% end %>
|
26
|
+
|
21
27
|
<h2>Last synchronization</h2>
|
22
28
|
<% if @synchronizations.first %>
|
23
29
|
<%= "#{@synchronizations.first.updated_at} #{@synchronizations.first.status}" %>
|
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: maestrano-connector-rails 0.2.
|
5
|
+
# stub: maestrano-connector-rails 0.2.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "maestrano-connector-rails"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Pierre Berard"]
|
14
|
-
s.date = "2016-02-
|
14
|
+
s.date = "2016-02-08"
|
15
15
|
s.description = "Maestrano is the next generation marketplace for SME applications. See https://maestrano.com for details."
|
16
16
|
s.email = "pierre.berard@maestrano.com"
|
17
17
|
s.executables = ["rails"]
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"app/controllers/maestrano/account/groups_controller.rb",
|
33
33
|
"app/controllers/maestrano/application_controller.rb",
|
34
34
|
"app/controllers/maestrano/auth/saml_controller.rb",
|
35
|
+
"app/controllers/maestrano/connec_controller.rb",
|
35
36
|
"app/controllers/maestrano/sessions_controller.rb",
|
36
37
|
"app/helpers/maestrano/connector/rails/session_helper.rb",
|
37
38
|
"app/jobs/maestrano/connector/rails/synchronization_job.rb",
|
@@ -49,11 +50,12 @@ Gem::Specification.new do |s|
|
|
49
50
|
"app/models/maestrano/connector/rails/user_organization_rel.rb",
|
50
51
|
"bin/rails",
|
51
52
|
"config/routes.rb",
|
52
|
-
"db/migrate/
|
53
|
-
"db/migrate/
|
54
|
-
"db/migrate/
|
55
|
-
"db/migrate/
|
56
|
-
"db/migrate/
|
53
|
+
"db/migrate/20151122162100_create_users.rb",
|
54
|
+
"db/migrate/20151122162414_create_organizations.rb",
|
55
|
+
"db/migrate/20151122162613_create_user_organization_rels.rb",
|
56
|
+
"db/migrate/20151122163325_create_synchronizations.rb",
|
57
|
+
"db/migrate/20151122163449_create_id_maps.rb",
|
58
|
+
"db/migrate/20160205132857_add_sync_enabled_to_organizations.rb",
|
57
59
|
"lib/generators/connector/USAGE",
|
58
60
|
"lib/generators/connector/complex_entity_generator.rb",
|
59
61
|
"lib/generators/connector/install_generator.rb",
|
@@ -77,6 +79,7 @@ Gem::Specification.new do |s|
|
|
77
79
|
"maestrano-connector-rails.gemspec",
|
78
80
|
"maestrano.png",
|
79
81
|
"pkg/maestrano-connector-rails-0.0.1.gem",
|
82
|
+
"spec/controllers/connec_controller_spec.rb",
|
80
83
|
"spec/dummy/README.md",
|
81
84
|
"spec/dummy/Rakefile",
|
82
85
|
"spec/dummy/app/assets/images/.keep",
|
@@ -122,6 +125,12 @@ Gem::Specification.new do |s|
|
|
122
125
|
"spec/dummy/config/routes.rb",
|
123
126
|
"spec/dummy/config/secrets.yml",
|
124
127
|
"spec/dummy/db/development.sqlite3",
|
128
|
+
"spec/dummy/db/migrate/20160204223447_create_users.maestrano_connector_rails_engine.rb",
|
129
|
+
"spec/dummy/db/migrate/20160204223448_create_organizations.maestrano_connector_rails_engine.rb",
|
130
|
+
"spec/dummy/db/migrate/20160204223449_create_user_organization_rels.maestrano_connector_rails_engine.rb",
|
131
|
+
"spec/dummy/db/migrate/20160204223450_create_synchronizations.maestrano_connector_rails_engine.rb",
|
132
|
+
"spec/dummy/db/migrate/20160204223451_create_id_maps.maestrano_connector_rails_engine.rb",
|
133
|
+
"spec/dummy/db/migrate/20160205133024_add_sync_enabled_to_organizations.maestrano_connector_rails_engine.rb",
|
125
134
|
"spec/dummy/db/schema.rb",
|
126
135
|
"spec/dummy/db/test.sqlite3",
|
127
136
|
"spec/dummy/lib/assets/.keep",
|
@@ -142,7 +151,12 @@ Gem::Specification.new do |s|
|
|
142
151
|
"spec/models/synchronization_spec.rb",
|
143
152
|
"spec/models/user_organization_rel_spec.rb",
|
144
153
|
"spec/models/user_spec.rb",
|
145
|
-
"spec/
|
154
|
+
"spec/routing/connec_routing_spec.rb",
|
155
|
+
"spec/spec_helper.rb",
|
156
|
+
"template/factories.rb",
|
157
|
+
"template/gitignore",
|
158
|
+
"template/maestrano-connector-template.rb",
|
159
|
+
"template/spec_helper.rb"
|
146
160
|
]
|
147
161
|
s.homepage = "http://github.com/maestrano/maestrano-connector-rails"
|
148
162
|
s.licenses = ["MIT"]
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Maestrano::ConnecController, type: :controller do
|
4
|
+
routes { Maestrano::Connector::Rails::Engine.routes }
|
5
|
+
|
6
|
+
describe 'notifications' do
|
7
|
+
let(:notif) { {} }
|
8
|
+
let(:group_id) { 'cld_333' }
|
9
|
+
let(:entity) { {group_id: group_id, last_name: 'Georges', first_name: 'Teddy'} }
|
10
|
+
subject { post :notifications, tenant: 'default', notification: notif }
|
11
|
+
|
12
|
+
context 'without authentication' do
|
13
|
+
before {
|
14
|
+
controller.class.before_filter :authenticate_maestrano!
|
15
|
+
}
|
16
|
+
|
17
|
+
it 'respond with unauthorized' do
|
18
|
+
subject
|
19
|
+
expect(response.status).to eq(401)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'with authentication' do
|
24
|
+
before {
|
25
|
+
controller.class.skip_before_filter :authenticate_maestrano!
|
26
|
+
}
|
27
|
+
|
28
|
+
it 'is a success' do
|
29
|
+
subject
|
30
|
+
expect(response.status).to eq(200)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with an unknown entity" do
|
34
|
+
let(:notif) { {people: [entity]} }
|
35
|
+
before {
|
36
|
+
allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return(%w())
|
37
|
+
}
|
38
|
+
|
39
|
+
it 'logs a warning' do
|
40
|
+
expect(Rails.logger).to receive(:warn).with('Received notification from Connec! for unknow entity: people')
|
41
|
+
subject
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with a known complex entity" do
|
46
|
+
let(:notif) { {lead: [entity]} }
|
47
|
+
|
48
|
+
before {
|
49
|
+
allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return(%w(contact_and_lead))
|
50
|
+
class Entities::ContactAndLead < Maestrano::Connector::Rails::ComplexEntity
|
51
|
+
def connec_entities_names
|
52
|
+
%w(lead)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
module Entities::SubEntities end;
|
56
|
+
class Entities::SubEntities::Lead < Maestrano::Connector::Rails::SubEntityBase
|
57
|
+
end
|
58
|
+
}
|
59
|
+
|
60
|
+
it 'looks for an organization' do
|
61
|
+
expect(Maestrano::Connector::Rails::Organization).to receive(:find_by).with(uid: group_id, tenant: 'default')
|
62
|
+
subject
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when syncing' do
|
66
|
+
before {
|
67
|
+
allow_any_instance_of(Entities::ContactAndLead).to receive(:external_entities_names).and_return(%w())
|
68
|
+
}
|
69
|
+
let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: true, synchronized_entities: {contact_and_lead: true}) }
|
70
|
+
|
71
|
+
it 'process the data and push them' do
|
72
|
+
expect_any_instance_of(Entities::ContactAndLead).to receive(:consolidate_and_map_data).with({"lead"=>[entity]}, {}, organization, {})
|
73
|
+
expect_any_instance_of(Entities::ContactAndLead).to receive(:push_entities_to_external)
|
74
|
+
subject
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with a known non complex entity" do
|
80
|
+
let(:notif) { {people: [entity]} }
|
81
|
+
|
82
|
+
before {
|
83
|
+
allow(Maestrano::Connector::Rails::Entity).to receive(:entities_list).and_return(%w(person))
|
84
|
+
class Entities::Person < Maestrano::Connector::Rails::Entity
|
85
|
+
end
|
86
|
+
}
|
87
|
+
|
88
|
+
it 'looks for an organization' do
|
89
|
+
expect(Maestrano::Connector::Rails::Organization).to receive(:find_by).with(uid: group_id, tenant: 'default')
|
90
|
+
subject
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'with an invalid organization' do
|
94
|
+
context 'with no organization' do
|
95
|
+
it 'logs a warning' do
|
96
|
+
expect(Rails.logger).to receive(:warn).with("Received notification from Connec! for unknown group or group without oauth: #{group_id} (tenant: default)")
|
97
|
+
subject
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'with an organization with no oauth' do
|
102
|
+
let!(:organization) { create(:organization, uid: group_id, oauth_uid: nil) }
|
103
|
+
|
104
|
+
it 'logs a warning' do
|
105
|
+
expect(Rails.logger).to receive(:warn).with("Received notification from Connec! for unknown group or group without oauth: #{group_id} (tenant: default)")
|
106
|
+
subject
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'with a valid organization' do
|
112
|
+
context 'with sync disabled' do
|
113
|
+
let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: false, synchronized_entities: {person: true}) }
|
114
|
+
|
115
|
+
it 'does nothing' do
|
116
|
+
expect(Maestrano::Connector::Rails::External).to_not receive(:get_client).with(organization)
|
117
|
+
subject
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'with sync disabled for this entity' do
|
122
|
+
let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: true, synchronized_entities: {person: false}) }
|
123
|
+
|
124
|
+
it 'does nothing' do
|
125
|
+
expect(Maestrano::Connector::Rails::External).to_not receive(:get_client).with(organization)
|
126
|
+
subject
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "when syncing" do
|
131
|
+
let!(:organization) { create(:organization, uid: group_id, oauth_uid: 'lala', sync_enabled: true, synchronized_entities: {person: true}) }
|
132
|
+
|
133
|
+
it 'process the data and push them' do
|
134
|
+
expect_any_instance_of(Entities::Person).to receive(:consolidate_and_map_data).with([entity], [], organization, {})
|
135
|
+
expect_any_instance_of(Entities::Person).to receive(:push_entities_to_external)
|
136
|
+
subject
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This migration comes from maestrano_connector_rails_engine (originally 20151122162100)
|
2
|
+
class CreateUsers < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :users do |t|
|
5
|
+
t.string :provider
|
6
|
+
t.string :uid
|
7
|
+
t.string :first_name
|
8
|
+
t.string :last_name
|
9
|
+
t.string :email
|
10
|
+
t.string :tenant
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :users, [:uid, :tenant], name: 'user_uid_index'
|
16
|
+
end
|
17
|
+
end
|
data/spec/dummy/db/migrate/20160204223448_create_organizations.maestrano_connector_rails_engine.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This migration comes from maestrano_connector_rails_engine (originally 20151122162414)
|
2
|
+
class CreateOrganizations < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :organizations do |t|
|
5
|
+
t.string :provider
|
6
|
+
t.string :uid
|
7
|
+
t.string :name
|
8
|
+
t.string :tenant
|
9
|
+
|
10
|
+
t.string :oauth_provider
|
11
|
+
t.string :oauth_uid
|
12
|
+
t.string :oauth_token
|
13
|
+
t.string :refresh_token
|
14
|
+
t.string :instance_url
|
15
|
+
|
16
|
+
t.string :synchronized_entities
|
17
|
+
|
18
|
+
t.timestamps null: false
|
19
|
+
end
|
20
|
+
add_index :organizations, [:uid, :tenant], name: 'orga_uid_index'
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# This migration comes from maestrano_connector_rails_engine (originally 20151122162613)
|
2
|
+
class CreateUserOrganizationRels < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :user_organization_rels do |t|
|
5
|
+
t.integer :user_id
|
6
|
+
t.integer :organization_id
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :user_organization_rels, :organization_id, name: 'rels_orga_index'
|
11
|
+
add_index :user_organization_rels, :user_id, name: 'rels_user_index'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This migration comes from maestrano_connector_rails_engine (originally 20151122163325)
|
2
|
+
class CreateSynchronizations < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :synchronizations do |t|
|
5
|
+
t.integer :organization_id
|
6
|
+
t.string :status
|
7
|
+
t.text :message
|
8
|
+
t.boolean :partial, default: false
|
9
|
+
|
10
|
+
t.timestamps null: false
|
11
|
+
end
|
12
|
+
add_index :synchronizations, :organization_id, name: 'synchronization_orga_id_index'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# This migration comes from maestrano_connector_rails_engine (originally 20151122163449)
|
2
|
+
class CreateIdMaps < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :id_maps do |t|
|
5
|
+
t.string :connec_id
|
6
|
+
t.string :connec_entity
|
7
|
+
t.string :external_id
|
8
|
+
t.string :external_entity
|
9
|
+
t.integer :organization_id
|
10
|
+
t.datetime :last_push_to_connec
|
11
|
+
t.datetime :last_push_to_external
|
12
|
+
|
13
|
+
t.timestamps null: false
|
14
|
+
end
|
15
|
+
add_index :id_maps, [:connec_id, :connec_entity, :organization_id], name: 'idmap_connec_index'
|
16
|
+
add_index :id_maps, [:external_id, :external_entity, :organization_id], name: 'idmap_external_index'
|
17
|
+
add_index :id_maps, :organization_id, name: 'idmap_organization_index'
|
18
|
+
end
|
19
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,9 +11,9 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20160205133024) do
|
15
15
|
|
16
|
-
create_table "
|
16
|
+
create_table "id_maps", force: :cascade do |t|
|
17
17
|
t.string "connec_id"
|
18
18
|
t.string "connec_entity"
|
19
19
|
t.string "external_id"
|
@@ -25,11 +25,11 @@ ActiveRecord::Schema.define(version: 20151122163449) do
|
|
25
25
|
t.datetime "updated_at", null: false
|
26
26
|
end
|
27
27
|
|
28
|
-
add_index "
|
29
|
-
add_index "
|
30
|
-
add_index "
|
28
|
+
add_index "id_maps", ["connec_id", "connec_entity", "organization_id"], name: "idmap_connec_index"
|
29
|
+
add_index "id_maps", ["external_id", "external_entity", "organization_id"], name: "idmap_external_index"
|
30
|
+
add_index "id_maps", ["organization_id"], name: "idmap_organization_index"
|
31
31
|
|
32
|
-
create_table "
|
32
|
+
create_table "organizations", force: :cascade do |t|
|
33
33
|
t.string "provider"
|
34
34
|
t.string "uid"
|
35
35
|
t.string "name"
|
@@ -40,13 +40,14 @@ ActiveRecord::Schema.define(version: 20151122163449) do
|
|
40
40
|
t.string "refresh_token"
|
41
41
|
t.string "instance_url"
|
42
42
|
t.string "synchronized_entities"
|
43
|
-
t.datetime "created_at",
|
44
|
-
t.datetime "updated_at",
|
43
|
+
t.datetime "created_at", null: false
|
44
|
+
t.datetime "updated_at", null: false
|
45
|
+
t.boolean "sync_enabled", default: false
|
45
46
|
end
|
46
47
|
|
47
|
-
add_index "
|
48
|
+
add_index "organizations", ["uid", "tenant"], name: "orga_uid_index"
|
48
49
|
|
49
|
-
create_table "
|
50
|
+
create_table "synchronizations", force: :cascade do |t|
|
50
51
|
t.integer "organization_id"
|
51
52
|
t.string "status"
|
52
53
|
t.text "message"
|
@@ -55,19 +56,19 @@ ActiveRecord::Schema.define(version: 20151122163449) do
|
|
55
56
|
t.datetime "updated_at", null: false
|
56
57
|
end
|
57
58
|
|
58
|
-
add_index "
|
59
|
+
add_index "synchronizations", ["organization_id"], name: "synchronization_orga_id_index"
|
59
60
|
|
60
|
-
create_table "
|
61
|
+
create_table "user_organization_rels", force: :cascade do |t|
|
61
62
|
t.integer "user_id"
|
62
63
|
t.integer "organization_id"
|
63
64
|
t.datetime "created_at"
|
64
65
|
t.datetime "updated_at"
|
65
66
|
end
|
66
67
|
|
67
|
-
add_index "
|
68
|
-
add_index "
|
68
|
+
add_index "user_organization_rels", ["organization_id"], name: "rels_orga_index"
|
69
|
+
add_index "user_organization_rels", ["user_id"], name: "rels_user_index"
|
69
70
|
|
70
|
-
create_table "
|
71
|
+
create_table "users", force: :cascade do |t|
|
71
72
|
t.string "provider"
|
72
73
|
t.string "uid"
|
73
74
|
t.string "first_name"
|
@@ -78,6 +79,6 @@ ActiveRecord::Schema.define(version: 20151122163449) do
|
|
78
79
|
t.datetime "updated_at", null: false
|
79
80
|
end
|
80
81
|
|
81
|
-
add_index "
|
82
|
+
add_index "users", ["uid", "tenant"], name: "user_uid_index"
|
82
83
|
|
83
84
|
end
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -3,32 +3,47 @@ require 'spec_helper'
|
|
3
3
|
describe Maestrano::Connector::Rails::SynchronizationJob do
|
4
4
|
let(:organization) { create(:organization) }
|
5
5
|
subject { Maestrano::Connector::Rails::SynchronizationJob.perform_now(organization, {}) }
|
6
|
-
|
6
|
+
|
7
7
|
describe 'perform' do
|
8
|
-
|
9
|
-
|
8
|
+
context 'with sync_enabled set to false' do
|
9
|
+
it 'does not creates a syncrhonization' do
|
10
|
+
expect{ subject }.to change{ Maestrano::Connector::Rails::Synchronization.count }.by(0)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'does not calls sync entity' do
|
14
|
+
expect_any_instance_of(Maestrano::Connector::Rails::SynchronizationJob).to_not receive(:sync_entity)
|
15
|
+
subject
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
|
-
|
13
|
-
organization.
|
14
|
-
expect_any_instance_of(Maestrano::Connector::Rails::SynchronizationJob).to receive(:sync_entity).exactly(organization.synchronized_entities.count - 1).times
|
19
|
+
context 'with sync_enabled set to true' do
|
20
|
+
before {organization.update(sync_enabled: true)}
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
it 'creates a synchronization' do
|
23
|
+
expect{ subject }.to change{ Maestrano::Connector::Rails::Synchronization.count }.by(1)
|
24
|
+
end
|
18
25
|
|
19
|
-
|
20
|
-
|
21
|
-
|
26
|
+
it 'calls sync entity on all the organization synchronized entities set to true' do
|
27
|
+
organization.synchronized_entities[organization.synchronized_entities.keys.first] = false
|
28
|
+
expect_any_instance_of(Maestrano::Connector::Rails::SynchronizationJob).to receive(:sync_entity).exactly(organization.synchronized_entities.count - 1).times
|
22
29
|
|
23
|
-
|
24
|
-
|
30
|
+
subject
|
31
|
+
end
|
25
32
|
|
26
|
-
|
27
|
-
|
33
|
+
context 'with options' do
|
34
|
+
context 'with only_entities' do
|
35
|
+
subject { Maestrano::Connector::Rails::SynchronizationJob.perform_now(organization, {only_entities: %w(people price)}) }
|
36
|
+
|
37
|
+
it 'calls sync entity on the specified entities' do
|
38
|
+
expect_any_instance_of(Maestrano::Connector::Rails::SynchronizationJob).to receive(:sync_entity).twice
|
39
|
+
|
40
|
+
subject
|
41
|
+
end
|
28
42
|
|
29
|
-
|
30
|
-
|
31
|
-
|
43
|
+
it 'set the current syncrhonization as partial' do
|
44
|
+
subject
|
45
|
+
expect(Maestrano::Connector::Rails::Synchronization.last.partial).to be(true)
|
46
|
+
end
|
32
47
|
end
|
33
48
|
end
|
34
49
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Maestrano::ConnecController, type: :controller do
|
4
|
+
routes { Maestrano::Connector::Rails::Engine.routes }
|
5
|
+
|
6
|
+
describe "routing" do
|
7
|
+
|
8
|
+
it "routes to #notifications" do
|
9
|
+
expect(:post => '/maestrano/connec/notifications/default').to route_to("maestrano/connec#notifications", tenant: 'default')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,8 @@ 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'
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start
|
7
9
|
|
8
10
|
Rails.backtrace_cleaner.remove_silencers!
|
9
11
|
|
@@ -16,4 +18,5 @@ RSpec.configure do |config|
|
|
16
18
|
config.infer_base_class_for_anonymous_controllers = false
|
17
19
|
config.order = "random"
|
18
20
|
config.include FactoryGirl::Syntax::Methods
|
21
|
+
config.include Maestrano::Connector::Rails::Engine.routes.url_helpers
|
19
22
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
|
3
|
+
factory :organization, class: Maestrano::Connector::Rails::Organization do
|
4
|
+
name "My company"
|
5
|
+
tenant "default"
|
6
|
+
end
|
7
|
+
|
8
|
+
factory :idmap, class: Maestrano::Connector::Rails::IdMap do
|
9
|
+
connec_id '6798-ada6-te43'
|
10
|
+
connec_entity 'person'
|
11
|
+
external_id '4567ada66'
|
12
|
+
external_entity 'contact'
|
13
|
+
last_push_to_external 2.day.ago
|
14
|
+
last_push_to_connec 1.day.ago
|
15
|
+
association :organization
|
16
|
+
end
|
17
|
+
|
18
|
+
factory :synchronization, class: Maestrano::Connector::Rails::Synchronization do
|
19
|
+
association :organization
|
20
|
+
status 'SUCCESS'
|
21
|
+
partial false
|
22
|
+
end
|
23
|
+
end
|
data/template/gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*
|
16
|
+
!/log/.keep
|
17
|
+
/tmp
|
18
|
+
|
19
|
+
# Ignore coverage files
|
20
|
+
coverage/
|
@@ -0,0 +1,85 @@
|
|
1
|
+
def current_directory
|
2
|
+
@current_directory ||=
|
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/berardpi/maestrano-connector-rails.git #{tempdir}"
|
7
|
+
|
8
|
+
"#{tempdir}/template"
|
9
|
+
else
|
10
|
+
File.expand_path(File.dirname(__FILE__))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# def current_directory
|
15
|
+
# File.expand_path(File.dirname(__FILE__))
|
16
|
+
# end
|
17
|
+
|
18
|
+
# Add the current directory to the path Thor uses
|
19
|
+
# to look up files
|
20
|
+
def source_paths
|
21
|
+
Array(super) + [current_directory]
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Rebuild the Gemfile from scratch
|
26
|
+
#
|
27
|
+
remove_file 'Gemfile'
|
28
|
+
run 'touch Gemfile'
|
29
|
+
|
30
|
+
add_source 'https://rubygems.org'
|
31
|
+
|
32
|
+
gem 'rails', '4.2.4'
|
33
|
+
gem 'turbolinks'
|
34
|
+
gem 'jquery-rails'
|
35
|
+
gem 'puma'
|
36
|
+
gem 'figaro'
|
37
|
+
gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]
|
38
|
+
|
39
|
+
gem 'maestrano-connector-rails'
|
40
|
+
gem 'delayed_job_active_record'
|
41
|
+
|
42
|
+
gem 'sqlite3'
|
43
|
+
|
44
|
+
gem_group :test do
|
45
|
+
gem 'simplecov'
|
46
|
+
gem 'rspec-rails'
|
47
|
+
gem 'factory_girl_rails'
|
48
|
+
gem 'shoulda-matchers'
|
49
|
+
gem 'timecop'
|
50
|
+
end
|
51
|
+
|
52
|
+
remove_file '.gitignore'
|
53
|
+
copy_file 'gitignore', '.gitignore'
|
54
|
+
|
55
|
+
|
56
|
+
#
|
57
|
+
# Cleanup
|
58
|
+
#
|
59
|
+
after_bundle do
|
60
|
+
remove_dir 'app/mailers'
|
61
|
+
remove_dir 'test'
|
62
|
+
copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
|
63
|
+
copy_file 'factories.rb', 'spec/factories.rb'
|
64
|
+
|
65
|
+
application do <<-RUBY
|
66
|
+
config.generators do |g|
|
67
|
+
g.test_framework :rspec, fixture: false
|
68
|
+
g.view_specs false
|
69
|
+
g.helper_specs false
|
70
|
+
end
|
71
|
+
RUBY
|
72
|
+
end
|
73
|
+
|
74
|
+
run 'rails g maestrano:initializer'
|
75
|
+
run 'rails g connector:install'
|
76
|
+
run 'bundle exec figaro install'
|
77
|
+
run 'rake railties:install:migrations'
|
78
|
+
run 'rails g delayed_job:active_record'
|
79
|
+
run 'rake db:migrate'
|
80
|
+
|
81
|
+
# Init repo and commit
|
82
|
+
git :init
|
83
|
+
git add: "."
|
84
|
+
git commit: "-a -m 'Initial commit'"
|
85
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
|
6
|
+
require File.expand_path("../../config/environment", __FILE__)
|
7
|
+
require 'rspec/rails'
|
8
|
+
require 'factory_girl_rails'
|
9
|
+
require 'shoulda/matchers'
|
10
|
+
|
11
|
+
Rails.backtrace_cleaner.remove_silencers!
|
12
|
+
|
13
|
+
# Load support files
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.mock_with :rspec
|
18
|
+
config.use_transactional_fixtures = true
|
19
|
+
config.infer_base_class_for_anonymous_controllers = false
|
20
|
+
config.order = "random"
|
21
|
+
config.include FactoryGirl::Syntax::Methods
|
22
|
+
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: 0.2.
|
4
|
+
version: 0.2.2
|
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-02-
|
11
|
+
date: 2016-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: maestrano-rails
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- app/controllers/maestrano/account/groups_controller.rb
|
201
201
|
- app/controllers/maestrano/application_controller.rb
|
202
202
|
- app/controllers/maestrano/auth/saml_controller.rb
|
203
|
+
- app/controllers/maestrano/connec_controller.rb
|
203
204
|
- app/controllers/maestrano/sessions_controller.rb
|
204
205
|
- app/helpers/maestrano/connector/rails/session_helper.rb
|
205
206
|
- app/jobs/maestrano/connector/rails/synchronization_job.rb
|
@@ -217,11 +218,12 @@ files:
|
|
217
218
|
- app/models/maestrano/connector/rails/user_organization_rel.rb
|
218
219
|
- bin/rails
|
219
220
|
- config/routes.rb
|
220
|
-
- db/migrate/
|
221
|
-
- db/migrate/
|
222
|
-
- db/migrate/
|
223
|
-
- db/migrate/
|
224
|
-
- db/migrate/
|
221
|
+
- db/migrate/20151122162100_create_users.rb
|
222
|
+
- db/migrate/20151122162414_create_organizations.rb
|
223
|
+
- db/migrate/20151122162613_create_user_organization_rels.rb
|
224
|
+
- db/migrate/20151122163325_create_synchronizations.rb
|
225
|
+
- db/migrate/20151122163449_create_id_maps.rb
|
226
|
+
- db/migrate/20160205132857_add_sync_enabled_to_organizations.rb
|
225
227
|
- lib/generators/connector/USAGE
|
226
228
|
- lib/generators/connector/complex_entity_generator.rb
|
227
229
|
- lib/generators/connector/install_generator.rb
|
@@ -245,6 +247,7 @@ files:
|
|
245
247
|
- maestrano-connector-rails.gemspec
|
246
248
|
- maestrano.png
|
247
249
|
- pkg/maestrano-connector-rails-0.0.1.gem
|
250
|
+
- spec/controllers/connec_controller_spec.rb
|
248
251
|
- spec/dummy/README.md
|
249
252
|
- spec/dummy/Rakefile
|
250
253
|
- spec/dummy/app/assets/images/.keep
|
@@ -290,6 +293,12 @@ files:
|
|
290
293
|
- spec/dummy/config/routes.rb
|
291
294
|
- spec/dummy/config/secrets.yml
|
292
295
|
- spec/dummy/db/development.sqlite3
|
296
|
+
- spec/dummy/db/migrate/20160204223447_create_users.maestrano_connector_rails_engine.rb
|
297
|
+
- spec/dummy/db/migrate/20160204223448_create_organizations.maestrano_connector_rails_engine.rb
|
298
|
+
- spec/dummy/db/migrate/20160204223449_create_user_organization_rels.maestrano_connector_rails_engine.rb
|
299
|
+
- spec/dummy/db/migrate/20160204223450_create_synchronizations.maestrano_connector_rails_engine.rb
|
300
|
+
- spec/dummy/db/migrate/20160204223451_create_id_maps.maestrano_connector_rails_engine.rb
|
301
|
+
- spec/dummy/db/migrate/20160205133024_add_sync_enabled_to_organizations.maestrano_connector_rails_engine.rb
|
293
302
|
- spec/dummy/db/schema.rb
|
294
303
|
- spec/dummy/db/test.sqlite3
|
295
304
|
- spec/dummy/lib/assets/.keep
|
@@ -310,7 +319,12 @@ files:
|
|
310
319
|
- spec/models/synchronization_spec.rb
|
311
320
|
- spec/models/user_organization_rel_spec.rb
|
312
321
|
- spec/models/user_spec.rb
|
322
|
+
- spec/routing/connec_routing_spec.rb
|
313
323
|
- spec/spec_helper.rb
|
324
|
+
- template/factories.rb
|
325
|
+
- template/gitignore
|
326
|
+
- template/maestrano-connector-template.rb
|
327
|
+
- template/spec_helper.rb
|
314
328
|
homepage: http://github.com/maestrano/maestrano-connector-rails
|
315
329
|
licenses:
|
316
330
|
- MIT
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class CreateMaestranoConnectorRailsUsers < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :maestrano_connector_rails_users do |t|
|
4
|
-
t.string :provider
|
5
|
-
t.string :uid
|
6
|
-
t.string :first_name
|
7
|
-
t.string :last_name
|
8
|
-
t.string :email
|
9
|
-
t.string :tenant
|
10
|
-
|
11
|
-
t.timestamps null: false
|
12
|
-
end
|
13
|
-
|
14
|
-
add_index :maestrano_connector_rails_users, [:uid, :tenant], name: 'user_uid_index'
|
15
|
-
end
|
16
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class CreateMaestranoConnectorRailsUserOrganizationRels < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :maestrano_connector_rails_user_organization_rels do |t|
|
4
|
-
t.integer :user_id
|
5
|
-
t.integer :organization_id
|
6
|
-
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
add_index :maestrano_connector_rails_user_organization_rels, :organization_id, name: 'rels_orga_index'
|
10
|
-
add_index :maestrano_connector_rails_user_organization_rels, :user_id, name: 'rels_user_index'
|
11
|
-
end
|
12
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateMaestranoConnectorRailsSynchronizations < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :maestrano_connector_rails_synchronizations do |t|
|
4
|
-
t.integer :organization_id
|
5
|
-
t.string :status
|
6
|
-
t.text :message
|
7
|
-
t.boolean :partial, default: false
|
8
|
-
|
9
|
-
t.timestamps null: false
|
10
|
-
end
|
11
|
-
add_index :maestrano_connector_rails_synchronizations, :organization_id, name: 'synchronization_orga_id_index'
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateMaestranoConnectorRailsIdMaps < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :maestrano_connector_rails_id_maps do |t|
|
4
|
-
t.string :connec_id
|
5
|
-
t.string :connec_entity
|
6
|
-
t.string :external_id
|
7
|
-
t.string :external_entity
|
8
|
-
t.integer :organization_id
|
9
|
-
t.datetime :last_push_to_connec
|
10
|
-
t.datetime :last_push_to_external
|
11
|
-
|
12
|
-
t.timestamps null: false
|
13
|
-
end
|
14
|
-
add_index :maestrano_connector_rails_id_maps, [:connec_id, :connec_entity, :organization_id], name: 'idmap_connec_index'
|
15
|
-
add_index :maestrano_connector_rails_id_maps, [:external_id, :external_entity, :organization_id], name: 'idmap_external_index'
|
16
|
-
add_index :maestrano_connector_rails_id_maps, :organization_id, name: 'idmap_organization_index'
|
17
|
-
end
|
18
|
-
end
|