Class: Decidim::AmendmentsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper, FormFactory, HasSpecificBreadcrumb
Defined in:
app/controllers/decidim/amendments_controller.rb

Constant Summary

Constants included from AmendmentsHelper

Decidim::AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

Methods included from ApplicationHelper

#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials

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, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title

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_select_field, #scopes_select_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, #ordered_scopes_descendants, #ordered_scopes_descendants_for_select, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from RegistersPermissions

register_permissions

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#acceptObject



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'app/controllers/decidim/amendments_controller.rb', line 151

def accept
  enforce_permission_to :accept, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::ReviewForm).from_params(params)

  Decidim::Amendable::Accept.call(@form) do
    on(:ok) do |emendation|
      flash[:notice] = t("accepted.success", scope: "decidim.amendments")
      redirect_to Decidim::ResourceLocatorPresenter.new(emendation).path
    end

    on(:invalid) do
      flash.now[:alert] = t("accepted.error", scope: "decidim.amendments")
      render :review
    end
  end
end

#createObject



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

def create
  enforce_permission_to :create, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::CreateForm).from_params(params)

  Decidim::Amendable::CreateDraft.call(@form) do
    on(:ok) do |amendment|
      flash[:notice] = t("created.success", scope: "decidim.amendments")
      redirect_to preview_draft_amend_path(amendment)
    end

    on(:invalid) do
      flash.now[:alert] = t("created.error", scope: "decidim.amendments")
      render :new
    end
  end
end

#destroy_draftObject



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

def destroy_draft
  enforce_permission_to :create, :amendment, current_component: amendable.component

  Decidim::Amendable::DestroyDraft.call(amendment, current_user) do
    on(:ok) do |amendable|
      flash[:notice] = t("success", scope: "decidim.amendments.destroy_draft")
      redirect_to new_amend_path(amendable_gid: amendable.to_sgid.to_s)
    end

    on(:invalid) do
      flash[:alert] = t("error", scope: "decidim.amendments.destroy_draft")
      redirect_to edit_draft_amend_path(amendment)
    end
  end
end

#edit_draftObject



47
48
49
50
51
# File 'app/controllers/decidim/amendments_controller.rb', line 47

def edit_draft
  enforce_permission_to :create, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::EditForm).from_model(amendment)
end

#newObject

Raises:

  • (ActionController::RoutingError)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/decidim/amendments_controller.rb', line 15

def new
  raise ActionController::RoutingError, "Not Found" unless amendable

  enforce_permission_to :create, :amendment, current_component: amendable.component

  amendment_draft = amendable.amendments.find_by(amender: current_user.id, state: "draft")

  if amendment_draft
    redirect_to edit_draft_amend_path(amendment_draft)
  else
    @form = form(Decidim::Amendable::CreateForm).from_params(params)
  end
end

#preview_draftObject



87
88
89
# File 'app/controllers/decidim/amendments_controller.rb', line 87

def preview_draft
  enforce_permission_to :create, :amendment, current_component: amendable.component
end

#promoteObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/controllers/decidim/amendments_controller.rb', line 127

def promote
  enforce_permission_to :promote, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::PromoteForm).from_model(amendment)

  Decidim::Amendable::Promote.call(@form) do
    on(:ok) do |promoted_resource|
      flash[:notice] = I18n.t("promoted.success", scope: "decidim.amendments")
      redirect_to Decidim::ResourceLocatorPresenter.new(promoted_resource).path
    end

    on(:invalid) do
      flash.now[:alert] = t("promoted.error", scope: "decidim.amendments")
      redirect_to Decidim::ResourceLocatorPresenter.new(emendation).path
    end
  end
end

#publish_draftObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/decidim/amendments_controller.rb', line 91

def publish_draft
  enforce_permission_to :create, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::PublishForm).from_model(amendment)

  Decidim::Amendable::PublishDraft.call(@form) do
    on(:ok) do |emendation|
      flash[:notice] = t("success", scope: "decidim.amendments.publish_draft")
      redirect_to Decidim::ResourceLocatorPresenter.new(emendation).path
    end

    on(:invalid) do
      flash.now[:alert] = t("error", scope: "decidim.amendments.publish_draft")
      render :edit_draft
    end
  end
end

#rejectObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/decidim/amendments_controller.rb', line 109

def reject
  enforce_permission_to :reject, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::RejectForm).from_model(amendment)

  Decidim::Amendable::Reject.call(@form) do
    on(:ok) do
      flash[:notice] = t("rejected.success", scope: "decidim.amendments")
    end

    on(:invalid) do
      flash[:alert] = t("rejected.error", scope: "decidim.amendments")
    end

    redirect_to Decidim::ResourceLocatorPresenter.new(emendation).path
  end
end

#reviewObject



145
146
147
148
149
# File 'app/controllers/decidim/amendments_controller.rb', line 145

def review
  enforce_permission_to :accept, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::ReviewForm).from_params(params)
end

#update_draftObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/decidim/amendments_controller.rb', line 53

def update_draft
  enforce_permission_to :create, :amendment, current_component: amendable.component

  @form = form(Decidim::Amendable::EditForm).from_params(params)

  Decidim::Amendable::UpdateDraft.call(@form) do
    on(:ok) do |amendment|
      flash[:notice] = t("success", scope: "decidim.amendments.update_draft")
      redirect_to preview_draft_amend_path(amendment)
    end

    on(:invalid) do
      flash.now[:alert] = t("error", scope: "decidim.amendments.update_draft")
      render :edit_draft
    end
  end
end

#withdrawObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'app/controllers/decidim/amendments_controller.rb', line 169

def withdraw
  enforce_permission_to :withdraw, :amendment, amendment:, current_component: amendable.component

  Decidim::Amendable::Withdraw.call(amendment, current_user) do
    on(:ok) do |withdrawn_emendation|
      flash[:notice] = t("success", scope: "decidim.amendments.withdraw")
      redirect_to Decidim::ResourceLocatorPresenter.new(withdrawn_emendation).path
    end

    on(:invalid) do
      flash[:alert] = t("error", scope: "decidim.amendments.withdraw")
      redirect_to Decidim::ResourceLocatorPresenter.new(emendation).path
    end
  end
end