mno-enterprise-core 3.1.0 → 3.1.1
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/app/controllers/mno_enterprise/application_controller.rb +6 -2
- data/lib/her_extension/middleware/mnoe_raise_error.rb +21 -0
- data/lib/her_extension/model/relation.rb +3 -0
- data/lib/mno_enterprise/core.rb +8 -0
- data/lib/mno_enterprise/testing_support/factories/users.rb +10 -6
- data/lib/mno_enterprise/testing_support/mno_enterprise_api_test_helper.rb +2 -1
- data/lib/mno_enterprise/version.rb +1 -1
- data/spec/controllers/mno_enterprise/application_controller_spec.rb +22 -6
- data/spec/controllers/mno_enterprise/i18n_spec.rb +1 -1
- data/spec/lib/her_extension/model/relation_spec.rb +14 -0
- data/spec/models/mno_enterprise/base_resource_spec.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65ad5fd0badd5b1b262d37cec7072456038fb961
|
4
|
+
data.tar.gz: 5c4a566cd957070e836af6a3d7ada961f80242f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17d9bd4a3783ad23a7882ebac470cda39b8879df49050a17cee7a612afd1acf60b47f3d089d4335ada1900fecfed572ff4747139e7a19be6c650a2c562ff47e6
|
7
|
+
data.tar.gz: f42a459f8bd6e7f5b22d330e3d7fd2fbfa4de1b58ac5e05d716371ec9281dfa095fbbc3a2c60527d3ea5b9137f784924ced36b44e73d86125e6aa911ae3e4293
|
@@ -98,8 +98,12 @@ module MnoEnterprise
|
|
98
98
|
# Redirect to previous url and reset it
|
99
99
|
def after_sign_in_path_for(resource)
|
100
100
|
previous_url = session.delete(:previous_url)
|
101
|
-
|
102
|
-
|
101
|
+
default_url = if resource.respond_to?(:admin_role) && resource.admin_role.present?
|
102
|
+
MnoEnterprise.router.admin_path
|
103
|
+
else
|
104
|
+
MnoEnterprise.router.dashboard_path || main_app.root_url
|
105
|
+
end
|
106
|
+
return (return_to_url(resource) || previous_url || default_url)
|
103
107
|
end
|
104
108
|
|
105
109
|
# Some controllers needs to redirect to 'MySpace' which breaks if you dont use mnoe-frontend
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Her
|
2
|
+
module Middleware
|
3
|
+
# This middleware will raise errors based on the response status
|
4
|
+
# Same as Faraday::Response::RaiseError, except it will catch specific
|
5
|
+
# errors codes rather than everything in 400..600
|
6
|
+
class MnoeRaiseError < Faraday::Response::RaiseError
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status]
|
9
|
+
when 407
|
10
|
+
# mimic the behavior that we get with proxy requests with HTTPS
|
11
|
+
raise Faraday::Error::ConnectionFailed,
|
12
|
+
%(407 "Proxy Authentication Required ")
|
13
|
+
when 502..504
|
14
|
+
raise Faraday::Error::ConnectionFailed, response_values(env)
|
15
|
+
when 401, 500
|
16
|
+
raise Faraday::Error::ClientError, response_values(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -26,6 +26,9 @@ module Her
|
|
26
26
|
# Use filter instead of raw parameters
|
27
27
|
def where(params = {})
|
28
28
|
return self if !params || params.empty?
|
29
|
+
# If a value is an empty array, it'll be excluded when calling params.to_query, so convert it to nil instead
|
30
|
+
params.each { |k, v| params[k] = v.presence if v.is_a?(Array) }
|
31
|
+
|
29
32
|
self.params[:filter] ||= {}
|
30
33
|
self.params[:filter].merge!(params)
|
31
34
|
self
|
data/lib/mno_enterprise/core.rb
CHANGED
@@ -18,6 +18,7 @@ require "her_extension/model/associations/association"
|
|
18
18
|
require "her_extension/model/associations/association_proxy"
|
19
19
|
require "her_extension/model/associations/has_many_association"
|
20
20
|
require "her_extension/middleware/mnoe_api_v1_parse_json"
|
21
|
+
require "her_extension/middleware/mnoe_raise_error"
|
21
22
|
require "faraday_middleware"
|
22
23
|
require "mno_enterprise/engine"
|
23
24
|
|
@@ -53,6 +54,10 @@ module MnoEnterprise
|
|
53
54
|
@terms_url || '#'
|
54
55
|
end
|
55
56
|
|
57
|
+
def admin_path
|
58
|
+
@admin_path || '/admin/'
|
59
|
+
end
|
60
|
+
|
56
61
|
def launch_url(id,opts = {})
|
57
62
|
host_url("/launch/#{id}",opts)
|
58
63
|
end
|
@@ -310,6 +315,9 @@ module MnoEnterprise
|
|
310
315
|
|
311
316
|
# Adapter
|
312
317
|
c.use Faraday::Adapter::NetHttpNoProxy
|
318
|
+
|
319
|
+
# Error Handling
|
320
|
+
c.use Her::Middleware::MnoeRaiseError
|
313
321
|
end
|
314
322
|
end
|
315
323
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# Use as such: build(:api_user)
|
5
5
|
# See http://stackoverflow.com/questions/10032760/how-to-define-an-array-hash-in-factory-girl
|
6
6
|
FactoryGirl.define do
|
7
|
-
|
7
|
+
|
8
8
|
factory :user, class: MnoEnterprise::User do
|
9
9
|
sequence(:id)
|
10
10
|
sequence(:uid) { |n| "usr-fda9#{n}" }
|
@@ -20,28 +20,32 @@ FactoryGirl.define do
|
|
20
20
|
created_at 2.days.ago
|
21
21
|
updated_at 2.days.ago
|
22
22
|
sso_session "1fdd5sf5a73D7sd1as2a4sd541"
|
23
|
-
admin_role
|
23
|
+
admin_role nil
|
24
24
|
|
25
25
|
confirmation_sent_at 2.days.ago
|
26
26
|
confirmation_token "wky763pGjtzWR7dP44PD"
|
27
27
|
confirmed_at 1.days.ago
|
28
|
-
|
28
|
+
|
29
29
|
trait :unconfirmed do
|
30
30
|
confirmed_at nil
|
31
31
|
end
|
32
32
|
|
33
33
|
trait :admin do
|
34
|
-
admin_role
|
34
|
+
admin_role 'admin'
|
35
|
+
end
|
36
|
+
|
37
|
+
trait :staff do
|
38
|
+
admin_role 'staff'
|
35
39
|
end
|
36
40
|
|
37
41
|
trait :with_deletion_request do
|
38
42
|
deletion_request { build(:deletion_request).attributes }
|
39
43
|
end
|
40
|
-
|
44
|
+
|
41
45
|
trait :with_organizations do
|
42
46
|
organizations { [build(:organization).attributes] }
|
43
47
|
end
|
44
|
-
|
48
|
+
|
45
49
|
# Properly build the resource with Her
|
46
50
|
initialize_with { new(attributes).tap { |e| e.clear_attribute_changes! } }
|
47
51
|
end
|
@@ -124,7 +124,8 @@ module MnoEnterpriseApiTestHelper
|
|
124
124
|
|
125
125
|
# Response
|
126
126
|
c.use Her::Middleware::MnoeApiV1ParseJson
|
127
|
-
|
127
|
+
c.use Her::Middleware::MnoeRaiseError
|
128
|
+
|
128
129
|
# Add stubs on the test adapter
|
129
130
|
c.use MnoeFaradayTestAdapter do |receiver|
|
130
131
|
@_stub_list.each do |key,stub|
|
@@ -2,14 +2,30 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
module MnoEnterprise
|
4
4
|
describe ApplicationController, type: :controller do
|
5
|
+
# create an anonymous subclass of ApplicationController to expose protected methods
|
6
|
+
controller(MnoEnterprise::ApplicationController) do
|
7
|
+
def after_sign_in_path_for(resource)
|
8
|
+
super
|
9
|
+
end
|
10
|
+
def add_param_to_fragment(url, param_name, param_value)
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
describe '#add_param_to_fragment' do
|
6
|
-
|
16
|
+
it { expect(controller.add_param_to_fragment('/#/platform/accounts', 'foo', 'bar')).to eq('/#/platform/accounts?foo=bar') }
|
17
|
+
it { expect(controller.add_param_to_fragment('/', 'foo', 'bar')).to eq('/#?foo=bar') }
|
18
|
+
it { expect(controller.add_param_to_fragment('/#/platform/dashboard/he/43?en=690', 'foo', 'bar')).to eq('/#/platform/dashboard/he/43?en=690&foo=bar') }
|
19
|
+
it { expect(controller.add_param_to_fragment('/#/platform/dashboard/he/43?en=690', 'foo', [{msg: 'yolo'}])).to eq('/#/platform/dashboard/he/43?en=690&foo=%7B%3Amsg%3D%3E%22yolo%22%7D') }
|
20
|
+
end
|
7
21
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it { expect(
|
22
|
+
describe '#after_sign_in_path_for' do
|
23
|
+
before { @request.env["devise.mapping"] = Devise.mappings[:user] }
|
24
|
+
|
25
|
+
it { expect(controller.after_sign_in_path_for(User.new())).to eq('/dashboard/') }
|
26
|
+
it { expect(controller.after_sign_in_path_for(User.new(admin_role: "staff"))).to eq('/admin/') }
|
27
|
+
it { expect(controller.after_sign_in_path_for(User.new(admin_role: ""))).to eq('/dashboard/') }
|
28
|
+
it { expect(controller.after_sign_in_path_for(User.new(admin_role: "admin"))).to eq('/admin/') }
|
12
29
|
end
|
13
30
|
end
|
14
|
-
|
15
31
|
end
|
@@ -3,5 +3,19 @@ require 'rails_helper'
|
|
3
3
|
module MnoEnterprise
|
4
4
|
RSpec.describe Her::Model::Relation do
|
5
5
|
pending "add specs for Her::Model::Relation monkey patch: #{__FILE__}"
|
6
|
+
|
7
|
+
let(:dummy_class) { Class.new { include Her::Model } }
|
8
|
+
|
9
|
+
describe '.where' do
|
10
|
+
it 'adds the filter to params[:filter]' do
|
11
|
+
rel = Her::Model::Relation.new(dummy_class).where('uid.in' => [1, 2], 'foo' => 'bar')
|
12
|
+
expect(rel.params[:filter]).to eq('uid.in' => [1, 2], 'foo' => 'bar')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'replaces empty array values with nil' do
|
16
|
+
rel = Her::Model::Relation.new(dummy_class).where('id.in' => [])
|
17
|
+
expect(rel.params[:filter]).to eq('id.in' => nil)
|
18
|
+
end
|
19
|
+
end
|
6
20
|
end
|
7
21
|
end
|
@@ -2,6 +2,28 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
module MnoEnterprise
|
4
4
|
RSpec.describe BaseResource, type: :model do
|
5
|
+
describe 'Error Handling' do
|
6
|
+
class Test < BaseResource; end
|
7
|
+
|
8
|
+
context 'Connection Errors' do
|
9
|
+
((502..504).to_a<<407).each do |code|
|
10
|
+
it "handles #{code} error" do
|
11
|
+
api_stub_for(get: "/tests/1", code: code)
|
12
|
+
expect { Test.find(1) }.to raise_error(Faraday::ConnectionFailed)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'Server Errors' do
|
18
|
+
[401, 500].each do |code|
|
19
|
+
it "handles #{code} error" do
|
20
|
+
api_stub_for(get: "/tests/1", code: code)
|
21
|
+
expect { Test.find(1) }.to raise_error(Faraday::Error::ClientError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
5
27
|
describe '#cache_key' do
|
6
28
|
context 'for existing record' do
|
7
29
|
let(:user) { build(:user) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mno-enterprise-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -478,6 +478,7 @@ files:
|
|
478
478
|
- lib/generators/mno_enterprise/templates/scripts/upstart/app.conf
|
479
479
|
- lib/her_extension/her_orm_adapter.rb
|
480
480
|
- lib/her_extension/middleware/mnoe_api_v1_parse_json.rb
|
481
|
+
- lib/her_extension/middleware/mnoe_raise_error.rb
|
481
482
|
- lib/her_extension/model/associations/association.rb
|
482
483
|
- lib/her_extension/model/associations/association_proxy.rb
|
483
484
|
- lib/her_extension/model/associations/has_many_association.rb
|