Class: Decidim::ParticipatoryProcesses::Admin::ParticipatoryProcessGroupsController

Inherits:
ApplicationController show all
Defined in:
decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb

Overview

Controller that allows managing participatory process groups.

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

#createObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 22

def create
  enforce_permission_to :create, :process_group
  @form = form(ParticipatoryProcessGroupForm).from_params(params)

  CreateParticipatoryProcessGroup.call(@form) do
    on(:ok) do |participatory_process_group|
      flash[:notice] = I18n.t("participatory_processes_group.create.success", scope: "decidim.admin")
      redirect_to edit_participatory_process_group_path(participatory_process_group)
    end

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

#destroyObject


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 64

def destroy
  @participatory_process_group = collection.find(params[:id])
  enforce_permission_to :destroy, :process_group, process_group: @participatory_process_group

  DestroyParticipatoryProcessGroup.call(@participatory_process_group, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("participatory_process_groups.destroy.success", scope: "decidim.admin")
      redirect_to action: :index
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("participatory_process_groups.destroy.error", scope: "decidim.admin")
      render :index
    end
  end
end

#editObject


39
40
41
42
43
44
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 39

def edit
  @item = collection.find(params[:id])
  enforce_permission_to :update, :process_group, process_group: @item
  @form = form(ParticipatoryProcessGroupForm).from_model(@item)
  render layout: "decidim/admin/participatory_process_group"
end

#indexObject


13
14
15
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 13

def index
  enforce_permission_to :read, :process_group
end

#newObject


17
18
19
20
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 17

def new
  enforce_permission_to :create, :process_group
  @form = form(ParticipatoryProcessGroupForm).instance
end

#updateObject


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 46

def update
  @participatory_process_group = collection.find(params[:id])
  enforce_permission_to :update, :process_group, process_group: @participatory_process_group
  @form = form(ParticipatoryProcessGroupForm).from_params(params)

  UpdateParticipatoryProcessGroup.call(@participatory_process_group, @form) do
    on(:ok) do |participatory_process_group|
      flash[:notice] = I18n.t("participatory_process_groups.update.success", scope: "decidim.admin")
      redirect_to edit_participatory_process_group_path(participatory_process_group)
    end

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