mno-enterprise-api 3.1.1 → 3.1.2

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: 35fc216add77173460114179a66177c4691895a6
4
- data.tar.gz: 3996b0e5569c9b6cffd7fd8fcf22924fdf34976d
3
+ metadata.gz: 4634cd921bb1ad61aa2d22d2f87ec8f8f743a6eb
4
+ data.tar.gz: 5c9e5f8551ad2c50d31a8f97b36a4636b9612076
5
5
  SHA512:
6
- metadata.gz: 8937e10a9c4baf22b1625d8b9b360a7441a5a42275e92fc2b720abcc06e7d308ceacfe777ec339b933e92f22c864f3e4397680c830f2b3f107af9748676e6c91
7
- data.tar.gz: 1c8d427beae96bb414d9750ad19b01b81e4489d82aeca1a384e752b7b4412a680dbb675d0fdee06ceb5e7ed80ca21222e778241844d6a911f5cc265f949f9bd6
6
+ metadata.gz: 049b8bca7b97ba5ecbdf7f33744bb36a76a50de88c85340123c58b0f7838b8e32d9b01760a9d68f5a8ec4f102fbb609715f99d152abecad462f8fc49a7a7f395
7
+ data.tar.gz: 9c9487907c76667e0ad38df08a9ac4a51f488f3ce8b06719a2708badde5a0e4866f8e9d44081df083458114413fc5eb5d88536a4bc8e6f27842053f91450da11
@@ -8,6 +8,7 @@ module MnoEnterprise
8
8
  # Perform the user impersonate action
9
9
  # GET /impersonate/user/123
10
10
  def create
11
+ session[:impersonator_redirect_path] = params[:redirect_path].presence
11
12
  @user = MnoEnterprise::User.find(params[:user_id])
12
13
  if @user.present?
13
14
  impersonate(@user)
@@ -24,7 +25,7 @@ module MnoEnterprise
24
25
  # user = current_user
25
26
  revert_impersonate
26
27
  end
27
- redirect_to '/admin/'
28
+ redirect_to session.delete(:impersonator_redirect_path).presence || '/admin/'
28
29
  end
29
30
 
30
31
  private
@@ -13,35 +13,49 @@ module MnoEnterprise
13
13
 
14
14
  # GET /mnoe/jpi/v1/admin/invoices/current_billing_amount
15
15
  def current_billing_amount
16
- data = Rails.cache.fetch('tenant_admin/current_billing_amount', expires_in: ADMIN_CACHE_DURATION) do
17
- billing = MnoEnterprise::Organization.all.map(&:current_billing).sum(Money.new(0))
18
- {current_billing_amount: {amount: billing.amount, currency: billing.currency_as_string}}
19
- end
20
- render json: data
16
+ # Backward compatibility with old MnoHub (<= v1.0.2)
17
+ # TODO: Remove once all mnohub are migrated to newer versions
18
+ tenant.respond_to?(:current_billing_amount) && current_billing = tenant.current_billing_amount
19
+
20
+ render json: {current_billing_amount: format_money(current_billing)}
21
21
  end
22
22
 
23
23
  # GET /mnoe/jpi/v1/admin/invoices/last_invoicing_amount
24
24
  def last_invoicing_amount
25
- tenant_billing = MnoEnterprise::Tenant.get('tenant').last_customers_invoicing_amount
26
- render json: {last_invoicing_amount: {amount: tenant_billing.amount, currency: tenant_billing.currency_as_string}}
25
+ tenant_billing = tenant.last_customers_invoicing_amount
26
+ render json: {last_invoicing_amount: format_money(tenant_billing)}
27
27
  end
28
28
 
29
29
  # GET /mnoe/jpi/v1/admin/invoices/outstanding_amount
30
30
  def outstanding_amount
31
- tenant_billing = MnoEnterprise::Tenant.get('tenant').last_customers_outstanding_amount
32
- render json: {outstanding_amount: {amount: tenant_billing.amount, currency: tenant_billing.currency_as_string}}
31
+ tenant_billing = tenant.last_customers_outstanding_amount
32
+ render json: {outstanding_amount: format_money(tenant_billing)}
33
33
  end
