maestrano-connector-rails 0.2.16 → 0.2.17

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +27 -0
  4. data/VERSION +1 -1
  5. data/app/helpers/maestrano/connector/rails/session_helper.rb +5 -1
  6. data/app/models/maestrano/connector/rails/complex_entity.rb +14 -33
  7. data/app/models/maestrano/connector/rails/concerns/entity.rb +161 -73
  8. data/app/models/maestrano/connector/rails/sub_entity_base.rb +44 -4
  9. data/lib/generators/connector/install_generator.rb +20 -24
  10. data/lib/generators/connector/templates/home_controller.rb +33 -10
  11. data/lib/generators/connector/templates/home_controller_spec.rb +141 -0
  12. data/lib/generators/connector/templates/home_index.haml +103 -0
  13. data/lib/generators/connector/templates/layouts.haml +45 -0
  14. data/lib/generators/connector/templates/oauth_controller.rb +3 -6
  15. data/lib/generators/connector/templates/shared_entities_controller.rb +7 -0
  16. data/lib/generators/connector/templates/shared_entities_controller_spec.rb +23 -0
  17. data/lib/generators/connector/templates/shared_entities_index.haml +41 -0
  18. data/lib/generators/connector/templates/stylesheets/application.sass +24 -0
  19. data/lib/generators/connector/templates/stylesheets/banners.sass +59 -0
  20. data/lib/generators/connector/templates/stylesheets/home.sass +25 -0
  21. data/lib/generators/connector/templates/stylesheets/layout.sass +125 -0
  22. data/lib/generators/connector/templates/stylesheets/spacers.sass +46 -0
  23. data/lib/generators/connector/templates/stylesheets/variables.sass +57 -0
  24. data/lib/generators/connector/templates/sychronizations_controller_spec.rb +22 -0
  25. data/lib/generators/connector/templates/synchronizations_controller.rb +7 -0
  26. data/lib/generators/connector/templates/synchronizations_index.haml +42 -0
  27. data/maestrano-connector-rails.gemspec +29 -6
  28. data/pkg/maestrano-connector-rails-0.2.16.gem +0 -0
  29. data/spec/models/complex_entity_spec.rb +46 -12
  30. data/spec/models/entity_spec.rb +212 -113
  31. data/spec/models/sub_entity_base_spec.rb +59 -0
  32. data/template/maestrano-connector-template.rb +4 -3
  33. data/template/routes.rb +14 -0
  34. metadata +61 -5
  35. data/lib/generators/connector/templates/admin_controller.rb +0 -58
  36. data/lib/generators/connector/templates/admin_index.html.erb +0 -55
  37. data/lib/generators/connector/templates/home_index.html.erb +0 -48
@@ -48,4 +48,63 @@ describe Maestrano::Connector::Rails::SubEntityBase do
48
48
  it { expect{ subject.connec_entity_name }.to raise_error('Not implemented') }
49
49
  end
50
50
  end
51
+
52
+ describe 'names_hash' do
53
+ let(:bool) { true }
54
+ before {
55
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(bool)
56
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
57
+ }
58
+
59
+ context 'when external' do
60
+ it { expect(subject.names_hash).to eql({external_entity: 'name'}) }
61
+ end
62
+ context 'when not external' do
63
+ let(:bool) { false }
64
+ it { expect(subject.names_hash).to eql({connec_entity: 'name'}) }
65
+ end
66
+ end
67
+
68
+ describe 'create_idmap_from_external_entity' do
69
+ let(:organization) { create(:organization) }
70
+ let(:bool) { true }
71
+ before {
72
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(bool)
73
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
74
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:get_id_from_external_entity_hash).and_return('id')
75
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:object_name_from_external_entity_hash).and_return('object name')
76
+ }
77
+
78
+ context 'when external' do
79
+ it {
80
+ expect(Maestrano::Connector::Rails::IdMap).to receive(:create).with({:external_entity=>"name", :external_id=>"id", :name=>"object name", :connec_entity=>"lala", :organization_id=>1})
81
+ subject.create_idmap_from_external_entity({}, 'lala', organization)
82
+ }
83
+ end
84
+ context 'when not external' do
85
+ let(:bool) { false }
86
+ it { expect{ subject.create_idmap_from_external_entity({}, '', organization) }.to raise_error('Forbidden call') }
87
+ end
88
+ end
89
+
90
+ describe 'create_idmap_from_connec_entity' do
91
+ let(:organization) { create(:organization) }
92
+ let(:bool) { true }
93
+ before {
94
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:external?).and_return(bool)
95
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:entity_name).and_return('Name')
96
+ allow_any_instance_of(Maestrano::Connector::Rails::SubEntityBase).to receive(:object_name_from_connec_entity_hash).and_return('object name')
97
+ }
98
+
99
+ context 'when external' do
100
+ it { expect{ subject.create_idmap_from_connec_entity({}, '', organization) }.to raise_error('Forbidden call') }
101
+ end
102
+ context 'when not external' do
103
+ let(:bool) { false }
104
+ it {
105
+ expect(Maestrano::Connector::Rails::IdMap).to receive(:create).with({:connec_entity=>"name", :connec_id=>"lili", :name=>"object name", :external_entity=>"lala", :organization_id=>1})
106
+ subject.create_idmap_from_connec_entity({'id' => 'lili'}, 'lala', organization)
107
+ }
108
+ end
109
+ end
51
110
  end
