Class: Decidim::Consultations::Admin::ConsultationsController

Inherits:
ApplicationController show all
Includes:
Filterable
Defined in:
decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb

Overview

Controller in charge of managing consultation related requests

Instance Method Summary collapse

Methods included from RegistersPermissions

register_permissions

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject

POST /admin/consultations


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb', line 24

def create
  enforce_permission_to :create, :consultation
  @form = consultation_form.from_params(params)

  CreateConsultation.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("consultations.create.success", scope: "decidim.admin")
      redirect_to consultations_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("consultations.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#editObject

GET /admin/consultations/:slug/edit


42
43
44
45
46
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb', line 42

def edit
  enforce_permission_to :update, :consultation, consultation: current_consultation
  @form = consultation_form.from_model(current_consultation)
  render layout: "decidim/admin/consultation"
end

#indexObject

GET /admin/consultations


12
13
14
15
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb', line 12

def index
  enforce_permission_to :read, :consultation
  @consultations = filtered_collection
end

#newObject

GET /admin/consultations/new


18
19
20
21
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb', line 18

def new
  enforce_permission_to :create, :consultation
  @form = consultation_form.instance
end

#resultsObject

GET /admin/consultations/:slug/results


69
70
71
72
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb', line 69

def results
  enforce_permission_to :read, :consultation, consultation: current_consultation
  render layout: "decidim/admin/consultation"
end

#updateObject

PUT /admin/consultations/:slug


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'decidim-consultations/app/controllers/decidim/consultations/admin/consultations_controller.rb', line 49

def update
  enforce_permission_to :update, :consultation, consultation: current_consultation

  @form = consultation_form
          .from_params(params.except(:slug), consultation_id: current_consultation.id)

  UpdateConsultation.call(current_consultation, @form) do
    on(:ok) do |consultation|
      flash[:notice] = I18n.t("consultations.update.success", scope: "decidim.admin")
      redirect_to edit_consultation_path(consultation)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("consultations.update.error", scope: "decidim.admin")
      render :edit, layout: "decidim/admin/consultation"
    end
  end
end