34
34
 
35
35
  # GET /mnoe/jpi/v1/admin/invoices/last_portfolio_amount
36
36
  def last_portfolio_amount
37
- tenant_billing = MnoEnterprise::Tenant.get('tenant').last_portfolio_amount
38
- render json: {last_portfolio_amount: {amount: tenant_billing.amount, currency: tenant_billing.currency_as_string}}
37
+ tenant_billing = tenant.last_portfolio_amount
38
+ render json: {last_portfolio_amount: format_money(tenant_billing)}
39
39
  end
40
40
 
41
41
  # GET /mnoe/jpi/v1/admin/invoices/last_commission_amount
42
42
  def last_commission_amount
43
- tenant_billing = MnoEnterprise::Tenant.get('tenant').last_commission_amount
44
- render json: {last_commission_amount: {amount: tenant_billing.amount, currency: tenant_billing.currency_as_string}}
43
+ tenant_billing = tenant.last_commission_amount
44
+ render json: {last_commission_amount: format_money(tenant_billing)}
45
+ end
46
+
47
+ private
48
+
49
+ def tenant
50
+ @tenant ||= MnoEnterprise::Tenant.show
51
+ end
52
+
53
+ def format_money(money)
54
+ if money
55
+ {amount: money.amount, currency: money.currency_as_string}
56
+ else
57
+ {amount: 'N/A', currency: ''}
58
+ end
45
59
  end
46
60
  end
47
61
  end
@@ -1,5 +1,6 @@
1
1
  module MnoEnterprise
2
2
  class Jpi::V1::AppInstancesSyncController < Jpi::V1::BaseResourceController
3
+ CONNECTOR_STATUS_RUNNING = ['PENDING', 'RUNNING']
3
4
 
4
5
  # GET /mnoe/jpi/v1/organization/org-fbba/app_instances_sync
5
6
  def index
@@ -28,9 +29,8 @@ module MnoEnterprise
28
29
  def results(connectors)
29
30
  {
30
31
  connectors: connectors,
31
- is_syncing: connectors.any?{|c| c[:status]=="RUNNING" }
32
+ is_syncing: connectors.any? { |c| CONNECTOR_STATUS_RUNNING.include?(c[:status]) }
32
33
  }
33
34
  end
34
-
35
35
  end
36
36
  end
@@ -13,13 +13,15 @@ module MnoEnterprise
13
13
  # {
14
14
  # 'app-version': '9061048-6811c4a',
15
15
  # 'mno-enterprise-version': '0.0.1',
16
- # 'env': 'test'
16
+ # 'env': 'test',
17
+ # 'mno-api-host': 'https://uat.maestrano.io'
17
18
  # }
18
19
  def version
19
20
  data = {
20
21
  'app-version' => MnoEnterprise::APP_VERSION,
21
22
  'mno-enteprise-version' => MnoEnterprise::VERSION,
22
- 'env' => Rails.env
23
+ 'env' => Rails.env,
24
+ 'mno-api-host' => MnoEnterprise.mno_api_host
23
25
  }
24
26
  render json: data
25
27
  end
@@ -1,4 +1,4 @@
1
- %div{ 'ng-init' => "user = { $pwdScore: {}, name: '#{resource.name}', surname: '#{resource.surname}' }" }
1
+ %div{ 'ng-init' => "user = { $pwdScore: {}, name: '#{resource.name}', surname: '#{resource.surname}', phone: '#{resource.phone}' }" }
2
2
 
3
3
  = form_for(resource, as: resource_name, :url => mno_enterprise.user_confirmation_finalize_path, :html => { 'name' => 'loginForm', :class => 'autofill-detect text-center' }) do |f|
4
4
 
@@ -18,7 +18,7 @@
18
18
  .col-sm-12
19
19
  .phone
20
20
  = f.select :phone_country_code, options_for_select(Country.all.map { |country,code| c = Country.new(code); ["#{c.alpha2} +#{c.country_code}", code]}, MnoEnterprise.app_country), {}, class: 'form-control unstyled'
