Class: Decidim::Sortitions::Admin::SortitionsController

Inherits:
ApplicationController show all
Defined in:
decidim-sortitions/app/controllers/decidim/sortitions/admin/sortitions_controller.rb

Overview

Controller responsible of the sortition that selects proposals from a participatory space.

Instance Method Summary collapse

Methods inherited from ApplicationController

#sortition, #sortitions

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #skip_manage_component_permission

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

#confirm_destroyObject


64
65
66
67
68
# File 'decidim-sortitions/app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 64

def confirm_destroy
  enforce_permission_to :destroy, :sortition, sortition: sortition

  @form = destroy_sortition_form.from_model(sortition, current_participatory_space: current_participatory_space)
end

#createObject


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

def create
  enforce_permission_to :create, :sortition

  @form = sortition_form.from_params(params, current_participatory_space: current_participatory_space)
  CreateSortition.call(@form) do
    on(:ok) do |sortition|
      flash[:notice] = I18n.t("sortitions.create.success", scope: "decidim.sortitions.admin")
      redirect_to action: :show, id: sortition.id
    end

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

#destroyObject


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

def destroy
  enforce_permission_to :destroy, :sortition, sortition: sortition

  @form = destroy_sortition_form.from_params(params, current_participatory_space: current_participatory_space)
  DestroySortition.call(@form) do
    on(:ok) do |_sortition|
      flash[:notice] = I18n.t("sortitions.destroy.success", scope: "decidim.sortitions.admin")
      redirect_to action: :index
    end

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

#editObject


18
19
20
21
22
# File 'decidim-sortitions/app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 18

def edit
  enforce_permission_to :update, :sortition, sortition: sortition

  @form = edit_sortition_form.from_model(sortition, current_participatory_space: current_participatory_space)
end

#indexObject


12
# File 'decidim-sortitions/app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 12

def index; end

#newObject


41
42
43
44
45
# File 'decidim-sortitions/app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 41

def new
  enforce_permission_to :create, :sortition

  @form = sortition_form.instance(current_participatory_space: current_participatory_space)
end

#showObject


14
15
16
# File 'decidim-sortitions/app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 14

def show
  enforce_permission_to :read, :sortition, sortition: sortition
end

#updateObject


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

def update
  enforce_permission_to :update, :sortition, sortition: sortition

  @form = edit_sortition_form.from_params(params, current_participatory_space: current_participatory_space)
  UpdateSortition.call(@form) do
    on(:ok) do |_sortition|
      flash[:notice] = I18n.t("sortitions.update.success", scope: "decidim.sortitions.admin")
      redirect_to action: :index
    end

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