diff --git a/api/config/routes.rb b/api/config/routes.rb index d99c117af..524ee8de9 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -143,6 +143,7 @@ get :sync_history get :id_maps post :disconnect + put :update_addon_synchronized_entities end 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 992e03243..6b0f092a6 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 @@ -45,7 +45,7 @@ def destroy def setup_form app_instance = MnoEnterprise::AppInstance.find_one(params[:id], :app, :owner) authorize! :manage_app_instances, app_instance.owner - response = MnoEnterprise::AddOnHelper.send_request(app_instance, :get, '/setup_form') + response = MnoEnterprise::AddOnHelper.send_request(app_instance, :get, '/maestrano/api/account/setup_form') render json: JSON.parse(response.body) end @@ -55,7 +55,7 @@ def create_omniauth app_instance = MnoEnterprise::AppInstance.find_one(params[:id], :app, :owner) authorize! :manage_app_instances, app_instance.owner body = params[:app_instance].merge!(org_uid: app_instance.channel_id) - response = MnoEnterprise::AddOnHelper.send_request(app_instance, :post, "/auth/#{app_instance.name.downcase}/request", body: body) + response = MnoEnterprise::AddOnHelper.send_request(app_instance, :post, "/maestrano/api/account/link_account", body: body) MnoEnterprise::EventLogger.info('addon_create_omniauth', current_user.id, 'Link account to add_on', app_instance) render json: JSON.parse(response.body) end @@ -66,7 +66,7 @@ def sync authorize! :manage_app_instances, app_instance.owner body = { group_id: app_instance.uid, opts: { full_sync: params[:full_sync] } } response = MnoEnterprise::AddOnHelper.send_request(app_instance, :post, app_instance.metadata['app']['synchronization_start_path'], body: body) - MnoEnterprise::EventLogger.info('addon_syn', current_user.id, 'Launch sync on add_on', app_instance) + MnoEnterprise::EventLogger.info('addon_sync', current_user.id, 'Launch sync on add_on', app_instance) head :accepted end @@ -75,7 +75,7 @@ def disconnect app_instance = MnoEnterprise::AppInstance.find_one(params[:id], :app, :owner) authorize! :manage_app_instances, app_instance.owner body = { uid: app_instance.uid } - response = MnoEnterprise::AddOnHelper.send_request(app_instance, :post, '/disconnect', body: body) + response = MnoEnterprise::AddOnHelper.send_request(app_instance, :post, '/maestrano/api/account/unlink_account', body: body) MnoEnterprise::EventLogger.info('addon_disconnect', current_user.id, 'Unlink account from add_on', app_instance) head :accepted end @@ -87,7 +87,6 @@ def sync_history authorize! :manage_app_instances, app_instance.owner syncs = app_instance.sync_history(params.except(:id, :organization_id, :action, :controller)) response.headers['x-total-count'] = syncs.meta[:record_count] - MnoEnterprise::EventLogger.info('addon_sync_history', current_user.id, 'Get list of add_on syncs', app_instance) render json: syncs.as_json end @@ -98,7 +97,23 @@ def id_maps authorize! :manage_app_instances, app_instance.owner id_maps = app_instance.id_maps(params.except(:id, :organization_id, :action, :controller)) response.headers['x-total-count'] = id_maps.meta[:record_count] - MnoEnterprise::EventLogger.info('addon_id_maps', current_user.id, 'Get list of add_on id_maps', app_instance) render json: id_maps.as_json end + + # PUT /mnoe/jpi/v1/organization/1/app_instances/11/update_addon_synchronized_entities + def update_addon_synchronized_entities + app_instance = MnoEnterprise::AppInstance.find_one(params[:id], :app, :owner) + authorize! :manage_app_instances, app_instance.owner + body = { + data: { + type: 'organizations', + id: params[:org_id], + attributes: { + synchronized_entities: params[:entities] + } + } + } + MnoEnterprise::AddOnHelper.send_request(app_instance, :put, "/maestrano/api/organizations/#{params[:org_id]}", body: body.to_json, headers: {'Content-Type' => 'application/vnd.api+json'}) + head :accepted + end end 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 d6f7f3ca5..657fd5fd9 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 @@ -93,7 +93,7 @@ module MnoEnterprise let(:app_instance) { build(:app_instance, metadata: { app: { host: 'http://www.addon-url.com'} }) } let(:form) { { form: {} } } before { stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance, [:app, :owner])} - before { stub_add_on(app_instance, :get, '/setup_form', 200, form) } + before { stub_add_on(app_instance, :get, '/maestrano/api/account/setup_form', 200, form) } before { sign_in user } subject { get :setup_form, id: app_instance.id } @@ -109,7 +109,7 @@ module MnoEnterprise before { stub_audit_events } let(:app_instance) { build(:app_instance, metadata: { app: { host: 'http://www.addon-url.com' } }) } before { stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance, [:app, :owner])} - before { stub_add_on(app_instance, :post, "/auth/#{app_instance.name.downcase}/request", 202) } + before { stub_add_on(app_instance, :post, "/maestrano/api/account/link_account", 202) } before { sign_in user } subject { post :create_omniauth, id: app_instance.id, app_instance: {} } @@ -141,7 +141,7 @@ module MnoEnterprise before { stub_audit_events } let(:app_instance) { build(:app_instance, metadata: { app: { host: 'http://www.addon-url.com' } }) } before { stub_api_v2(:get, "/app_instances/#{app_instance.id}", app_instance, [:app, :owner])} - before { stub_add_on(app_instance, :post, '/disconnect', 202) } + before { stub_add_on(app_instance, :post, '/maestrano/api/account/unlink_account', 202) } before { sign_in user } subject { post :disconnect, id: app_instance.id } diff --git a/core/lib/mno_enterprise/core.rb b/core/lib/mno_enterprise/core.rb index e35594cec..e691674ce 100644 --- a/core/lib/mno_enterprise/core.rb +++ b/core/lib/mno_enterprise/core.rb @@ -289,7 +289,7 @@ def self.configure_api connection.use Faraday::Response::Logger # Instrumentation (see below for the subscription) - connection.use FaradayMiddleware::Instrumentation if Rails.env.development? + connection.use FaradayMiddleware::Instrumentation end end end