-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MNOE-428] Migrate mno-enterprise to MnoHub API V2 #281
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
json.audit_events do | ||
json.array! @audit_events, partial: 'audit_event', as: :audit_event | ||
end | ||
json.metadata @audit_events.metadata | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,24 +27,26 @@ json.cache! ['v1', @user.cache_key] do | |
# Embed association if user is persisted | ||
if @user.id | ||
json.organizations do | ||
json.array! (@user.organizations.active || []) do |o| | ||
json.array! (@user.organizations.select(&:active?) || []) do |o| | ||
json.id o.id | ||
json.uid o.uid | ||
json.name o.name | ||
json.currency o.billing_currency | ||
json.current_user_role o.role | ||
json.has_myob_essentials_only o.has_myob_essentials_only? | ||
json.current_user_role @user.role(o) | ||
json.has_myob_essentials_only o.has_myob_essentials_only | ||
json.financial_year_end_month o.financial_year_end_month | ||
end | ||
end | ||
|
||
if @user.deletion_request.present? | ||
if @user.current_deletion_request.present? | ||
json.deletion_request do | ||
json.extract! @user.deletion_request, :id, :token | ||
json.extract! @user.current_deletion_request, :id, :token | ||
end | ||
end | ||
|
||
json.kpi_enabled [email protected]_enabled | ||
end | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
json.ignore_nil! | ||
json.extract! alert, :id, :title, :webhook, :service, :sent | ||
json.metadata alert.settings | ||
json.kpi_id alert.impac_kpi_id | ||
json.kpi_id alert.kpi_id | ||
json.recipients alert.recipients.map do |recipient| | ||
json.extract! recipient, :id, :email | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,17 @@ json.average_rating app.average_rating | |
json.add_on app.add_on? | ||
json.running_instances_count app.running_instances_count | ||
|
||
json.shared_entities do | ||
json.array! app.shared_entities do |shared_entity| | ||
json.extract! shared_entity, :shared_entity_nid, :shared_entity_name, :write, :read | ||
if app.app_shared_entities.any? | ||
json.app_shared_entities do | ||
json.array! app.app_shared_entities do |shared_entity| | ||
json.shared_entity_nid shared_entity.shared_entity.nid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it's not taking the fields name by name, it is mapping |
||
json.shared_entity_name shared_entity.shared_entity&.name | ||
json.shared_entity_name shared_entity.shared_entity&.name | ||
json.write shared_entity.write | ||
json.read shared_entity.read | ||
end | ||
end | ||
end if app.shared_entities.any? | ||
end | ||
|
||
if app.logo | ||
json.logo app.logo.to_s | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ json.id user.id | |
json.name user.name | ||
json.surname user.surname | ||
json.email user.email | ||
json.role organization.members.to_a.find { |e| e.id == user.id }.role | ||
json.role user.role(organization) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a couple calls like this. What is the effect in terms of performance? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no performance issue, as the user is already loaded with it's organization. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
json.invoices do | ||
# TODO: Introduce pagination | ||
json.array! organization.invoices.order_by('ended_at.desc').limit(12) do |invoice| | ||
json.period invoice.period_label | ||
json.amount AccountingjsSerializer.serialize(invoice.total_due) | ||
json.paid invoice.paid? | ||
json.link mno_enterprise.invoice_path(invoice.slug) | ||
end | ||
json.array! [] | ||
# TODO [MIGRATION_V2] remove and replace by a call to /organizations/id/invoices | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,23 @@ | |
|
||
module MnoEnterprise | ||
class AuditEventsListener | ||
include HTTParty | ||
base_uri "#{MnoEnterprise.mno_api_private_host || MnoEnterprise.mno_api_host}/api/mnoe/v1/audit_events" | ||
read_timeout 0.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we still have a short read timeout here? As we don't care about the response. |
||
basic_auth MnoEnterprise.tenant_id, MnoEnterprise.tenant_key | ||
|
||
def info(key, current_user_id, description, subject_type, subject_id, metadata) | ||
data = { | ||
key: key, | ||
user_id: current_user_id, | ||
description: description, | ||
metadata: metadata, | ||
subject_type: subject_type, | ||
subject_id: subject_id, | ||
} | ||
organization_id = if (subject_type == 'MnoEnterprise::Organization') then | ||
subject_id | ||
elsif metadata.is_a?(Hash) | ||
metadata[:organization_id].presence | ||
end | ||
body = { | ||
data: { | ||
key: key, | ||
user_id: current_user_id, | ||
description: description, | ||
metadata: metadata, | ||
subject_type: subject_type, | ||
subject_id: subject_id, | ||
} | ||
} | ||
body[:data][:organization_id] = organization_id if organization_id | ||
self.class.post('', body: body) | ||
rescue Net::ReadTimeout | ||
# Meant to fail | ||
data[:organization_id] = organization_id if organization_id | ||
MnoEnterprise::AuditEvent.create(data) | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,31 +13,33 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::AppInstancesController | |
#================================================================== | ||
# Instance methods | ||
#================================================================== | ||
# GET /mnoe/jpi/v1/organization/1/apps.json?timestamp=151452452345 | ||
# GET /mnoe/jpi/v1/organization/1/app_instances | ||
def index | ||
@app_instances = parent_organization.app_instances.active.where("updated_at.gt" => Time.at(timestamp)).select do |i| | ||
# force owner assignment to avoid a refetch in ability can?(:access,i) | ||
i.owner = parent_organization | ||
@app_instances = MnoEnterprise::AppInstance.includes(:app, :owner).where(owner_id: parent_organization.id, 'status.in': MnoEnterprise::AppInstance::ACTIVE_STATUSES).to_a.select do |i| | ||
can?(:access,i) | ||
end | ||
end | ||
|
||
# POST /mnoe/jpi/v1/organization/1/app_instances | ||
def create | ||
authorize! :manage_app_instances, parent_organization | ||
app_instance = parent_organization.app_instances.create(product: params[:nid]) | ||
MnoEnterprise::EventLogger.info('app_add', current_user.id, 'App added', app_instance) | ||
head :created | ||
app_instance = parent_organization.provision_app_instance(params[:nid]) | ||
if app_instance.errors.any? | ||
render json: app_instance.errors, status: :bad_request | ||
else | ||
MnoEnterprise::EventLogger.info('app_add', current_user.id, 'App added', app_instance.first) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, but this is the way of working of json_api_client, everything returned is always an array. |
||
head :created | ||
end | ||
end | ||
|
||
# DELETE /mnoe/jpi/v1/app_instances/1 | ||
def destroy | ||
app_instance = MnoEnterprise::AppInstance.find(params[:id]) | ||
@app_instance = MnoEnterprise::AppInstance.find_one(params[:id]) | ||
|
||
if app_instance | ||
authorize! :manage_app_instances, app_instance.owner | ||
MnoEnterprise::EventLogger.info('app_destroy', current_user.id, 'App destroyed', app_instance) | ||
app_instance.terminate | ||
if @app_instance | ||
authorize! :manage_app_instances, @app_instance.owner | ||
MnoEnterprise::EventLogger.info('app_destroy', current_user.id, 'App destroyed', @app_instance) | ||
@app_instance = @app_instance.terminate.first | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, JsonApiClient/json_api_client#75
|
||
end | ||
|
||
head :accepted | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response is changing from
shared_entities
toapp_shared_entities
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The app contains a list of app_shared_entities in the v2 api.