diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller.rb index 4ff61dde0..132ecf8a4 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller.rb @@ -3,7 +3,7 @@ class Jpi::V1::Admin::AppInstancesController < Jpi::V1::Admin::BaseResourceContr # DELETE /mnoe/jpi/v1/app_instances/1 def destroy - app_instance = MnoEnterprise::AppInstance.find_one(params[:id]) + app_instance = MnoEnterprise::AppInstance.find_one(params[:id], :owner) if app_instance MnoEnterprise::EventLogger.info('app_destroy', current_user.id, 'App destroyed', app_instance) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb index 94a085ac6..8e63fbfff 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/app_reviews_controller.rb @@ -52,6 +52,10 @@ def current_app @app ||= MnoEnterprise::App.find_one(params[:id]) end + def orga_relation + @orga_relation ||= MnoEnterprise::OrgaRelation.where('organization.id': organization_id, 'user.id': current_user.id).first + end + def ensure_app_exists render_not_found('App') unless current_app.present? end diff --git a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/app_instances_controller.rb b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/app_instances_controller.rb index 5eaf2d92a..7bd984fb2 100644 --- a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/app_instances_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/app_instances_controller.rb @@ -24,8 +24,8 @@ def index # POST /mnoe/jpi/v1/organization/1/app_instances def create authorize! :manage_app_instances, orga_relation - input = { data: { attributes: { app_nid: params[:nid], owner_id: parent_organization_id, owner_type: 'Organization' } } } - app_instance = MnoEnterprise::AppInstance.provision!(input) + app_instance = MnoEnterprise::AppInstance.provision!(params[:nid], parent_organization_id, 'Organization' ) + app_instance = app_instance.load_required(:owner) MnoEnterprise::EventLogger.info('app_add', current_user.id, 'App added', app_instance) head :created end diff --git a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb index 0acef38ae..d9111d0aa 100644 --- a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/current_users_controller.rb @@ -1,7 +1,7 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController extend ActiveSupport::Concern - INCLUDED_DEPENDENCIES = %i(organizations orga_relations dashboards teams orga_relations.user orga_relations.organization) + INCLUDED_DEPENDENCIES = %i(organizations orga_relations orga_relations.organization dashboards teams orga_relations.user orga_relations.organization) #================================================================== # Included methods @@ -28,7 +28,7 @@ def update changed_attributes = current_user.changed_attributes current_user.save! current_user.refresh_user_cache - MnoEnterprise::EventLogger.info('user_update', current_user.id, 'User update', @user, changed_attributes) + MnoEnterprise::EventLogger.info('user_update', current_user.id, 'User update', current_user, changed_attributes) @user = current_user.load_required(*INCLUDED_DEPENDENCIES) render :show end diff --git a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/products_controller.rb b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/products_controller.rb index bff655a05..309da42f7 100644 --- a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/products_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/products_controller.rb @@ -11,7 +11,7 @@ def index query = MnoEnterprise::Product.apply_query_params(params).includes(DEPENDENCIES).where(active: true) # Ensure prices include organization-specific markups/discounts - if params[:organization_id] && parent_organization + if params[:organization_id] && orga_relation query = query.with_params(_metadata: { organization_id: parent_organization_id }) end diff --git a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscription_events_controller.rb b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscription_events_controller.rb index 0f81787de..75275aa72 100644 --- a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscription_events_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscription_events_controller.rb @@ -8,14 +8,14 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::SubscriptionEventsControll #================================================================== # 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]) + authorize! :manage_app_instances, orga_relation + @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]) + authorize! :manage_app_instances, orga_relation + @subscription_event = fetch_subscription_event(parent_organization_id, params[:subscription_id], params[:id]) end protected diff --git a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscriptions_controller.rb b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscriptions_controller.rb index 2c6cb8bf7..ebd9584de 100644 --- a/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscriptions_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/jpi/v1/subscriptions_controller.rb @@ -8,19 +8,19 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::SubscriptionsController #================================================================== # GET /mnoe/jpi/v1/organizations/1/subscriptions def index - authorize! :manage_app_instances, parent_organization + authorize! :manage_app_instances, orga_relation @subscriptions = fetch_subscriptions(parent_organization_id) end # GET /mnoe/jpi/v1/organizations/1/subscriptions/id def show - authorize! :manage_app_instances, parent_organization + authorize! :manage_app_instances, orga_relation @subscription = fetch_subscription(parent_organization_id, params[:id]) end # POST /mnoe/jpi/v1/organizations/1/subscriptions def create - authorize! :manage_app_instances, parent_organization + authorize! :manage_app_instances, orga_relation subscription = MnoEnterprise::Subscription.new(subscription_update_params) subscription.relationships.organization = MnoEnterprise::Organization.new(id: parent_organization_id) @@ -40,7 +40,7 @@ def create # PUT /mnoe/jpi/v1/organizations/1/subscriptions/abc def update - authorize! :manage_app_instances, parent_organization + authorize! :manage_app_instances, orga_relation subscription = MnoEnterprise::Subscription.where(organization_id: parent_organization_id, id: params[:id]).first return render_not_found('subscription') unless subscription @@ -61,7 +61,7 @@ def update # POST /mnoe/jpi/v1/organizations/1/subscriptions/abc/cancel def cancel - authorize! :manage_app_instances, parent_organization + authorize! :manage_app_instances, orga_relation subscription = MnoEnterprise::Subscription.where(organization_id: parent_organization_id, id: params[:id]).first return render_not_found('subscription') unless subscription diff --git a/api/lib/mno_enterprise/concerns/controllers/pages_controller.rb b/api/lib/mno_enterprise/concerns/controllers/pages_controller.rb index 53d0ac037..f7d84a497 100644 --- a/api/lib/mno_enterprise/concerns/controllers/pages_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/pages_controller.rb @@ -25,7 +25,7 @@ module MnoEnterprise::Concerns::Controllers::PagesController # TODO: Access + existence checks could be added in the future. This is not # mandatory as Mno Enterprise will do it anyway def launch - app_instance = MnoEnterprise::AppInstance.where(uid: params[:id]).first + app_instance = MnoEnterprise::AppInstance.where(uid: params[:id]).includes(:owner).first MnoEnterprise::EventLogger.info('app_launch', current_user.id, 'App launched', app_instance) redirect_to MnoEnterprise.router.launch_url(params[:id], {wtk: MnoEnterprise.jwt(user_id: current_user.uid)}.reverse_merge(request.query_parameters)) end diff --git a/api/lib/mno_enterprise/concerns/controllers/provision_controller.rb b/api/lib/mno_enterprise/concerns/controllers/provision_controller.rb index c03764226..38a43e6cb 100644 --- a/api/lib/mno_enterprise/concerns/controllers/provision_controller.rb +++ b/api/lib/mno_enterprise/concerns/controllers/provision_controller.rb @@ -67,7 +67,8 @@ def create app_instances = [] params[:apps].each do |product_name| - app_instance = @organization.provision_app_instance!(product_name) + app_instance = MnoEnterprise::AppInstance.provision!(product_name, parent_organization_id, 'Organization' ) + app_instance = app_instance.load_required(:owner) app_instances << app_instance MnoEnterprise::EventLogger.info('app_add', current_user.id, 'App added', app_instance) end diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller_spec.rb index 1173769d7..512af63f1 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/app_instances_controller_spec.rb @@ -10,7 +10,8 @@ module MnoEnterprise before { request.env['HTTP_ACCEPT'] = 'application/json' } before { stub_audit_events } - let(:user) { build(:user, :admin, :with_organizations) } + let(:user) { build(:user, :admin) } + let(:organization) { build(:organization) } let!(:current_user_stub) { stub_user(user) } before do @@ -19,9 +20,9 @@ module MnoEnterprise describe 'DELETE #destroy' do # Stub AppInstance - let(:app_instance) { build(:app_instance) } + let(:app_instance) { build(:app_instance, owner: organization) } - before { stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance) } + before { stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance, [:owner]) } let!(:stub) { stub_api_v2(:delete, "/app_instances/#{app_instance.id}/terminate") } subject { delete :destroy, id: app_instance.id } diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb index 7cc1a8001..ffe30cced 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_controller_spec.rb @@ -54,6 +54,7 @@ module MnoEnterprise let!(:stub) { stub_api_v2(:post, '/app_instances/provision', app_instance) } before do sign_in user + stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance, [:owner]) end it do diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb index 1c6cb624c..123f2537e 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/app_instances_sync_controller_spec.rb @@ -24,10 +24,10 @@ module MnoEnterprise before { sign_in user } # Stub organization - let(:orga_relation) { build(:orga_relation) } + let(:orga_relation) { build(:orga_relation, role: 'Admin') } let!(:organization) { build(:organization) } before do - stub_orga_relation(user, organization, orga_relation) + stub_orga_relation(user, organization, orga_relation, 'uid') stub_api_v2(:get, '/organizations', [organization], [], { filter: { uid: organization.uid } }) end diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb index fcacfa6aa..f201d8b3c 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/current_users_controller_spec.rb @@ -87,17 +87,25 @@ def hash_for(res) end # Stub user retrieval - let!(:user) { build(:user, :with_organizations, :kpi_enabled) } + let(:organization) { build(:organization) } + let!(:user) { build(:user, :kpi_enabled, organizations: [organization], orga_relations: [orga_relation]) } + + let!(:orga_relation) { build(:orga_relation, organization: organization) } + let!(:current_user_stub) { stub_user(user) } before do - stub_user(user, MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController::INCLUDED_DEPENDENCIES) + stub_orga_relation(user, organization, orga_relation) stub_deletion_requests(user, []) end describe 'GET #show' do subject { get :show } + before do + stub_user(user, MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController::INCLUDED_DEPENDENCIES) + end + describe 'guest' do it 'is successful' do subject @@ -133,7 +141,7 @@ def hash_for(res) updated_user.attributes = attrs stub_api_v2(:patch, "/users/#{user.id}", updated_user) # user reload - stub_user(updated_user) + stub_user(updated_user, MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController::INCLUDED_DEPENDENCIES) } subject { put :update, user: attrs } @@ -153,24 +161,26 @@ def hash_for(res) end describe 'PUT #register_developer' do - before { stub_api_v2(:patch, "/users/#{user.id}/create_api_credentials", user) } - #user reload - before { stub_user(user) } - before { sign_in user } subject { put :register_developer } - + before do + sign_in user + stub_api_v2(:patch, "/users/#{user.id}/create_api_credentials", user) + #user reload + stub_user(user, MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController::INCLUDED_DEPENDENCIES) + subject + end describe 'logged in' do - before { subject } it { expect(response).to be_success } end end describe 'PUT #update_password' do + subject { put :update_password, user: attrs } + let(:attrs) { { current_password: 'password', password: 'blablabla', password_confirmation: 'blablabla' } } let!(:update_password_stub) { stub_api_v2(:patch, "/users/#{user.id}/update_password", user) } #user reload - before { stub_user(user) } - subject { put :update_password, user: attrs } + before { stub_user(user, MnoEnterprise::Concerns::Controllers::Jpi::V1::CurrentUsersController::INCLUDED_DEPENDENCIES) } it_behaves_like 'a user management action' diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb index e75591f68..530ef5b10 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/organizations_controller_spec.rb @@ -26,7 +26,7 @@ module MnoEnterprise let!(:organization_stub) { stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(users orga_invites orga_relations credit_card invoices)) } # Stub user and user call let!(:current_user_stub) { stub_user(user) } - + let(:role) { 'Admin' } before { sign_in user } # Advanced features - currently disabled @@ -68,7 +68,7 @@ module MnoEnterprise it_behaves_like 'jpi v1 protected action' - before { stub_orga_relation(user, organization, build(:orga_relation)) } + before { stub_orga_relation(user, organization, build(:orga_relation, role: role)) } context 'success' do before { subject } @@ -80,13 +80,10 @@ module MnoEnterprise end context 'contains invoices' do - subject { get :show, id: organization.id } - let(:money) { Money.new(0, 'AUD') } + subject { get :show, id: organization.id } let(:role) { 'Super Admin' } - let(:member_role) { role } - let(:member) { build(:user, id: user.id, email: user.email) } - + let(:money) { Money.new(0, 'AUD') } before do allow_any_instance_of(MnoEnterprise::Organization).to receive(:current_billing).and_return(money) allow_any_instance_of(MnoEnterprise::Organization).to receive(:current_credit).and_return(money) @@ -94,7 +91,6 @@ module MnoEnterprise stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(users orga_invites orga_relations credit_card invoices)) end - it 'renders the list of invoices' do subject expect(JSON.parse(response.body)['invoices']).to eq(partial_hash_for_invoices(organization)) @@ -107,6 +103,7 @@ module MnoEnterprise let(:orga_relation) { build(:orga_relation) } subject { post :create, organization: params } before do + stub_orga_relation(user, organization, orga_relation) stub_api_v2(:post, '/organizations', organization) stub_api_v2(:post, '/orga_relations', orga_relation) stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(users orga_invites orga_relations)) @@ -309,7 +306,6 @@ module MnoEnterprise stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(users orga_invites orga_relations credit_card invoices)) end before do - stub_orga_relation(user, organization, orga_relation) stub_api_v2(:get, "/orga_relations", [member_orga_relation], [], { filter: { organization_id: organization.id, user_id: member.id }, page: one_page }) stub_api_v2(:post, "/orga_relations/#{member_orga_relation.id}", orga_relation) stub_api_v2(:patch, "/orga_relations/#{member_orga_relation.id}") diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/products_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/products_controller_spec.rb index 69230c596..e4c2f5201 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/products_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/products_controller_spec.rb @@ -8,24 +8,23 @@ module MnoEnterprise before { request.env['HTTP_ACCEPT'] = 'application/json' } before(:all) do - Settings.merge!(dashboard: {marketplace: {local_products: true}}) + Settings.merge!(dashboard: { marketplace: { local_products: true } }) Rails.application.reload_routes! end # Stub user and user call let!(:user) { build(:user) } + let(:organization) { build(:organization) } let!(:current_user_stub) { stub_user(user) } + before do + stub_orga_relation(user, organization, build(:orga_relation)) + end describe 'GET #index' do subject { get :index, params } let(:params) { {} } let(:product) { build(:product) } - let(:organization) { - o = build(:organization, orga_relations: []) - o.orga_relations << build(:orga_relation, user_id: user.id, organization_id: o.id, role: 'Super Admin') - o - } before { sign_in user } @@ -40,7 +39,7 @@ module MnoEnterprise before { stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(orga_relations users)) } before do stub_api_v2(:get, "/products", [product], - [:'values.field', :assets, :categories, :product_pricings, :product_contracts], { filter: { active: true }, _metadata: { organization_id: organization.id } }) + [:'values.field', :assets, :categories, :product_pricings, :product_contracts], { filter: { active: true }, _metadata: { organization_id: organization.id } }) end it_behaves_like 'jpi v1 protected action' diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/subscription_events_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/subscription_events_controller_spec.rb index febcbff57..7c74cf2c0 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/subscription_events_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/subscription_events_controller_spec.rb @@ -21,9 +21,11 @@ module MnoEnterprise 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)) } + let!(:organization) { build(:organization) } + let!(:orga_relation) { build(:orga_relation, role: 'Super Admin') } + before do + stub_orga_relation(user, organization, orga_relation) + end describe 'GET #index' do let(:subscription) { build(:subscription) } diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/subscriptions_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/subscriptions_controller_spec.rb index 33eca247a..801f85aae 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/subscriptions_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/subscriptions_controller_spec.rb @@ -21,10 +21,11 @@ module MnoEnterprise 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)) } - + let!(:organization) { build(:organization) } + let!(:orga_relation) { build(:orga_relation, role: 'Super Admin') } + before do + stub_orga_relation(user, organization, orga_relation) + end # Stub license_assignments association before { allow_any_instance_of(MnoEnterprise::Subscription).to receive(:license_assignments).and_return([]) } diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb index 3561a36d3..0e5af9ed0 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/team_controller_spec.rb @@ -61,7 +61,7 @@ def hash_for_team(team) subject { put :add_users, id: team.id, team: {users: [{id: user.id}]} } before do stub_user(user) - stub_orga_relation + stub_orga_relation(user, organization, build(:orga_relation)) stub_api_v2(:get, "/apps", [app]) stub_api_v2(:get, "/organizations/#{organization.id}", organization, %i(orga_relations)) stub_api_v2(:get, "/teams/#{team.id}", team, %i(organization)) @@ -71,8 +71,6 @@ def hash_for_team(team) stub_audit_events end - - context 'success' do before { subject } diff --git a/api/spec/controllers/mno_enterprise/pages_controller_spec.rb b/api/spec/controllers/mno_enterprise/pages_controller_spec.rb index cedf2db42..77e089480 100644 --- a/api/spec/controllers/mno_enterprise/pages_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/pages_controller_spec.rb @@ -16,7 +16,7 @@ module MnoEnterprise before do stub_user(user) - stub_api_v2(:get, '/app_instances', [app_instance], [], {filter:{uid: app_instance.uid}, page:{number: 1, size: 1}}) + stub_api_v2(:get, '/app_instances', [app_instance], [:owner], { filter: { uid: app_instance.uid }, page: one_page }) end describe 'GET #launch' do @@ -28,7 +28,7 @@ module MnoEnterprise it 'redirect to the mno enterprise launch page with a web token' do subject - expect(response).to redirect_to(MnoEnterprise.router.launch_url(app_instance.uid, wtk: MnoEnterprise.jwt({user_id: user.uid}))) + expect(response).to redirect_to(MnoEnterprise.router.launch_url(app_instance.uid, wtk: MnoEnterprise.jwt({ user_id: user.uid }))) end end @@ -41,7 +41,7 @@ module MnoEnterprise it 'redirects to the mno enterprise launch page with a web token and extra params' do subject - expect(response).to redirect_to(MnoEnterprise.router.launch_url(app_instance.uid, wtk: MnoEnterprise.jwt({user_id: user.uid}), specific_parameters: 'specific_parameters_value')) + expect(response).to redirect_to(MnoEnterprise.router.launch_url(app_instance.uid, wtk: MnoEnterprise.jwt({ user_id: user.uid }), specific_parameters: 'specific_parameters_value')) end end @@ -66,7 +66,7 @@ module MnoEnterprise describe 'GET #terms' do let(:app) { build(:app) } before { - stub_api_v2(:get, '/apps', [app], [], {fields: {apps: 'updated_at'}, page: {number: 1, size: 1}, sort: '-updated_at'}) + stub_api_v2(:get, '/apps', [app], [], { fields: { apps: 'updated_at' }, page: { number: 1, size: 1 }, sort: '-updated_at' }) stub_api_v2(:get, '/apps', [app], []) } @@ -74,6 +74,5 @@ module MnoEnterprise before { subject } it { expect(response).to be_success } end - end end diff --git a/api/spec/controllers/mno_enterprise/provision_controller_spec.rb b/api/spec/controllers/mno_enterprise/provision_controller_spec.rb index 0b5dd05ed..cf485542b 100644 --- a/api/spec/controllers/mno_enterprise/provision_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/provision_controller_spec.rb @@ -109,6 +109,7 @@ module MnoEnterprise subject { post :create, params } before do stub_api_v2(:post, "/app_instances/provision", app_instance) + stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance, [:owner]) end describe 'guest' do diff --git a/api/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb b/api/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb index 12110d7e2..354ab6c26 100644 --- a/api/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb +++ b/api/spec/mailer/mno_enterprise/system_notification_mailer_spec.rb @@ -9,7 +9,7 @@ module MnoEnterprise end let(:routes) { MnoEnterprise::Engine.routes.url_helpers } let(:user) { build(:user) } - let(:token) { "1sd5f323S1D5AS" } + let(:token) { '1sd5f323S1D5AS' } let(:deletion_request) { build(:deletion_request) } # Commonly used mandrill variables diff --git a/core/app/models/mno_enterprise/orga_relation.rb b/core/app/models/mno_enterprise/orga_relation.rb index de5deefa1..503f71a9e 100644 --- a/core/app/models/mno_enterprise/orga_relation.rb +++ b/core/app/models/mno_enterprise/orga_relation.rb @@ -9,6 +9,5 @@ class OrgaRelation < BaseResource has_one :organization has_one :user - end end diff --git a/core/lib/json_api_client_extension/has_one_extension.rb b/core/lib/json_api_client_extension/has_one_extension.rb index 491179a5a..e02ad0e72 100644 --- a/core/lib/json_api_client_extension/has_one_extension.rb +++ b/core/lib/json_api_client_extension/has_one_extension.rb @@ -6,14 +6,11 @@ def has_one(attr_name, options = {}) class_eval <<-CODE def #{attr_name}_id=(id) ActiveSupport::Deprecation.warn(self.class.name + ".#{attr_name}_id Use relationships instead") - association = id ? {data: {type: "#{attr_name.to_s.pluralize}", id: id.to_s}} : nil - self.relationships.#{attr_name} = association + super end def #{attr_name}_id - # First we try in the relationship - relationship_definitions = self.relationships.try(:#{attr_name}) - return nil unless relationship_definitions - relationship_definitions.dig(:data, :id) + ActiveSupport::Deprecation.warn(self.class.name + ".#{attr_name}_id Use relationships instead") + super end def #{attr_name}=(relation) self.relationships.#{attr_name} = relation diff --git a/core/lib/mno_enterprise/concerns/models/app_instance.rb b/core/lib/mno_enterprise/concerns/models/app_instance.rb index 64c6417c2..3dac8fcc8 100644 --- a/core/lib/mno_enterprise/concerns/models/app_instance.rb +++ b/core/lib/mno_enterprise/concerns/models/app_instance.rb @@ -27,7 +27,8 @@ module MnoEnterprise::Concerns::Models::AppInstance # Class methods #================================================================== module ClassMethods - def provision!(input) + def provision!(app_nid, owner_id, owner_type) + input = { data: { attributes: { app_nid: app_nid, owner_id: owner_id, owner_type: owner_type} } } result = provision(input) process_custom_result(result) end @@ -48,7 +49,7 @@ def to_audit_event uid: uid, name: name, app_nid: app_nid, - organization_id: owner_id + organization_id: owner.id } end