@@ -3,7 +3,7 @@ def current_directory
3
3
  if __FILE__ =~ %r{\Ahttps?://}
4
4
  tempdir = Dir.mktmpdir("maestrano-connector-rails-")
5
5
  at_exit { FileUtils.remove_entry(tempdir) }
6
- git :clone => "--quiet https://github.com/berardpi/maestrano-connector-rails.git #{tempdir}"
6
+ git :clone => "--quiet https://github.com/berardpi/maestrano-connector-rails/tree/include-frontend #{tempdir}"
7
7
 
8
8
  "#{tempdir}/template"
9
9
  else
@@ -49,7 +49,6 @@ gem 'figaro'
49
49
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]
50
50
 
51
51
  gem 'maestrano-connector-rails'
52
- gem 'delayed_job_active_record'
53
52
 
54
53
 
55
54
  gem_group :test do
@@ -70,8 +69,11 @@ copy_file 'gitignore', '.gitignore'
70
69
  after_bundle do
71
70
  remove_dir 'app/mailers'
72
71
  remove_dir 'test'
72
+ remove_file 'app/views/layouts/application.html.erb'
73
+ remove_file 'app/assets/stylesheets/application.css'
73
74
  copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
74
75
  copy_file 'factories.rb', 'spec/factories.rb'
76
+ copy_file 'routes.rb', 'config/routes.rb'
75
77
 
76
78
  application do <<-RUBY
77
79
  config.generators do |g|
@@ -85,7 +87,6 @@ after_bundle do
85
87
  run 'rails g connector:install'
86
88
  run 'bundle exec figaro install'
87
89
  run 'rake railties:install:migrations'
88
- run 'rails g delayed_job:active_record'
89
90
  run 'rake db:migrate'
90
91
 
91
92
  # Init repo and commit
@@ -0,0 +1,14 @@
1
+ Rails.application.routes.draw do
2
+ mount Maestrano::Connector::Rails::Engine, at: '/'
3
+
4
+ root 'home#index'
5
+ get 'home/index' => 'home#index'
6
+ get 'home/redirect_to_external' => 'home#redirect_to_external'
7
+ get 'home/index' => 'home#index'
8
+ put 'home/update' => 'home#update'
9
+ post 'home/synchronize' => 'home#synchronize'
10
+ put 'home/toggle_sync' => 'home#toggle_sync'
11
+
12
+ get 'synchronizations/index' => 'synchronizations#index'
13
+ get 'shared_entities/index' => 'shared_entities#index'
14
+ 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.16
4
+ version: 0.2.17
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-03-07 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: maestrano-rails
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: haml-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bootstrap-sass
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: autoprefixer-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: shoulda
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -230,8 +272,6 @@ files:
230
272
  - lib/generators/connector/USAGE
231
273
  - lib/generators/connector/complex_entity_generator.rb
232
274
  - lib/generators/connector/install_generator.rb
233
- - lib/generators/connector/templates/admin_controller.rb
234
- - lib/generators/connector/templates/admin_index.html.erb
235
275
  - lib/generators/connector/templates/complex_entity_example/contact.rb
236
276
  - lib/generators/connector/templates/complex_entity_example/contact_and_lead.rb
237
277
  - lib/generators/connector/templates/complex_entity_example/contact_mapper.rb
@@ -243,13 +283,28 @@ files:
243
283
  - lib/generators/connector/templates/example_entity.rb
244
284
  - lib/generators/connector/templates/external.rb
245
285
  - lib/generators/connector/templates/home_controller.rb
246
- - lib/generators/connector/templates/home_index.html.erb
286
+ - lib/generators/connector/templates/home_controller_spec.rb
287
+ - lib/generators/connector/templates/home_index.haml
288
+ - lib/generators/connector/templates/layouts.haml
247
289
  - lib/generators/connector/templates/oauth_controller.rb
290
+ - lib/generators/connector/templates/shared_entities_controller.rb
291
+ - lib/generators/connector/templates/shared_entities_controller_spec.rb
292
+ - lib/generators/connector/templates/shared_entities_index.haml
293
+ - lib/generators/connector/templates/stylesheets/application.sass
294
+ - lib/generators/connector/templates/stylesheets/banners.sass
295
+ - lib/generators/connector/templates/stylesheets/home.sass
296
+ - lib/generators/connector/templates/stylesheets/layout.sass
297
+ - lib/generators/connector/templates/stylesheets/spacers.sass
298
+ - lib/generators/connector/templates/stylesheets/variables.sass
299
+ - lib/generators/connector/templates/sychronizations_controller_spec.rb
300
+ - lib/generators/connector/templates/synchronizations_controller.rb
301
+ - lib/generators/connector/templates/synchronizations_index.haml
248
302
  - lib/maestrano-connector-rails.rb
