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


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 27

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 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


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 69

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


44
45
46
47
48
49
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 44

def edit
  @participatory_process_group = collection.find(params[:id])
  enforce_permission_to :update, :process_group, process_group: @participatory_process_group
  @form = form(ParticipatoryProcessGroupForm).from_model(@participatory_process_group)
  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


22
23
24
25
# File 'decidim-participatory_processes/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb', line 22

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

#showObject


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

def show
  enforce_permission_to :read, :process_group, process_group: participatory_process_group
  render layout: "decidim/admin/participatory_process_group"
end

#updateObject


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

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 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