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

Inherits:
ApplicationController
  • Object
show all
Defined in:
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

Instance Method Details

#confirm_destroyObject



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

def confirm_destroy
  enforce_permission_to(:destroy, :sortition, sortition:)

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

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File '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:)
  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 'app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 70

def destroy
  enforce_permission_to(:destroy, :sortition, sortition:)

  @form = destroy_sortition_form.from_params(params, 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 'app/controllers/decidim/sortitions/admin/sortitions_controller.rb', line 18

def edit
  enforce_permission_to(:update, :sortition, sortition:)

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

#indexObject



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

def index; end

#newObject



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

def new
  enforce_permission_to :create, :sortition

  @form = sortition_form.instance(current_participatory_space:)
end

#showObject



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

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

#updateObject



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

def update
  enforce_permission_to(:update, :sortition, sortition:)

  @form = edit_sortition_form.from_params(params, 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