Class: Decidim::AmendmentsController
Instance Method Summary
collapse
#cell, #edit_link, #extra_admin_link, #html_truncate, #present, #resolve_presenter_class, #step_cta_url
#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, #user_group_select_field
included, #text_editor_for
#floating_help
#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag
#default_locale?
#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #foundation_datepicker_locale_tag, #name_with_locale, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag
#normalize_provider_name, #oauth_icon, #provider_name
#snippets
#disable_http_caching
register_permissions
enhance_controller, extended, included
Instance Method Details
#accept ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 158
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
|
#compare_draft ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 45
def compare_draft
enforce_permission_to :create, :amendment, current_component: amendable.component
if similar_emendations.empty?
flash[:notice] = t("no_similars_found", scope: "decidim.amendments.compare_draft")
redirect_to edit_draft_amend_path(amendment)
end
end
|
#create ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 27
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 compare_draft_amend_path(amendment)
end
on(:invalid) do
flash.now[:alert] = t("created.error", scope: "decidim.amendments")
render :new
end
end
end
|
#destroy_draft ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 78
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_draft ⇒ Object
54
55
56
57
58
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 54
def edit_draft
enforce_permission_to :create, :amendment, current_component: amendable.component
@form = form(Decidim::Amendable::EditForm).from_model(amendment)
end
|
#new ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 13
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_draft ⇒ Object
94
95
96
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 94
def preview_draft
enforce_permission_to :create, :amendment, current_component: amendable.component
end
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 134
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_draft ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 98
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
|
#reject ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 116
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
|
#review ⇒ Object
152
153
154
155
156
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 152
def review
enforce_permission_to :accept, :amendment, current_component: amendable.component
@form = form(Decidim::Amendable::ReviewForm).from_params(params)
end
|
#update_draft ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 60
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
|
#withdraw ⇒ Object
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'app/controllers/concerns/decidim/amendments_controller.rb', line 176
def withdraw
enforce_permission_to :withdraw, :amendment, 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
|