maestrano-connector-rails 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07ffd861760785ab2d5e54e574a0d5382d643496
4
- data.tar.gz: 4184a45eb2939e6506d780963161d242546c0ebd
3
+ metadata.gz: 2a82734a77d8a8231e8a01d8c9c9e0f62e684cad
4
+ data.tar.gz: 73ce17a1cacbd9f5c0c988e4c132b1f7c8769b63
5
5
  SHA512:
6
- metadata.gz: 4512861d9e65c9771e54657c432fde4f5d18c424a81e3d277e559f175db0f28655a7cdf0fa3361f85392b7e6a822359d45b66e487def78eb01c68ff1452cd0ec
7
- data.tar.gz: 2827d2a7e1a3352850f9d536d24c12484528cbe60656dc1cff61dd7bcc4f54a7bb8aadce3e33124e792f3937324644eee2d532f3dfb223c0981514c26ced1314
6
+ metadata.gz: a092e0cfcecc3f1f6745ad6ad49970a8cfdd5e0e1887f5a29f2e79fa5e23502b893e15d81e57f3d0d89e15b6392b9a5b9dee0d044177334c304913b69db4b023
7
+ data.tar.gz: 9b9232cd104ec556d91ddcda3af1eeb12e3db8be65371ccc98a81b6d67b38dd5f48fb52974999eb854562416a601293b3bd3e65f3f511509288f83295076ccd7
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.3
1
+ 1.3.4
@@ -1,7 +1,8 @@
1
1
  class Maestrano::SynchronizationsController < Maestrano::Rails::WebHookController
2
2
  def show
3
+ tenant = params[:tenant]
3
4
  uid = params[:id]
4
- organization = Maestrano::Connector::Rails::Organization.find_by_uid(uid)
5
+ organization = Maestrano::Connector::Rails::Organization.find_by_uid_and_tenant(uid, tenant)
5
6
  return render json: {errors: [{message: "Organization not found", code: 404}]}, status: :not_found unless organization
6
7
 
7
8
  h = {
@@ -22,9 +23,10 @@ class Maestrano::SynchronizationsController < Maestrano::Rails::WebHookControlle
22
23
  end
23
24
 
24
25
  def create
26
+ tenant = params[:tenant]
25
27
  uid = params[:group_id]
26
28
  opts = params[:opts] || {}
27
- organization = Maestrano::Connector::Rails::Organization.find_by_uid(uid)
29
+ organization = Maestrano::Connector::Rails::Organization.find_by_uid_and_tenant(uid, tenant)
28
30
  return render json: {errors: [{message: "Organization not found", code: 404}]}, status: :not_found unless organization
29
31
 
30
32
  Maestrano::Connector::Rails::SynchronizationJob.perform_later(organization, opts.with_indifferent_access)
@@ -32,8 +34,9 @@ class Maestrano::SynchronizationsController < Maestrano::Rails::WebHookControlle
32
34
  end
33
35
 
34
36
  def toggle_sync
37
+ tenant = params[:tenant]
35
38
  uid = params[:group_id]
36
- organization = Maestrano::Connector::Rails::Organization.find_by_uid(uid)
39
+ organization = Maestrano::Connector::Rails::Organization.find_by_uid_and_tenant(uid, tenant)
37
40
  return render json: {errors: [{message: "Organization not found", code: 404}]}, status: :not_found unless organization
38
41
 
39
42
  organization.toggle(:sync_enabled)
@@ -28,6 +28,15 @@ module Maestrano::Connector::Rails::Concerns::ConnecHelper
28
28
  @@connec_version
29
29
  end
30
30
 
31
+ def connec_version_lt?(version, organization)
32
+ version = Gem::Version.new(version)
33
+ current_version = Gem::Version.new(connec_version(organization))
34
+
35
+ current_version < version
36
+ rescue
37
+ true
38
+ end
39
+
31
40
  # Replaces the arrays of id received from Connec! by the id of the external application
32
41
  # Returns a hash {entity: {}, connec_id: '', id_refs_only_connec_entity: {}}
33
42
  # If an array has no id for this oauth_provider and oauth_uid but has one for connec, it returns a nil entity (skip the record)
@@ -136,7 +136,7 @@ module Maestrano::Connector::Rails::Concerns::Entity
136
136
  end
137
137
 
138
138
  def public_connec_entity_name
139
- connec_entity_name.pluralize
139
+ singleton? ? connec_entity_name : connec_entity_name.pluralize
140
140
  end
141
141
 
142
142
  def public_external_entity_name
data/config/routes.rb CHANGED
@@ -7,11 +7,14 @@ Maestrano::Connector::Rails::Engine.routes.draw do
7
7
  match 'signout', to: 'sessions#destroy', as: 'signout', via: [:get, :post]
8
8
  post 'connec/notifications/:tenant' => 'connec#notifications'
9
9
 
10
- resources :synchronizations, only: [:show, :create] do
11
- collection do
12
- put :toggle_sync
10
+ resources :dependancies, only: [:index]
11
+
12
+ scope ':tenant' do
13
+ resources :synchronizations, only: [:show, :create] do
14
+ collection do
15
+ put :toggle_sync
16
+ end
13
17
  end
14
18
  end
15
- resources :dependancies, only: [:index]
16
19
  end
17
20
  end
@@ -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 1.3.3 ruby lib
5
+ # stub: maestrano-connector-rails 1.3.4 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "maestrano-connector-rails"
9
- s.version = "1.3.3"
9
+ s.version = "1.3.4"
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-07-29"
14
+ s.date = "2016-08-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"]
@@ -4,9 +4,10 @@ describe Maestrano::SynchronizationsController, type: :controller do
4
4
  routes { Maestrano::Connector::Rails::Engine.routes }
