Skip to content

Commit

Permalink
New endpoint to update organization, and update old ones
Browse files Browse the repository at this point in the history
  • Loading branch information
manu-d committed Nov 26, 2017
1 parent b932a02 commit 4032d5b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
get :sync_history
get :id_maps
post :disconnect
put :update_addon_synchronized_entities
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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: {} }

Expand Down Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion core/lib/mno_enterprise/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4032d5b

Please sign in to comment.