module MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::DashboardsController
Public Instance Methods
copy()
click to toggle source
Allows to create a dashboard using another dashboard as a source At the moment, only dashboards of type “template” can be copied Ultimately we could allow the creation of dashboards from any other dashboard
POST mnoe/jpi/v1/impac/dashboards/1/copy
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 73 def copy return render_not_found('template') unless template authorize! :create_impac_dashboards, template # Owner is the current user by default, can be overriden to something else (eg: current organization) @dashboard = template.copy(current_user, dashboard_params[:name], dashboard_params[:organization_ids]) return render_bad_request('copy template', 'Unable to copy template') unless dashboard.present? render 'show' end
create()
click to toggle source
POST /mnoe/jpi/v1/impac/dashboards
-> POST /api/mnoe/v1/users/1/dashboards
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 30 def create authorize! :create_impac_dashboards, dashboards.build(dashboard_create_params) if @dashboard = dashboards.create(dashboard_create_params) MnoEnterprise::EventLogger.info('dashboard_create', current_user.id, 'Dashboard Creation', @dashboard) render 'show' else render_bad_request('create dashboard', @dashboard.errors) end end
destroy()
click to toggle source
DELETE /mnoe/jpi/v1/impac/dashboards/1
-> DELETE /api/mnoe/v1/dashboards/1
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 56 def destroy return render_not_found('dashboard') unless dashboard authorize! :destroy_impac_dashboards, dashboard if dashboard.destroy MnoEnterprise::EventLogger.info('dashboard_delete', current_user.id, 'Dashboard Deletion', dashboard) head status: :ok else render_bad_request('destroy dashboard', 'Unable to destroy dashboard') end end
index()
click to toggle source
show()
click to toggle source
GET /mnoe/jpi/v1/impac/dashboards/1
-> GET /api/mnoe/v1/users/1/dashboards
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 23 def show dashboard render_not_found('dashboard') unless @dashboard end
update()
click to toggle source
PUT /mnoe/jpi/v1/impac/dashboards/1
-> PUT /api/mnoe/v1/dashboards/1
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 43 def update return render_not_found('dashboard') unless dashboard authorize! :update_impac_dashboards, dashboard if dashboard.update(dashboard_update_params) render 'show' else render_bad_request('update dashboard', dashboard.errors) end end
Private Instance Methods
dashboard()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 90 def dashboard @dashboard ||= current_user.dashboards.find(params[:id].to_i) end
dashboard_params()
click to toggle source
Allows all metadata attrs to be permitted, and maps it to :settings for the Her “meta_data” issue.
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 108 def dashboard_params params.require(:dashboard).permit(*whitelisted_params).tap do |whitelisted| whitelisted[:settings] = params[:dashboard][:metadata] || {} end .except(:metadata) end
Also aliased as: dashboard_update_params, dashboard_create_params
dashboards()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 86 def dashboards @dashboards ||= current_user.dashboards end
template()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 98 def template @template ||= templates.find(params[:id].to_i) end
templates()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 94 def templates @templates ||= MnoEnterprise::Impac::Dashboard.templates end
whitelisted_params()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb, line 102 def whitelisted_params [:name, :currency, { widgets_order: [] }, { organization_ids: [] }] end