5
5
 
6
6
  let(:uid) { 'cld-aaaa' }
7
+ let(:tenant) { 'default' }
7
8
 
8
9
  describe 'show' do
9
- subject { get :show, id: uid }
10
+ subject { get :show, id: uid, tenant: tenant }
10
11
 
11
12
 
12
13
  context 'without authentication' do
@@ -26,11 +27,22 @@ describe Maestrano::SynchronizationsController, type: :controller do
26
27
  }
27
28
 
28
29
  context 'when organization is not found' do
29
- let!(:organization) { create(:organization, uid: 'cld-bbbb') }
30
+ context 'bad uid' do
31
+ let!(:organization) { create(:organization, uid: 'cld-bbbb') }
30
32
 
31
- it 'is a 404' do
32
- subject
33
- expect(response.status).to eq(404)
33
+ it 'is a 404' do
34
+ subject
35
+ expect(response.status).to eq(404)
36
+ end
37
+ end
38
+
39
+ context 'bad tenant' do
40
+ let!(:organization) { create(:organization, uid: uid, tenant: 'another_tenant') }
41
+
42
+ it 'is a 404' do
43
+ subject
44
+ expect(response.status).to eq(404)
45
+ end
34
46
  end
35
47
  end
36
48
 
@@ -77,7 +89,7 @@ describe Maestrano::SynchronizationsController, type: :controller do
77
89
 
78
90
  describe 'create' do
79
91
  let(:opts) { {'only_entities' => ['customer']} }
80
- subject { post :create, group_id: uid, opts: opts }
92
+ subject { post :create, group_id: uid, opts: opts, tenant: tenant }
81
93
 
82
94
 
83
95
  context 'without authentication' do
@@ -103,6 +115,15 @@ describe Maestrano::SynchronizationsController, type: :controller do
103
115
  subject
104
116
  expect(response.status).to eq(404)
105
117
  end
118
+
119
+ context 'bad tenant' do
120
+ let!(:organization) { create(:organization, uid: uid, tenant: 'another_tenant') }
121
+
122
+ it 'is a 404' do
123
+ subject
124
+ expect(response.status).to eq(404)
125
+ end
126
+ end
106
127
  end
107
128
 
108
129
  context 'when organization is found' do
@@ -122,7 +143,7 @@ describe Maestrano::SynchronizationsController, type: :controller do
122
143
  end