21
- = f.text_field :phone, placeholder: "*Phone", required: true, 'ng-model' => 'user.phone_number', class: 'form-control'
21
+ = f.text_field :phone, placeholder: "*Phone", required: true, 'ng-model' => 'user.phone', class: 'form-control'
22
22
 
23
23
  %br
24
24
 
@@ -25,7 +25,7 @@
25
25
  .checkbox-section.text-center
26
26
  = check_box_tag 'tos', 'accept', false, :required => true, :style => "margin-top: -3px;", 'ng-model' => 'acceptTos'
27
27
  %label{for: 'tos'}= t('mno_enterprise.auth.registrations.new.user_accept')
28
- = link_to t('.tos'), MnoEnterprise.router.terms_url, target: '_blank'
28
+ = link_to t('mno_enterprise.auth.registrations.new.tos'), MnoEnterprise.router.terms_url, target: '_blank'
29
29
 
30
30
  %br
31
31
  .row
@@ -1 +1 @@
1
- json.extract! kpi, :id, :name, :element_watched, :endpoint, :source, :targets, :settings, :extra_params
1
+ json.extract! kpi, :id, :element_watched, :endpoint, :source, :targets, :settings, :extra_params
@@ -2,6 +2,6 @@ json.credit_card do
2
2
  if credit_card
3
3
  json.extract! credit_card, :id, :title,:first_name,:last_name,:month,:year,:country,:billing_address,:billing_city,:billing_postcode, :billing_country
4
4
  json.number credit_card.masked_number
5
- json.verification_value 'CVV'
5
+ json.verification_value credit_card.id ? 'CVV' : nil
6
6
  end
7
- end
7
+ end
@@ -30,13 +30,23 @@ module MnoEnterprise
30
30
 
31
31
  describe "#destroy" do
32
32
  subject { get :destroy }
33
- before { get :create, user_id: user2.id }
34
33
 
35
- it { expect(controller.current_user.id).to eq(user2.id) }
34
+ context 'without redirect_path' do
35
+ before { get :create, user_id: user2.id }
36
36
 
37
- it { subject; expect(controller.current_user.id).to eq(user.id) }
37
+ it { expect(controller.current_user.id).to eq(user2.id) }
38
+
39
+ it { subject; expect(controller.current_user.id).to eq(user.id) }
40
+
41
+ it { is_expected.to redirect_to('/admin/') }
42
+ end
43
+
44
+ context 'with a redirect_path' do
45
+ before { get :create, user_id: user2.id, redirect_path: '/admin/redirect#path' }
46
+
47
+ it { is_expected.to redirect_to('/admin/redirect#path') }
48
+ end
38
49
  end
39
50
  end
40
51
  end
41
-
42
52
  end
@@ -39,16 +39,13 @@ module MnoEnterprise
39
39
  # Stub invoice and invoice call
40
40
  let(:invoice) { build(:invoice) }
41
41
  let(:user) { build(:user, :admin) }
42
- let(:tenant) { build(:tenant) }
43
- let(:org1) { build(:organization, current_billing: Money.new(10_000,'AUD')) }
44
- let(:org2) { build(:organization, current_billing: Money.new(1000,'AUD')) }
42
+ let(:tenant) { build(:tenant, current_billing_amount: Money.new(11_000,'AUD')) }
45
43
 
46
44
  before do
47
45
  api_stub_for(get: "/invoices", response: from_api([invoice]))
48
46
  api_stub_for(get: "/invoices/#{invoice.id}", response: from_api(invoice))
49
47
  api_stub_for(get: "/users", response: from_api([user]))
50
48
  api_stub_for(get: "/users/#{user.id}", response: from_api(user))
51
- api_stub_for(get: "/organizations", response: from_api([org1, org2]))
52
49
  api_stub_for(get: "/tenant", response: from_api(tenant))
53
50
  sign_in user
54
51
  end
@@ -85,6 +82,19 @@ module MnoEnterprise
85
82
  describe 'GET #current_billing_amount' do
86
83
  subject { get :current_billing_amount }
87
84
 
