Module: MnoEnterprise::Concerns::Controllers::Jpi::V1::Impac::DashboardsController

Extended by:
ActiveSupport::Concern
Included in:
Jpi::V1::Impac::DashboardsController
Defined in:
lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb

Instance Method Summary collapse

Instance Method Details

#copyObject

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



73
74
75
76
77
78
79
80
81
82
# 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

#createObject

POST /mnoe/jpi/v1/impac/dashboards

-> POST /api/mnoe/v1/users/1/dashboards


30
31
32
33
34
35
36
37
38
39
# 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

#destroyObject

DELETE /mnoe/jpi/v1/impac/dashboards/1

-> DELETE /api/mnoe/v1/dashboards/1


56
57
58
59
60
61
62
63
64
65
66
# 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

#indexObject

Instance methods

GET /mnoe/jpi/v1/impac/dashboards



17
18
19
# File 'lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb', line 17

def index
  dashboards
end

#showObject

GET /mnoe/jpi/v1/impac/dashboards/1

-> GET /api/mnoe/v1/users/1/dashboards


23
24
25
26
# File 'lib/mno_enterprise/concerns/controllers/jpi/v1/impac/dashboards_controller.rb', line 23

def show
  dashboard
  render_not_found('dashboard') unless @dashboard
end

#updateObject

PUT /mnoe/jpi/v1/impac/dashboards/1

-> PUT /api/mnoe/v1/dashboards/1


43
44
45
46
47
48
49
50
51
52
# 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