123
144
 
124
145
  describe 'toggle_sync' do
125
- subject { put :toggle_sync, group_id: uid }
146
+ subject { put :toggle_sync, group_id: uid, tenant: tenant }
126
147
 
127
148
 
128
149
  context 'without authentication' do
@@ -148,6 +169,15 @@ describe Maestrano::SynchronizationsController, type: :controller do
148
169
  subject
149
170
  expect(response.status).to eq(404)
150
171
  end
172
+
173
+ context 'bad tenant' do
174
+ let!(:organization) { create(:organization, uid: uid, tenant: 'another_tenant') }
175
+
176
+ it 'is a 404' do
177
+ subject
178
+ expect(response.status).to eq(404)
179
+ end
180
+ end
151
181
  end
152
182
 
153
183
  context 'when organization is found' do
@@ -29,7 +29,28 @@ describe Maestrano::Connector::Rails::ConnecHelper do
29
29
  expect(subject.connec_version(organization)).to eql('1.1')
30
30
  expect(subject.connec_version(organization2)).to eql('1.2')
31
31
  end
32
+ end
33
+
34
+ describe 'connec_version_lt?' do
35
+ before {
36
+ allow(subject).to receive(:connec_version).and_return('1.1.0')
37
+ }
38
+
39
+ it 'returns true if the current version is gt the parameter' do
40
+ expect(subject.connec_version_lt?('1.0.1', nil)).to be false
41
+ end
32
42
 
43
+ it 'returns false if the current version is lt the parameter' do
44
+ expect(subject.connec_version_lt?('1.2.1', nil)).to be true
45
+ end
46
+
47
+ it 'returns false if the current version is eq the parameter' do
48
+ expect(subject.connec_version_lt?('1.1.0', nil)).to be false
49
+ end
50
+
51
+ it 'returns true if something fails' do
52
+ expect(subject.connec_version_lt?('lala', nil)).to be true
53
+ end
33
54
  end
34
55
 
35
56
  describe 'unfold_references' do
@@ -118,14 +118,25 @@ describe Maestrano::Connector::Rails::Entity do
118
118
  end
119
119
 
120
120
  describe 'public_connec_entity_name' do
121
- it 'returns the connec_entity_name' do
121
+ it 'returns the pluralized connec_entity_name' do
122
122
  allow(subject).to receive(:connec_entity_name).and_return('tree')
123
123
  expect(subject.public_connec_entity_name).to eql('trees')
124
124
  end
125
+
126
+ context 'when singleton' do
127
+ before {
128
+ allow(subject).to receive(:singleton?).and_return(true)
129
+ }
130
+
131
+ it 'returns the connec_entity_name' do
132
+ allow(subject).to receive(:connec_entity_name).and_return('tree')
133
+ expect(subject.public_connec_entity_name).to eql('tree')
134
+ end
135
+ end
125
136
  end
126
137
 
127
138
  describe 'public_external_entity_name' do
128
- it 'returns the external_entity_name' do
139
+ it 'returns the pluralized external_entity_name' do
129
140
  allow(subject).to receive(:external_entity_name).and_return('tree')
130
141
  expect(subject.public_external_entity_name).to eql('trees')
131
142
  end
@@ -30,6 +30,12 @@
30
30
 
31
31
  config.sso.x509_certificate = Settings[tenant][:x509_certificate]
32
32
  config.sso.x509_fingerprint = Settings[tenant][:x509_fingerprint]
33
+
34
+ # => Synchronizations endpoints
35
+ config.app.synchronization_status_path = "/maestrano/#{tenant}/synchronizations/:cld-uid"
36
+ config.app.synchronization_toggle_path = "/maestrano/#{tenant}/synchronizations/toggle_sync"
37
+ config.app.synchronization_start_path = "/maestrano/#{tenant}/synchronizations"
38
+
33
39
  # ==> Single Sign-On activation
34
40
  # Enable/Disable single sign-on. When troubleshooting authentication issues
35
41
  # you might want to disable SSO temporarily
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.3
4
+ version: 1.3.4
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-07-29 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails