maestrano-connector-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/DEVELOPER.md +10 -0
  4. data/Gemfile +18 -0
  5. data/Gemfile.lock +222 -0
  6. data/LICENSE +21 -0
  7. data/README.md +138 -0
  8. data/Rakefile +37 -0
  9. data/VERSION +1 -0
  10. data/app/controllers/maestrano/account/group_users_controller.rb +20 -0
  11. data/app/controllers/maestrano/account/groups_controller.rb +22 -0
  12. data/app/controllers/maestrano/application_controller.rb +7 -0
  13. data/app/controllers/maestrano/auth/saml_controller.rb +31 -0
  14. data/app/controllers/maestrano/sessions_controller.rb +15 -0
  15. data/app/helpers/maestrano/connector/rails/session_helper.rb +17 -0
  16. data/app/jobs/maestrano/connector/rails/synchronization_job.rb +49 -0
  17. data/app/models/maestrano/connector/rails/complex_entity.rb +175 -0
  18. data/app/models/maestrano/connector/rails/concerns/entity.rb +231 -0
  19. data/app/models/maestrano/connector/rails/concerns/external.rb +13 -0
  20. data/app/models/maestrano/connector/rails/connector_logger.rb +9 -0
  21. data/app/models/maestrano/connector/rails/entity.rb +5 -0
  22. data/app/models/maestrano/connector/rails/external.rb +5 -0
  23. data/app/models/maestrano/connector/rails/id_map.rb +6 -0
  24. data/app/models/maestrano/connector/rails/organization.rb +60 -0
  25. data/app/models/maestrano/connector/rails/sub_entity_base.rb +32 -0
  26. data/app/models/maestrano/connector/rails/synchronization.rb +38 -0
  27. data/app/models/maestrano/connector/rails/user.rb +25 -0
  28. data/app/models/maestrano/connector/rails/user_organization_rel.rb +9 -0
  29. data/bin/rails +12 -0
  30. data/config/routes.rb +28 -0
  31. data/db/migrate/20151122162100_create_maestrano_connector_rails_users.rb +16 -0
  32. data/db/migrate/20151122162414_create_maestrano_connector_rails_organizations.rb +21 -0
  33. data/db/migrate/20151122162613_create_maestrano_connector_rails_user_organization_rels.rb +12 -0
  34. data/db/migrate/20151122163325_create_maestrano_connector_rails_synchronizations.rb +13 -0
  35. data/db/migrate/20151122163449_create_maestrano_connector_rails_id_maps.rb +18 -0
  36. data/lib/generators/connector/USAGE +2 -0
  37. data/lib/generators/connector/complex_entity_generator.rb +19 -0
  38. data/lib/generators/connector/install_generator.rb +70 -0
  39. data/lib/generators/connector/templates/admin_controller.rb +48 -0
  40. data/lib/generators/connector/templates/admin_index.html.erb +51 -0
  41. data/lib/generators/connector/templates/complex_entity_example/contact.rb +22 -0
  42. data/lib/generators/connector/templates/complex_entity_example/contact_and_lead.rb +56 -0
  43. data/lib/generators/connector/templates/complex_entity_example/contact_mapper.rb +17 -0
  44. data/lib/generators/connector/templates/complex_entity_example/lead.rb +22 -0
  45. data/lib/generators/connector/templates/complex_entity_example/lead_mapper.rb +15 -0
  46. data/lib/generators/connector/templates/complex_entity_example/person.rb +23 -0
  47. data/lib/generators/connector/templates/contact_and_lead.rb +55 -0
  48. data/lib/generators/connector/templates/entity.rb +48 -0
  49. data/lib/generators/connector/templates/example_entity.rb +26 -0
  50. data/lib/generators/connector/templates/external.rb +19 -0
  51. data/lib/generators/connector/templates/home_controller.rb +17 -0
  52. data/lib/generators/connector/templates/home_index.html.erb +42 -0
  53. data/lib/generators/connector/templates/oauth_controller.rb +45 -0
  54. data/lib/maestrano-connector-rails.rb +1 -0
  55. data/lib/maestrano/connector/rails.rb +13 -0
  56. data/maestrano-connector-rails.gemspec +197 -0
  57. data/maestrano.png +0 -0
  58. data/spec/dummy/README.md +1 -0
  59. data/spec/dummy/Rakefile +6 -0
  60. data/spec/dummy/app/assets/images/.keep +0 -0
  61. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  62. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  63. data/spec/dummy/app/controllers/admin_controller.rb +48 -0
  64. data/spec/dummy/app/controllers/application_controller.rb +8 -0
  65. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  66. data/spec/dummy/app/controllers/home_controller.rb +17 -0
  67. data/spec/dummy/app/controllers/oauth_controller.rb +45 -0
  68. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  69. data/spec/dummy/app/mailers/.keep +0 -0
  70. data/spec/dummy/app/models/.keep +0 -0
  71. data/spec/dummy/app/models/concerns/.keep +0 -0
  72. data/spec/dummy/app/models/entities/example_entitiy.rb +26 -0
  73. data/spec/dummy/app/models/maestrano/connector/rails/entity.rb +10 -0
  74. data/spec/dummy/app/models/maestrano/connector/rails/external.rb +11 -0
  75. data/spec/dummy/app/views/admin/index.html.erb +51 -0
  76. data/spec/dummy/app/views/home/index.html.erb +36 -0
  77. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  78. data/spec/dummy/bin/bundle +3 -0
  79. data/spec/dummy/bin/rails +4 -0
  80. data/spec/dummy/bin/rake +4 -0
  81. data/spec/dummy/bin/setup +29 -0
  82. data/spec/dummy/config.ru +4 -0
  83. data/spec/dummy/config/application.rb +26 -0
  84. data/spec/dummy/config/boot.rb +5 -0
  85. data/spec/dummy/config/database.yml +25 -0
  86. data/spec/dummy/config/environment.rb +5 -0
  87. data/spec/dummy/config/environments/development.rb +41 -0
  88. data/spec/dummy/config/environments/production.rb +79 -0
  89. data/spec/dummy/config/environments/test.rb +42 -0
  90. data/spec/dummy/config/initializers/assets.rb +11 -0
  91. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  92. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  93. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  94. data/spec/dummy/config/initializers/inflections.rb +16 -0
  95. data/spec/dummy/config/initializers/maestrano.rb +135 -0
  96. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  97. data/spec/dummy/config/initializers/session_store.rb +3 -0
  98. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  99. data/spec/dummy/config/locales/en.yml +23 -0
  100. data/spec/dummy/config/routes.rb +9 -0
  101. data/spec/dummy/config/secrets.yml +22 -0
  102. data/spec/dummy/db/development.sqlite3 +0 -0
  103. data/spec/dummy/db/migrate/20151209134445_create_maestrano_connector_rails_users.maestrano_connector_rails.rb +17 -0
  104. data/spec/dummy/db/migrate/20151209134446_create_maestrano_connector_rails_organizations.maestrano_connector_rails.rb +22 -0
  105. data/spec/dummy/db/migrate/20151209134447_create_maestrano_connector_rails_user_organization_rels.maestrano_connector_rails.rb +13 -0
  106. data/spec/dummy/db/migrate/20151209134448_create_maestrano_connector_rails_synchronizations.maestrano_connector_rails.rb +14 -0
  107. data/spec/dummy/db/migrate/20151209134449_create_maestrano_connector_rails_id_maps.maestrano_connector_rails.rb +19 -0
  108. data/spec/dummy/db/schema.rb +83 -0
  109. data/spec/dummy/lib/assets/.keep +0 -0
  110. data/spec/dummy/log/.keep +0 -0
  111. data/spec/dummy/public/404.html +67 -0
  112. data/spec/dummy/public/422.html +67 -0
  113. data/spec/dummy/public/500.html +66 -0
  114. data/spec/dummy/public/favicon.ico +0 -0
  115. data/spec/factories.rb +33 -0
  116. data/spec/jobs/syncrhonization_job_spec.rb +53 -0
  117. data/spec/models/complex_entity_spec.rb +353 -0
  118. data/spec/models/connector_logger_spec.rb +21 -0
  119. data/spec/models/entity_spec.rb +457 -0
  120. data/spec/models/external_spec.rb +15 -0
  121. data/spec/models/id_map_spec.rb +12 -0
  122. data/spec/models/organizaztion_spec.rb +105 -0
  123. data/spec/models/sub_entity_base_spec.rb +51 -0
  124. data/spec/models/synchronization_spec.rb +75 -0
  125. data/spec/models/user_organization_rel_spec.rb +14 -0
  126. data/spec/models/user_spec.rb +15 -0
  127. data/spec/spec_helper.rb +19 -0
  128. metadata +327 -0
@@ -0,0 +1,48 @@
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
+ Delayed::Job.enqueue Maestrano::Connector::Rails::SynchronizationJob.new(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
@@ -0,0 +1,51 @@
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>Synchronized entities</h3>
30
+ <p>You can customize which entities are synchronized by the connector.</p>
31
+ <%= form_tag admin_update_path(id: @organization.id), method: :put do %>
32
+ <% @organization.synchronized_entities.each do |k, v| %>
33
+ <label for="<%= k %>">#{k.to_s.humanize}</label>
34
+ <input checked="<%= v %>" id="<%= k %>" name="<%= k %>" type="checkbox"></input>
35
+ <% 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 %>
37
+ <% end %>
38
+ <% end %>
39
+ <%= submit_tag :Update%>
40
+ <% end %>
41
+
42
+ <h3>IdMap</h3>
43
+ <% @idmaps.each do |idmap| %>
44
+ <%= idmap.connec_entity ? idmap.connec_entity.humanize : nil %>
45
+ <%= idmap.connec_id %>
46
+ <%= idmap.external_entity ? idmap.external_entity.humanize : nil %>
47
+ <%= idmap.external_id %>
48
+ <% end %>
49
+
50
+ <% end %>
51
+ </div>
@@ -0,0 +1,22 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # See README for explanation
4
+ # class Entities::SubEntities::Contact < Maestrano::Connector::Rails::SubEntityBase
5
+
6
+ # def external?
7
+ # true
8
+ # end
9
+
10
+ # def entity_name
11
+ # 'contact'
12
+ # end
13
+
14
+ # def map_to(name, entity, organization)
15
+ # case name
16
+ # when 'person'
17
+ # Entities::SubEntities::ContactMapper.denormalize(entity)
18
+ # else
19
+ # raise "Impossible mapping from #{self.entity_name} to #{name}"
20
+ # end
21
+ # end
22
+ # end
@@ -0,0 +1,56 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # See README for explanation
4
+ # class Entities::ContactAndLead < Maestrano::Connector::Rails::ComplexEntity
5
+ # def connec_entities_names
6
+ # %w(person)
7
+ # end
8
+
9
+ # def external_entities_names
10
+ # %w(contact lead)
11
+ # end
12
+
13
+ # # input : {
14
+ # # connec_entity_names[0]: [unmapped_connec_entitiy1, unmapped_connec_entitiy2],
15
+ # # connec_entity_names[1]: [unmapped_connec_entitiy3, unmapped_connec_entitiy4]
16
+ # # }
17
+ # # output : {
18
+ # # connec_entity_names[0]: {
19
+ # # external_entities_names[0]: [unmapped_connec_entitiy1, unmapped_connec_entitiy2]
20
+ # # },
21
+ # # connec_entity_names[1]: {
22
+ # # external_entities_names[0]: [unmapped_connec_entitiy3],
23
+ # # external_entities_names[1]: [unmapped_connec_entitiy4]
24
+ # # }
25
+ # # }
26
+ # def connec_model_to_external_model!(connec_hash_of_entities)
27
+ # people = connec_hash_of_entities['person']
28
+ # connec_hash_of_entities['person'] = { 'lead' => [], 'contact' => [] }
29
+
30
+ # people.each do |person|
31
+ # if person['is_lead']
32
+ # connec_hash_of_entities['person']['lead'] << person
33
+ # else
34
+ # connec_hash_of_entities['person']['contact'] << person
35
+ # end
36
+ # end
37
+ # end
38
+
39
+ # # input : {
40
+ # # external_entities_names[0]: [unmapped_external_entity1, unmapped_external_entity2],
41
+ # # external_entities_names[1]: [unmapped_external_entity3, unmapped_external_entity4]
42
+ # # }
43
+ # # output : {
44
+ # # external_entities_names[0]: {
45
+ # # connec_entity_names[0]: [unmapped_external_entity1],
46
+ # # connec_entity_names[1]: [unmapped_external_entity2]
47
+ # # },
48
+ # # external_entities_names[1]: {
49
+ # # connec_entity_names[0]: [unmapped_external_entity3, unmapped_external_entity4]
50
+ # # }
51
+ # # }
52
+ # def external_model_to_connec_model!(external_hash_of_entities)
53
+ # external_hash_of_entities['lead'] = { 'person' => external_hash_of_entities['lead'] }
54
+ # external_hash_of_entities['contact'] = { 'person' => external_hash_of_entities['contact'] }
55
+ # end
56
+ # end
@@ -0,0 +1,17 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # See README for explanation
4
+ # class Entities::SubEntities::ContactMapper
5
+ # extend HashMapper
6
+
7
+ # map from('title'), to('Salutation')
8
+ # map from('first_name'), to('FirstName')
9
+ # map from('last_name'), to('LastName'), default: 'Undefined'
10
+ # map from('job_title'), to('Title')
11
+
12
+ # map from('address_work/billing/line1'), to('MailingStreet')
13
+ # map from('address_work/billing/city'), to('MailingCity')
14
+ # map from('address_work/billing/region'), to('MailingState')
15
+ # map from('address_work/billing/postal_code'), to('MailingPostalCode')
16
+ # map from('address_work/billing/country'), to('MailingCountry')
17
+ # end
@@ -0,0 +1,22 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # See README for explanation
4
+ # class Entities::SubEntities::Lead < Maestrano::Connector::Rails::SubEntityBase
5
+
6
+ # def external?
7
+ # true
8
+ # end
9
+
10
+ # def entity_name
11
+ # 'lead'
12
+ # end
13
+
14
+ # def map_to(name, entity, organization)
15
+ # case name
16
+ # when 'person'
17
+ # Entities::SubEntities::LeadMapper.denormalize(entity).merge(is_lead: true)
18
+ # else
19
+ # raise "Impossible mapping from #{self.entity_name} to #{name}"
20
+ # end
21
+ # end
22
+ # end
@@ -0,0 +1,15 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # See README for explanation
4
+ # class Entities::SubEntities::LeadMapper
5
+ # extend HashMapper
6
+
7
+ # map from('title'), to('Salutation')
8
+ # map from('first_name'), to('FirstName')
9
+ # map from('last_name'), to('LastName'), default: 'Undefined'
10
+ # map from('job_title'), to('Title')
11
+
12
+ # map from('lead_source'), to('LeadSource')
13
+ # map from('lead_status'), to('Status')
14
+ # map from('lead_conversion_date'), to('ConvertedDate')
15
+ # end
@@ -0,0 +1,23 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # See README for explanation
4
+ # class Enities::SubEntities::Person < Maestrano::Connector::Rails::SubEntityBase
5
+ # def external?
6
+ # false
7
+ # end
8
+
9
+ # def entity_name
10
+ # 'person'
11
+ # end
12
+
13
+ # def map_to(name, entity, organization)
14
+ # case name
15
+ # when 'lead'
16
+ # Enities::SubEntities::LeadMapper.normalize(entity)
17
+ # when 'contact'
18
+ # Enities::SubEntities::ContactMapper.normalize(entity)
19
+ # else
20
+ # raise "Impossible mapping from #{self.entity_name} to #{name}"
21
+ # end
22
+ # end
23
+ # end
@@ -0,0 +1,55 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # class Entities::ContactAndLead < Maestrano::Connector::Rails::ComplexEntity
4
+ # def connec_entities_names
5
+ # %w(person)
6
+ # end
7
+
8
+ # def external_entities_names
9
+ # %w(contact lead)
10
+ # end
11
+
12
+ # # input : {
13
+ # # connec_entity_names[0]: [unmapped_connec_entitiy1, unmapped_connec_entitiy2],
14
+ # # connec_entity_names[1]: [unmapped_connec_entitiy3, unmapped_connec_entitiy4]
15
+ # # }
16
+ # # output : {
17
+ # # connec_entity_names[0]: {
18
+ # # external_entities_names[0]: [unmapped_connec_entitiy1, unmapped_connec_entitiy2]
19
+ # # },
20
+ # # connec_entity_names[1]: {
21
+ # # external_entities_names[0]: [unmapped_connec_entitiy3],
22
+ # # external_entities_names[1]: [unmapped_connec_entitiy4]
23
+ # # }
24
+ # # }
25
+ # def connec_model_to_external_model!(connec_hash_of_entities)
26
+ # people = connec_hash_of_entities['person']
27
+ # connec_hash_of_entities['person'] = { 'lead' => [], 'contact' => [] }
28
+
29
+ # people.each do |person|
30
+ # if person['is_lead']
31
+ # connec_hash_of_entities['person']['lead'] << person
32
+ # else
33
+ # connec_hash_of_entities['person']['contact'] << person
34
+ # end
35
+ # end
36
+ # end
37
+
38
+ # # input : {
39
+ # # external_entities_names[0]: [unmapped_external_entity1, unmapped_external_entity2],
40
+ # # external_entities_names[1]: [unmapped_external_entity3, unmapped_external_entity4]
41
+ # # }
42
+ # # output : {
43
+ # # external_entities_names[0]: {
44
+ # # connec_entity_names[0]: [unmapped_external_entity1],
45
+ # # connec_entity_names[1]: [unmapped_external_entity2]
46
+ # # },
47
+ # # external_entities_names[1]: {
48
+ # # connec_entity_names[0]: [unmapped_external_entity3, unmapped_external_entity4]
49
+ # # }
50
+ # # }
51
+ # def external_model_to_connec_model!(external_hash_of_entities)
52
+ # external_hash_of_entities['lead'] = { 'person' => external_hash_of_entities['lead'] }
53
+ # external_hash_of_entities['contact'] = { 'person' => external_hash_of_entities['contact'] }
54
+ # end
55
+ # end
@@ -0,0 +1,48 @@
1
+ class Maestrano::Connector::Rails::Entity
2
+ include Maestrano::Connector::Rails::Concerns::Entity
3
+
4
+ # Return an array of all the entities that the connector can synchronize
5
+ # If you add new entities, you need to generate
6
+ # a migration to add them to existing organizations
7
+ def self.entities_list
8
+ # TODO
9
+ # The names in this list should match the names of your entities class
10
+ # e.g %w(person, tasks_list)
11
+ # will synchronized Entities::Person and Entities::TasksList
12
+ []
13
+ end
14
+
15
+ # Return an array of entities from the external app
16
+ def get_external_entities(client, last_synchronization, organization, opts={})
17
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Fetching #{@@external_name} #{self.external_entity_name.pluralize}")
18
+ # TODO
19
+ # This method should return only entities that have been updated since the last_synchronization
20
+ # It should also implements an option to do a full synchronization when opts[:full_sync] == true or when there is no last_synchronization
21
+ # Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Received data: Source=#{@@external_name}, Entity=#{self.external_entity_name}, Response=#{entities}")
22
+ end
23
+
24
+ def create_entity_to_external(client, mapped_connec_entity, external_entity_name, organization)
25
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending create #{external_entity_name}: #{mapped_connec_entity} to #{@@external_name}")
26
+ # TODO
27
+ # This method creates the entity in the external app and returns the external id
28
+ end
29
+
30
+ def update_entity_to_external(client, mapped_connec_entity, external_id, external_entity_name)
31
+ Maestrano::Connector::Rails::ConnectorLogger.log('info', organization, "Sending update #{external_entity_name} (id=#{external_id}): #{mapped_connec_entity} to #{@@external_name}")
32
+ # TODO
33
+ # This method updates the entity with the given id in the external app
34
+ end
35
+
36
+ def get_id_from_external_entity_hash(entity)
37
+ # TODO
38
+ # This method return the id from an external_entity_hash
39
+ # e.g entity['id']
40
+ end
41
+
42
+ def get_last_update_date_from_external_entity_hash(entity)
43
+ # TODO
44
+ # This method return the last update date from an external_entity_hash
45
+ # e.g entity['last_update']
46
+ end
47
+
48
+ end
@@ -0,0 +1,26 @@
1
+ # TODO
2
+ # This file is provided as an example and should be removed
3
+ # One such file needs to be created for each synchronizable entity,
4
+ # with its associated mapper
5
+
6
+ # class Entities::ExampleEntity < Maestrano::Connector::Rails::Entity
7
+ # def connec_entity_name
8
+ # 'ExampleEntity'
9
+ # end
10
+
11
+ # def external_entity_name
12
+ # 'Contact'
13
+ # end
14
+
15
+ # def mapper_class
16
+ # ExampleEntityMapper
17
+ # end
18
+ # end
19
+
20
+ # class ExampleEntityMapper
21
+ # extend HashMapper
22
+
23
+ # map from('/title'), to('/Salutation')
24
+ # map from('/first_name'), to('/FirstName')
25
+ # map from('address_work/billing2/city'), to('City')
26
+ # end
@@ -0,0 +1,19 @@
1
+ class Maestrano::Connector::Rails::External
2
+ include Maestrano::Connector::Rails::Concerns::External
3
+
4
+ def self.external_name
5
+ # TODO
6
+ # Returns the name of the external app
7
+ end
8
+
9
+ def self.get_client(organization)
10
+ # TODO
11
+ # Returns a client for the external application for the given organization
12
+ # e.g
13
+ # SomeName.new :oauth_token => organization.oauth_token,
14
+ # refresh_token: organization.refresh_token,
15
+ # instance_url: organization.instance_url,
16
+ # client_id: ENV[''],
17
+ # client_secret: ENV['']
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # TODO
2
+ # This controller is given as an example of a possible home
3
+ # Home 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
@@ -0,0 +1,42 @@
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
+ <h2>Last synchronization</h2>
22
+ <% if @synchronizations.first %>
23
+ <%= "#{@synchronizations.first.updated_at} #{@synchronizations.first.status}" %>
24
+ <% if @synchronizations.first.is_error? %>
25
+ <%= @synchronizations.first.message %>
26
+ <% elsif @synchronizations.first.is_success? && @synchronizations.first.partial? %>
27
+ Partial synchronization
28
+ <% end %>
29
+ <% end %>
30
+
31
+ <h2>Synchronizations history</h2>
32
+ <% @synchronizations.each do |sync| %>
33
+ <%= sync.updated_at %>
34
+ <%= sync.status %>
35
+ <% if sync.is_error %>
36
+ <%= sync.message %>
37
+ <% elsif sync.is_success? && sync.partial? %>
38
+ Partial synchronization
39
+ <% end %>
40
+ <% end %>
41
+ <% end %>
42
+ </div>