Class: Decidim::Proposals::Admin::ProposalStatesController

Inherits:
ApplicationController
  • Object
show all
Includes:
Decidim::Paginable
Defined in:
app/controllers/decidim/proposals/admin/proposal_states_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/decidim/proposals/admin/proposal_states_controller.rb', line 19

def create
  enforce_permission_to :create, :proposal_state

  @form = form(ProposalStateForm).from_params(params)

  CreateProposalState.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("proposal_states.create.success", scope: "decidim.proposals.admin")
      redirect_to proposal_states_path
    end

    on(:invalid) do
      flash.keep[:alert] = I18n.t("proposal_states.create.error", scope: "decidim.proposals.admin")

      render action: :new
    end
  end
end

#destroyObject



62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/decidim/proposals/admin/proposal_states_controller.rb', line 62

def destroy
  enforce_permission_to(:destroy, :proposal_state, proposal_state:)

  DestroyProposalState.call(proposal_state, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("proposal_states.destroy.success", scope: "decidim.proposals.admin")

      redirect_to proposal_states_path
    end
  end
end

#editObject



38
39
40
41
# File 'app/controllers/decidim/proposals/admin/proposal_states_controller.rb', line 38

def edit
  enforce_permission_to(:update, :proposal_state, proposal_state:)
  @form = form(Decidim::Proposals::Admin::ProposalStateForm).from_model(proposal_state)
end

#indexObject



10
11
12
# File 'app/controllers/decidim/proposals/admin/proposal_states_controller.rb', line 10

def index
  enforce_permission_to :read, :proposal_state
end

#newObject



14
15
16
17
# File 'app/controllers/decidim/proposals/admin/proposal_states_controller.rb', line 14

def new
  enforce_permission_to :create, :proposal_state
  @form = form(Decidim::Proposals::Admin::ProposalStateForm).instance
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/decidim/proposals/admin/proposal_states_controller.rb', line 43

def update
  enforce_permission_to(:update, :proposal_state, proposal_state:)
  @form = form(ProposalStateForm).from_params(params)

  UpdateProposalState.call(@form, proposal_state) do
    on(:ok) do
      flash[:notice] = I18n.t("proposal_states.update.success", scope: "decidim.proposals.admin")

      redirect_to proposal_states_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("proposal_states.update.error", scope: "decidim.proposals.admin")

      render action: :edit
    end
  end
end