249
303
  - lib/maestrano/connector/rails.rb
250
304
  - maestrano-connector-rails.gemspec
251
305
  - maestrano.png
252
306
  - pkg/maestrano-connector-rails-0.0.1.gem
307
+ - pkg/maestrano-connector-rails-0.2.16.gem
253
308
  - pkg/maestrano-connector-rails-0.2.4.gem
254
309
  - spec/controllers/connec_controller_spec.rb
255
310
  - spec/dummy/README.md
@@ -324,6 +379,7 @@ files:
324
379
  - template/factories.rb
325
380
  - template/gitignore
326
381
  - template/maestrano-connector-template.rb
382
+ - template/routes.rb
327
383
  - template/spec_helper.rb
328
384
  homepage: http://github.com/maestrano/maestrano-connector-rails
329
385
  licenses:
@@ -1,58 +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
- 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
-
54
- private
55
- def is_admin
56
- current_user && current_organization && is_admin?(current_user, current_organization)
57
- end
58
- end
@@ -1,55 +0,0 @@
1
- <!-- TODO -->
2
- <!-- This template is given as an example of the informations
3
- and functions available on the admin panel -->
4
- <!-- This view is designed according to the admin controller supplied -->
5
- <div class='admin'>
6
- <% unless @organization %>
7
- <p> You need to be Admin or Super Admin in your company to access this panel.</p>
8
- <% else %>
9
- <ul>
10
- <li>
11
- Maestrano account
12
- <%= link_to "Disconnect your Maestrano account", maestrano_connector_rails.signout_path %>
13
- </li>
14
-
15
- <li>
16
- External account
17
- <% if @organization.oauth_uid %>
18
- <%= link_to "Disconnect #{@organization.name} (#{@organization.uid})", 'some_path' %>
19
- <% else %>
20
- <%= link_to "Connect #{@organization.name} (#{@organization.uid})", 'some_other_path' %>
21
- <% end %>
22
- </li>
23
-
24
- <li>
25
- <%= link_to "Force a synchronization", admin_synchronize_path, method: :post %>
26
- </li>
27
- </ul>
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
-
33
- <h3>Synchronized entities</h3>
34
- <p>You can customize which entities are synchronized by the connector</p>
35
- <%= form_tag admin_update_path(id: @organization.id), method: :put do %>
36
- <% @organization.synchronized_entities.each do |k, v| %>
37
- <label for="<%= k %>">#{k.to_s.humanize}</label>
38
- <input checked="<%= v %>" id="<%= k %>" name="<%= k %>" type="checkbox"></input>
39
- <% if v && @organization.oauth_uid %>
40
- <%= link_to "Force a synchronization for #{k.to_s.humanize.pluralize} only", admin_synchronize_path(opts: {only_entities: [k.to_s]}), method: :post %>
41
- <% end %>
42
- <% end %>
43
- <%= submit_tag :Update%>
44
- <% end %>
45
-
46
- <h3>IdMap</h3>
47
- <% @idmaps.each do |idmap| %>
48
- <%= idmap.connec_entity ? idmap.connec_entity.humanize : nil %>
49
- <%= idmap.connec_id %>
50
- <%= idmap.external_entity ? idmap.external_entity.humanize : nil %>
51
- <%= idmap.external_id %>
52
- <% end %>
53
-
54
- <% end %>
55
- </div>
@@ -1,48 +0,0 @@
1
- <!-- TODO -->
2
- <!-- This template is given as an example of the informations that
3
- can be displayed on the home page -->
4
- <!-- This view is designed according to the home controller supplied -->
5
- <div class='home'>
6
- <%= link_to 'Admin panel', admin_index_path %>
7
- <% unless current_user %>
8
- <%= link_to "Link your Maestrano account", maestrano_connector_rails.init_maestrano_auth_saml_index_path(tenant: :default) %>
9
- <p>Some generic information about the connector</p>
10
-
11
- <% else %>
12
- <% unless @organization.oauth_uid %>
13
- Not linked to external app
14
- <% if is_admin?(current_user, @organization) %>
15
- <%= link_to "Link this company to ...", 'some_path' %>
16
- <% end %>
17
- <% else %>
18
- Linked to external app
19
- <% end %>
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
-
27
- <h2>Last synchronization</h2>
28
- <% if @synchronizations.first %>
29
- <%= "#{@synchronizations.first.updated_at} #{@synchronizations.first.status}" %>
30
- <% if @synchronizations.first.is_error? %>
31
- <%= @synchronizations.first.message %>
32
- <% elsif @synchronizations.first.is_success? && @synchronizations.first.partial? %>
33
- Partial synchronization
34
- <% end %>
35
- <% end %>
36
-
37
- <h2>Synchronizations history</h2>
38
- <% @synchronizations.each do |sync| %>
39
- <%= sync.updated_at %>
40
- <%= sync.status %>
41
- <% if sync.is_error %>
42
- <%= sync.message %>
43
- <% elsif sync.is_success? && sync.partial? %>
44
- Partial synchronization
45
- <% end %>
46
- <% end %>
47
- <% end %>
48
- </div>