-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #564 from BrunoChauvet/feature/tenant-dashboards
Feature/tenant dashboards
- Loading branch information
Showing
37 changed files
with
378 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--color | ||
--backtrace | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
api/app/controllers/mno_enterprise/jpi/v1/admin/subscription_events_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module MnoEnterprise | ||
class Jpi::V1::Admin::SubscriptionEventsController < Jpi::V1::Admin::BaseResourceController | ||
include MnoEnterprise::Concerns::Controllers::Jpi::V1::Admin::SubscriptionEventsController | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
api/app/controllers/mno_enterprise/jpi/v1/subscription_events_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module MnoEnterprise | ||
class Jpi::V1::SubscriptionEventsController < Jpi::V1::BaseResourceController | ||
include MnoEnterprise::Concerns::Controllers::Jpi::V1::SubscriptionEventsController | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
api/app/views/mno_enterprise/jpi/v1/admin/organizations/_organization.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
json.extract! organization, :id, :name, :uid, :soa_enabled, :created_at, :account_frozen, :financial_metrics, :billing_currency | ||
json.extract! organization, :id, :name, :uid, :soa_enabled, :created_at, :account_frozen, :financial_metrics, :billing_currency, :external_id |
7 changes: 7 additions & 0 deletions
7
...p/views/mno_enterprise/jpi/v1/admin/subscription_events/_subscription_event.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
json.id subscription_event.id | ||
json.event_type subscription_event.event_type | ||
json.status subscription_event.status | ||
json.message subscription_event.message | ||
json.provisioning_data subscription_event.provisioning_data | ||
json.created_at subscription_event.created_at | ||
json.updated_at subscription_event.updated_at |
1 change: 1 addition & 0 deletions
1
api/app/views/mno_enterprise/jpi/v1/admin/subscription_events/index.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.subscription_events @subscription_events, partial: 'subscription_event', as: :subscription_event |
3 changes: 3 additions & 0 deletions
3
api/app/views/mno_enterprise/jpi/v1/admin/subscription_events/show.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.subscription_event do | ||
json.partial! 'subscription_event', subscription_event: @subscription_event | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
api/app/views/mno_enterprise/jpi/v1/subscription_events/_subscription_event.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
json.id subscription_event.id | ||
json.event_type subscription_event.event_type | ||
json.status subscription_event.status | ||
json.message subscription_event.message | ||
json.provisioning_data subscription_event.provisioning_data | ||
json.created_at subscription_event.created_at | ||
json.updated_at subscription_event.updated_at |
1 change: 1 addition & 0 deletions
1
api/app/views/mno_enterprise/jpi/v1/subscription_events/index.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.subscription_events @subscription_events, partial: 'subscription_event', as: :subscription_event |
3 changes: 3 additions & 0 deletions
3
api/app/views/mno_enterprise/jpi/v1/subscription_events/show.json.jbuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
json.subscription_event do | ||
json.partial! 'subscription_event', subscription_event: @subscription_event | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
api/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/subscription_events_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module MnoEnterprise::Concerns::Controllers::Jpi::V1::Admin::SubscriptionEventsController | ||
extend ActiveSupport::Concern | ||
|
||
SUBSCRIPTION_EVENT_INCLUDES ||= [:'subscription'] | ||
|
||
#================================================================== | ||
# Instance methods | ||
#================================================================== | ||
# GET /mnoe/jpi/v1/admin/organizations/1/subscriptions/xyz/subscription_events | ||
def index | ||
query = fetch_subscription_events(params[:organization_id], params[:subscription_id]) | ||
@subscription_events = query.to_a | ||
response.headers['X-Total-Count'] = query.meta.record_count | ||
end | ||
|
||
# GET /mnoe/jpi/v1/admin/organizations/1/subscriptions/xyz/subscription_events/id | ||
def show | ||
@subscription_event = fetch_subscription_event(params[:organization_id], params[:subscription_id], params[:id], SUBSCRIPTION_EVENT_INCLUDES) | ||
return render_not_found('SubscriptionEvent') unless @subscription_event | ||
end | ||
|
||
protected | ||
|
||
def fetch_subscription_events(organization_id, subscription_id) | ||
MnoEnterprise::SubscriptionEvent | ||
.apply_query_params(params) | ||
.with_params(_metadata: { act_as_manager: current_user.id, organization_id: organization_id }) | ||
.includes(SUBSCRIPTION_EVENT_INCLUDES) | ||
.where('subscription.id' => subscription_id) | ||
end | ||
|
||
def fetch_subscription_event(organization_id, subscription_id, id, includes = nil) | ||
rel = MnoEnterprise::SubscriptionEvent | ||
.with_params(_metadata: { act_as_manager: current_user.id, organization_id: organization_id }) | ||
.where('subscription.id' => subscription_id, id: id) | ||
rel = rel.includes(*includes) if includes.present? | ||
rel.first | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
api/lib/mno_enterprise/concerns/controllers/jpi/v1/admin/subscriptions_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscription_events_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module MnoEnterprise::Concerns::Controllers::Jpi::V1::SubscriptionEventsController | ||
extend ActiveSupport::Concern | ||
|
||
SUBSCRIPTION_EVENT_INCLUDES ||= [:'subscription'] | ||
|
||
#================================================================== | ||
# Instance methods | ||
#================================================================== | ||
# GET /mnoe/jpi/v1/organizations/1/subscriptions/xyz/subscription_events | ||
def index | ||
authorize! :manage_app_instances, parent_organization | ||
@subscription_events = fetch_subscription_events(parent_organization.id, params[:subscription_id]) | ||
end | ||
|
||
# GET /mnoe/jpi/v1/organizations/1/subscriptions/xyz/subscription_events/id | ||
def show | ||
authorize! :manage_app_instances, parent_organization | ||
@subscription_event = fetch_subscription_event(parent_organization.id, params[:subscription_id], params[:id]) | ||
end | ||
|
||
protected | ||
|
||
def fetch_subscription_events(organization_id, subscription_id) | ||
query = MnoEnterprise::SubscriptionEvent.with_params(_metadata: { organization_id: organization_id }) | ||
MnoEnterprise::SubscriptionEvent.fetch_all(query.includes(*SUBSCRIPTION_EVENT_INCLUDES).where('subscription.id' => subscription_id)) | ||
end | ||
|
||
def fetch_subscription_event(organization_id, subscription_id, id) | ||
query = MnoEnterprise::SubscriptionEvent.with_params(_metadata: { organization_id: organization_id }) | ||
query.includes(*SUBSCRIPTION_EVENT_INCLUDES).where('subscription.id' => subscription_id, id: id).first | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscriptions_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
api/spec/controllers/mno_enterprise/jpi/v1/admin/subscription_events_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'rails_helper' | ||
|
||
module MnoEnterprise | ||
describe Jpi::V1::Admin::SubscriptionEventsController, type: :controller do | ||
include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin | ||
|
||
render_views | ||
routes { MnoEnterprise::Engine.routes } | ||
before { request.env["HTTP_ACCEPT"] = 'application/json' } | ||
|
||
before(:each) do | ||
Settings.merge!(dashboard: { marketplace: {provisioning: true } }) | ||
Rails.application.reload_routes! | ||
end | ||
|
||
#=============================================== | ||
# Assignments | ||
#=============================================== | ||
let(:user) { build(:user, :admin) } | ||
let!(:current_user_stub) { stub_user(user) } | ||
|
||
let(:organization) { build(:organization) } | ||
let(:subscription) { build(:subscription) } | ||
let(:subscription_event) { build(:subscription_event, subscription: subscription) } | ||
|
||
#=============================================== | ||
# Specs | ||
#=============================================== | ||
before { sign_in user } | ||
|
||
describe 'GET #index' do | ||
subject { get :index, organization_id: organization.id, subscription_id: subscription.id } | ||
|
||
let(:data) { JSON.parse(response.body) } | ||
let(:includes) { [:'subscription'] } | ||
let(:expected_params) { { filter: { 'subscription.id': subscription.id }, _metadata: { act_as_manager: user.id, organization_id: organization.id } } } | ||
|
||
before { stub_api_v2(:get, "/subscription_events", [subscription_event], includes, expected_params) } | ||
|
||
it_behaves_like 'a jpi v1 admin action' | ||
|
||
it 'returns the subscription events' do | ||
subject | ||
expect(data['subscription_events'].first['id']).to eq(subscription_event.id) | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
subject { get :show, id: subscription_event.id, organization_id: organization.id, subscription_id: subscription.id } | ||
|
||
let(:data) { JSON.parse(response.body) } | ||
let(:includes) { [:'subscription'] } | ||
let(:expected_params) do | ||
{ | ||
filter: { id: subscription_event.id, 'subscription.id': subscription.id }, | ||
_metadata: { act_as_manager: user.id, organization_id: organization.id }, | ||
page: { number: 1, size: 1 } } | ||
end | ||
|
||
before { allow(subscription_event).to receive(:license_assignments).and_return([]) } | ||
before { allow(subscription_event).to receive(:organization).and_return(organization) } | ||
before { stub_api_v2(:get, "/subscription_events", subscription_event, includes, expected_params) } | ||
|
||
it_behaves_like 'a jpi v1 admin action' | ||
|
||
it 'returns the subscription event' do | ||
subject | ||
expect(data['subscription_event']['id']).to eq(subscription_event.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
api/spec/controllers/mno_enterprise/jpi/v1/subscription_events_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'rails_helper' | ||
|
||
module MnoEnterprise | ||
describe Jpi::V1::SubscriptionEventsController, type: :controller do | ||
include MnoEnterprise::TestingSupport::JpiV1TestHelper | ||
render_views | ||
routes { MnoEnterprise::Engine.routes } | ||
before { request.env['HTTP_ACCEPT'] = 'application/json' } | ||
|
||
before(:all) do | ||
Settings.merge!(dashboard: {marketplace: {provisioning: true}}) | ||
Rails.application.reload_routes! | ||
end | ||
|
||
# Stub controller ability | ||
let!(:ability) { stub_ability } | ||
before { allow(ability).to receive(:can?).with(any_args).and_return(true) } | ||
|
||
# Stub user and user call | ||
let!(:user) { build(:user) } | ||
let!(:current_user_stub) { stub_user(user) } | ||
|
||
# Stub organization and association | ||
let!(:organization) { build(:organization, orga_relations: []) } | ||
let!(:orga_relation) { organization.orga_relations << build(:orga_relation, user_id: user.id, organization_id: organization.id, role: 'Super Admin') } | ||
let!(:organization_stub) { stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(orga_relations users)) } | ||
|
||
describe 'GET #index' do | ||
let(:subscription) { build(:subscription) } | ||
let(:subscription_event) { build(:subscription_event, subscription: subscription) } | ||
|
||
let(:expected_params) do | ||
{ | ||
filter: { 'subscription.id': subscription.id }, | ||
_metadata: { organization_id: organization.id } | ||
} | ||
end | ||
before { stub_api_v2(:get, "/subscription_events", [subscription_event], [:subscription], expected_params) } | ||
before { sign_in user } | ||
|
||
subject { get :index, organization_id: organization.id, subscription_id: subscription.id } | ||
|
||
it_behaves_like 'jpi v1 protected action' | ||
end | ||
|
||
describe 'GET #show' do | ||
let(:subscription) { build(:subscription) } | ||
let(:subscription_event) { build(:subscription_event, subscription: subscription) } | ||
|
||
let(:expected_params) do | ||
{ | ||
filter: { id: subscription_event.id, 'subscription.id': subscription.id }, | ||
_metadata: { organization_id: organization.id }, | ||
page: { number: 1, size: 1 } | ||
} | ||
end | ||
before { stub_api_v2(:get, "/subscription_events", subscription_event, [:subscription], expected_params) } | ||
before { sign_in user } | ||
|
||
subject { get :show, organization_id: organization.id, subscription_id: subscription.id, id: subscription_event.id } | ||
|
||
it_behaves_like 'jpi v1 protected action' | ||
end | ||
end | ||
end |
Oops, something went wrong.