Class: Decidim::Proposals::Admin::ProposalsController

Inherits:
ApplicationController
  • Object
show all
Includes:
ApplicationHelper, Filterable
Defined in:
app/controllers/decidim/proposals/admin/proposals_controller.rb

Overview

This controller allows admins to manage proposals in a participatory process.

Instance Method Summary collapse

Instance Method Details

#createObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 33

def create
  enforce_permission_to :create, :proposal
  @form = form(Decidim::Proposals::Admin::ProposalForm).from_params(params)

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

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

#editObject



128
129
130
131
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 128

def edit
  enforce_permission_to(:edit, :proposal, proposal:)
  @form = form(Admin::ProposalForm).from_model(proposal)
end

#indexObject



19
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 19

def index; end

#newObject



26
27
28
29
30
31
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 26

def new
  enforce_permission_to :create, :proposal
  @form = form(Decidim::Proposals::Admin::ProposalForm).from_params(
    attachment: form(AttachmentForm).from_params({})
  )
end

#publish_answersObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 79

def publish_answers
  enforce_permission_to :publish_answers, :proposals

  Decidim::Proposals::Admin::PublishAnswers.call(current_component, current_user, proposal_ids) do
    on(:invalid) do
      flash.now[:alert] = t(
        "proposals.publish_answers.select_a_proposal",
        scope: "decidim.proposals.admin"
      )
    end

    on(:ok) do
      flash.now[:notice] = I18n.t("proposals.publish_answers.success", scope: "decidim")
    end
  end

  respond_to do |format|
    format.js
  end
end

#showObject



21
22
23
24
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 21

def show
  @notes_form = form(ProposalNoteForm).instance
  @answer_form = form(Admin::ProposalAnswerForm).from_model(proposal)
end

#updateObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 133

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

  @form = form(Admin::ProposalForm).from_params(params)

  Admin::UpdateProposal.call(@form, @proposal) do
    on(:ok) do |_proposal|
      flash[:notice] = t("proposals.update.success", scope: "decidim")
      redirect_to proposals_path
    end

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

#update_categoryObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 50

def update_category
  enforce_permission_to :update, :proposal_category

  Admin::UpdateProposalCategory.call(params[:category][:id], proposal_ids) do
    on(:invalid_category) do
      flash.now[:error] = I18n.t(
        "proposals.update_category.select_a_category",
        scope: "decidim.proposals.admin"
      )
    end

    on(:invalid_proposal_ids) do
      flash.now[:alert] = I18n.t(
        "proposals.update_category.select_a_proposal",
        scope: "decidim.proposals.admin"
      )
    end

    on(:update_proposals_category) do
      flash.now[:notice] = update_proposals_bulk_response_successful(@response, :category)
      flash.now[:alert] = update_proposals_bulk_response_errored(@response, :category)
    end
  end

  respond_to do |format|
    format.js { render :update_attribute, locals: { form_selector: "#js-form-recategorize-projects", attribute_selector: "#category_id" } }
  end
end

#update_scopeObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/decidim/proposals/admin/proposals_controller.rb', line 100

def update_scope
  enforce_permission_to :update, :proposal_scope

  Admin::UpdateProposalScope.call(params[:scope_id], proposal_ids) do
    on(:invalid_scope) do
      flash.now[:error] = t(
        "proposals.update_scope.select_a_scope",
        scope: "decidim.proposals.admin"
      )
    end

    on(:invalid_proposal_ids) do
      flash.now[:alert] = t(
        "proposals.update_scope.select_a_proposal",
        scope: "decidim.proposals.admin"
      )
    end

    on(:update_proposals_scope) do
      flash.now[:notice] = update_proposals_bulk_response_successful(@response, :scope)
      flash.now[:alert] = update_proposals_bulk_response_errored(@response, :scope)
    end
  end
  respond_to do |format|
    format.js { render :update_attribute, locals: { form_selector: "#js-form-scope-change-projects", attribute_selector: "#scope_id" } }
  end
end