85
+ context 'with an old MnoHub' do
86
+ let(:tenant) { build(:old_tenant) }
87
+
88
+ before { subject }
89
+
90
+ it { expect(response).to be_success }
91
+
92
+ it 'returns the sum of the current_billing' do
93
+ expected = {'current_billing_amount' => {"amount"=>"N/A", "currency"=>""}}
94
+ expect(response.body).to eq(expected.to_json)
95
+ end
96
+ end
97
+
88
98
  context 'success' do
89
99
  before { subject }
90
100
 
@@ -74,6 +74,14 @@ module MnoEnterprise
74
74
  before { subject }
75
75
  it { expect(JSON.parse(response.body)['is_syncing']).to be_falsey }
76
76
  end
77
+
78
+ context "when connector is pending" do
79
+ let(:progress_results) { { connectors: [
80
+ HashWithIndifferentAccess.new({name: 'a_name', status: 'PENDING', date: nil})
81
+ ] } }
82
+ before { subject }
83
+ it { expect(JSON.parse(response.body)['is_syncing']).to be_truthy }
84
+ end
77
85
  end
78
86
 
79
87
  describe "POST #create" do
@@ -46,7 +46,7 @@ module MnoEnterprise
46
46
  end
47
47
 
48
48
  describe 'PUT #update' do
49
- let(:kpi_hash) { from_api(kpi)[:data].except(:dashboard).merge(name: 'New Name') }
49
+ let(:kpi_hash) { from_api(kpi)[:data].except(:dashboard).merge(element_watched: 'New Watchable') }
50
50
 
51
51
  subject { put :update, id: kpi.id, kpi: kpi_hash }
52
52
 
@@ -59,7 +59,7 @@ module MnoEnterprise
59
59
 
60
60
  it "updates the kpi" do
61
61
  subject
62
- expect(assigns(:kpi).name).to eq('New Name')
62
+ expect(assigns(:kpi).element_watched).to eq('New Watchable')
63
63
  end
64
64
 
65
65
  it { subject; expect(response.code).to eq('200') }
@@ -5,6 +5,10 @@ module MnoEnterprise
5
5
  render_views
6
6
  routes { MnoEnterprise::Engine.routes }
7
7
 
8
+ # Freeze time (JWT are time dependent)
9
+ before { Timecop.freeze }
10
+ after { Timecop.return }
11
+
8
12
  let(:user) { build(:user) }
9
13
  let(:app_instance) { build(:app_instance) }
10
14
 
@@ -29,6 +29,10 @@ module MnoEnterprise
29
29
  it 'returns the environment' do
30
30
  expect(data['env']).to eq('test')
31
31
  end
32
+
33
+ it 'returns the mno-api-host' do
34
+ expect(data['mno-api-host']).to eq('https://api-enterprise.maestrano.com')
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -9,6 +9,10 @@ module MnoEnterprise
9
9
  render_views
10
10
  routes { MnoEnterprise::Engine.routes }
11
11
 
12
+ # Freeze time (JWT are time dependent)
13
+ before { Timecop.freeze }
14
+ after { Timecop.return }
15
+
12
16
  # Stub controller ability
13
17
  let!(:ability) { stub_ability }
14
18
  let(:extra_params) { {some: 'param'} }
@@ -33,7 +37,7 @@ module MnoEnterprise
33
37
  it_behaves_like 'a user protected resource'
34
38
 
35
39
  it { subject; expect(response).to be_success }
36
- it { Timecop.freeze { subject; expect(assigns(:redirect_to)).to eq(redirect_url) } }
40
+ it { subject; expect(assigns(:redirect_to)).to eq(redirect_url) }
37
41
 
38
42
  Webhook::OAuthController::PROVIDERS_WITH_OPTIONS.each do |provider|
39
43
  describe "#{provider.capitalize} provider" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mno-enterprise-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
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-08-30 00:00:00.000000000 Z
12
+ date: 2016-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mno-enterprise-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 3.1.1
20
+ version: 3.1.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 3.1.1
27
+ version: 3.1.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: jbuilder
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -341,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
341
341
  version: '0'
342
342
  requirements: []
343
343
  rubyforge_project:
344
- rubygems_version: 2.4.8
344
+ rubygems_version: 2.5.1
345
345
  signing_key:
346
346
  specification_version: 4
347
347
  summary: Maestrano Enterprise - API