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

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

Overview

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

Instance Method Summary collapse

Methods included from ApplicationHelper

#cell, #edit_link, #extra_admin_link, #html_truncate, #present, #resolve_presenter_class, #step_cta_url

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amend_button_for, #amenders_list_for, #amendments_enabled?, #amendments_for, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

Methods included from ScopesHelper

#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag

Methods included from TranslatableAttributes

#default_locale?

Methods included from DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

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

#createObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 29

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


124
125
126
127
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 124

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

#newObject


22
23
24
25
26
27
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 22

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

#publish_answersObject


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 74

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


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

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

#updateObject


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 129

def update
  enforce_permission_to :edit, :proposal, 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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 46

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
    respond_to do |format|
      format.js
    end
  end
end

#update_scopeObject


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'decidim-proposals/app/controllers/decidim/proposals/admin/proposals_controller.rb', line 95

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

    respond_to do |format|
      format.js
    end
  end
end