Skip to content
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

[TODO SPECS]: Fix dashboard owner_type forced as User on update #557

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
json.array! @dashboards, partial: 'dashboard', as: :dashboard
# Fully qualify template path to allow concern to be included in different modules
json.array! @dashboards, partial: 'mno_enterprise/jpi/v1/impac/dashboards/dashboard', as: :dashboard
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
json.partial! 'dashboard', dashboard: @dashboard
# Fully qualify template path to allow concern to be included in different modules
json.partial! 'mno_enterprise/jpi/v1/impac/dashboards/dashboard', dashboard: @dashboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,33 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::DashboardsControlle
# GET /mnoe/jpi/v1/impac/dashboards
def index
dashboards

# Fully qualify template path to allow concern to be included in different modules
render template: 'mno_enterprise/jpi/v1/impac/dashboards/index'
end

# GET /mnoe/jpi/v1/impac/dashboards/1
# -> GET /api/mnoe/v1/users/1/dashboards
def show
render_not_found('dashboard') unless dashboard(*DASHBOARD_DEPENDENCIES)

# Fully qualify template path to allow concern to be included in different modules
render template: 'mno_enterprise/jpi/v1/impac/dashboards/show'
end

# POST /mnoe/jpi/v1/impac/dashboards
# -> POST /api/mnoe/v1/users/1/dashboards
def create
# TODO: dashboards.build breaks as dashboard.organization_ids returns nil, instead of an
# empty array. (see MnoEnterprise::Impac::Dashboard #organizations)
# @dashboard = dashboards.build(dashboard_create_params)
# TODO: enable authorization
# authorize! :manage_dashboard, @dashboard
# if @dashboard.save
@dashboard = MnoEnterprise::Dashboard.create!(dashboard_create_params)
MnoEnterprise::EventLogger.info('dashboard_create', current_user.id, 'Dashboard Creation', @dashboard)
dashboard = MnoEnterprise::Dashboard.new(dashboard_params)
dashboard.relationships.owner = current_user
dashboard.save!
MnoEnterprise::EventLogger.info('dashboard_create', current_user.id, 'Dashboard Creation', dashboard)
@dashboard = dashboard.load_required(*DASHBOARD_DEPENDENCIES)
render 'show'

# Fully qualify template path to allow concern to be included in different modules
render template: 'mno_enterprise/jpi/v1/impac/dashboards/show'
end

# PUT /mnoe/jpi/v1/impac/dashboards/1
Expand All @@ -48,11 +54,13 @@ def update

# TODO: enable authorization
# authorize! :manage_dashboard, dashboard
dashboard.update_attributes!(dashboard_update_params)
dashboard.update_attributes!(dashboard_params)

# Reload Dashboard
@dashboard = dashboard.load_required(DASHBOARD_DEPENDENCIES)
render 'show'

# Fully qualify template path to allow concern to be included in different modules
render template: 'mno_enterprise/jpi/v1/impac/dashboards/show'
end

# DELETE /mnoe/jpi/v1/impac/dashboards/1
Expand Down Expand Up @@ -82,21 +90,22 @@ def copy
private

def dashboard(*included)
# TODO: [APIv2] Improve filtering by owner (owner_type?)
@dashboard ||= MnoEnterprise::Dashboard.where(owner_id: current_user.id).includes(included).find(params[:id].to_i).first
@dashboard ||= MnoEnterprise::Dashboard.where(id: params[:id])
.includes(included)
.first
end

def dashboards
# TODO: [APIv2] Improve filtering by owner (owner_type?)
@dashboards ||= MnoEnterprise::Dashboard.includes(*DASHBOARD_DEPENDENCIES).find(owner_id: current_user.id)
@dashboards ||= MnoEnterprise::Dashboard.where(owner_id: current_user.id)
.includes(*DASHBOARD_DEPENDENCIES)
end

def templates
@templates ||= MnoEnterprise::Dashboard.templates
end

def template
@template ||= MnoEnterprise::Dashboard.templates.find(params[:id].to_i).first
@template ||= MnoEnterprise::Dashboard.templates.find(params[:id]).first
end

def whitelisted_params
Expand All @@ -110,9 +119,5 @@ def dashboard_params
whitelisted[:settings] = params[:dashboard][:metadata] || {}
end
.except(:metadata)
.merge(owner_type: "User", owner_id: current_user.id)
end
alias :dashboard_update_params :dashboard_params
alias :dashboard_create_params :dashboard_params

end
2 changes: 2 additions & 0 deletions core/app/models/mno_enterprise/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Dashboard < BaseResource
property :updated_at, type: :time
property :owner_id, type: :string

has_one :owner

# TODO: APIv2 - Is this needed?
# default_scope -> { where(dashboard_type: 'dashboard') }

Expand Down