Class: Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessesController

Inherits:
ApplicationController show all
Includes:
Admin::ParticipatorySpaceAdminContext, Filterable
Defined in:
decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb

Overview

Controller that allows managing participatory processes.

Instance Method Summary collapse

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 RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#copyObject


73
74
75
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb', line 73

def copy
  enforce_permission_to :create, Decidim::ParticipatoryProcess
end

#createObject


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb', line 30

def create
  enforce_permission_to :create, :process
  @form = form(ParticipatoryProcessForm).from_params(params)

  CreateParticipatoryProcess.call(@form) do
    on(:ok) do |participatory_process|
      flash[:notice] = I18n.t("participatory_processes.create.success", scope: "decidim.admin")
      redirect_to participatory_process_steps_path(participatory_process)
    end

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

#editObject


47
48
49
50
51
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb', line 47

def edit
  enforce_permission_to :update, :process, process: current_participatory_process
  @form = form(ParticipatoryProcessForm).from_model(current_participatory_process)
  render layout: "decidim/admin/participatory_process"
end

#indexObject


20
21
22
23
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb', line 20

def index
  enforce_permission_to :read, :process_list
  @participatory_processes = filtered_collection
end

#newObject


25
26
27
28
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb', line 25

def new
  enforce_permission_to :create, :process
  @form = form(ParticipatoryProcessForm).instance
end

#updateObject


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb', line 53

def update
  enforce_permission_to :update, :process, process: current_participatory_process
  @form = form(ParticipatoryProcessForm).from_params(
    participatory_process_params,
    process_id: current_participatory_process.id
  )

  UpdateParticipatoryProcess.call(current_participatory_process, @form) do
    on(:ok) do |participatory_process|
      flash[:notice] = I18n.t("participatory_processes.update.success", scope: "decidim.admin")
      redirect_to edit_participatory_process_path(participatory_process)
    end

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