decidim-debates 0.22.0 → 0.23.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/cells/decidim/debates/debate_activity_cell.rb +4 -0
- data/app/cells/decidim/debates/debate_m/data.erb +10 -8
- data/app/cells/decidim/debates/debate_m/footer.erb +5 -0
- data/app/cells/decidim/debates/debate_m_cell.rb +24 -2
- data/app/commands/decidim/debates/admin/close_debate.rb +54 -0
- data/app/commands/decidim/debates/admin/create_debate.rb +4 -2
- data/app/commands/decidim/debates/admin/update_debate.rb +5 -2
- data/app/commands/decidim/debates/close_debate.rb +58 -0
- data/app/commands/decidim/debates/create_debate.rb +17 -12
- data/app/commands/decidim/debates/update_debate.rb +56 -0
- data/app/controllers/decidim/debates/admin/debate_closes_controller.rb +43 -0
- data/app/controllers/decidim/debates/admin/debates_controller.rb +4 -2
- data/app/controllers/decidim/debates/debates_controller.rb +70 -9
- data/app/controllers/decidim/debates/orderable.rb +41 -0
- data/app/controllers/decidim/debates/versions_controller.rb +16 -0
- data/app/controllers/decidim/debates/widgets_controller.rb +19 -0
- data/app/events/decidim/debates/close_debate_event.rb +15 -0
- data/app/forms/decidim/debates/admin/close_debate_form.rb +34 -0
- data/app/forms/decidim/debates/admin/debate_form.rb +5 -1
- data/app/forms/decidim/debates/close_debate_form.rb +39 -0
- data/app/forms/decidim/debates/debate_form.rb +27 -1
- data/app/helpers/decidim/debates/admin/application_helper.rb +13 -0
- data/app/helpers/decidim/debates/application_helper.rb +37 -1
- data/app/models/decidim/debates/debate.rb +67 -12
- data/app/permissions/decidim/debates/admin/permissions.rb +3 -1
- data/app/permissions/decidim/debates/permissions.rb +28 -0
- data/app/presenters/decidim/debates/admin_log/debate_presenter.rb +6 -2
- data/app/presenters/decidim/debates/admin_log/value_types/debate_title_description_presenter.rb +20 -0
- data/app/presenters/decidim/debates/debate_presenter.rb +62 -7
- data/app/presenters/decidim/debates/log/resource_presenter.rb +18 -0
- data/app/presenters/decidim/debates/official_author_presenter.rb +1 -29
- data/app/services/decidim/debates/debate_search.rb +13 -23
- data/app/services/decidim/debates/diff_renderer.rb +27 -0
- data/app/views/decidim/debates/admin/debate_closes/edit.html.erb +17 -0
- data/app/views/decidim/debates/admin/debates/_form.html.erb +4 -4
- data/app/views/decidim/debates/admin/debates/index.html.erb +7 -1
- data/app/views/decidim/debates/debates/_close_debate_modal.html.erb +13 -0
- data/app/views/decidim/debates/debates/_debates.html.erb +7 -0
- data/app/views/decidim/debates/debates/_filters.html.erb +15 -13
- data/app/views/decidim/debates/debates/_form.html.erb +19 -0
- data/app/views/decidim/debates/debates/edit.html.erb +24 -0
- data/app/views/decidim/debates/debates/new.html.erb +7 -26
- data/app/views/decidim/debates/debates/show.html.erb +86 -14
- data/app/views/decidim/debates/versions/index.html.erb +8 -0
- data/app/views/decidim/debates/versions/show.html.erb +10 -0
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +2 -1
- data/config/locales/bg.yml +15 -0
- data/config/locales/ca.yml +70 -1
- data/config/locales/cs.yml +70 -1
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +92 -23
- data/config/locales/el.yml +2 -1
- data/config/locales/en.yml +70 -1
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +70 -1
- data/config/locales/es-PY.yml +70 -1
- data/config/locales/es.yml +70 -1
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +2 -1
- data/config/locales/fi-plain.yml +70 -1
- data/config/locales/fi.yml +70 -1
- data/config/locales/fr-CA.yml +70 -1
- data/config/locales/fr.yml +70 -1
- data/config/locales/gl.yml +7 -1
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +24 -1
- data/config/locales/id-ID.yml +2 -1
- data/config/locales/is-IS.yml +2 -1
- data/config/locales/is.yml +102 -0
- data/config/locales/it.yml +33 -1
- data/config/locales/ja-JP.yml +63 -20
- data/config/locales/ja.yml +221 -0
- data/config/locales/ko-KR.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/{lv-LV.yml → lv.yml} +0 -0
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +47 -2
- data/config/locales/no.yml +44 -1
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +58 -6
- data/config/locales/pt-BR.yml +2 -1
- data/config/locales/pt.yml +18 -1
- data/config/locales/ro-RO.yml +18 -1
- data/config/locales/ru.yml +2 -1
- data/config/locales/si-LK.yml +1 -0
- data/config/locales/sk.yml +2 -1
- data/config/locales/sl.yml +13 -1
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sv.yml +57 -1
- data/config/locales/sw-KE.yml +1 -0
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +103 -31
- data/config/locales/uk.yml +2 -1
- data/config/locales/vi-VN.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +218 -0
- data/config/locales/zh-TW.yml +1 -0
- data/db/migrate/20200703134657_close_debates.rb +9 -0
- data/db/migrate/20200708072042_fix_debates_i18n_fields.rb +48 -0
- data/db/migrate/20200716143929_add_endorsable_to_debates.rb +8 -0
- data/db/migrate/20200827154116_add_commentable_counter_cache_to_debates.rb +14 -0
- data/db/migrate/20200902133452_add_cached_comment_metadata_to_debates.rb +23 -0
- data/lib/decidim/debates/admin_engine.rb +3 -1
- data/lib/decidim/debates/component.rb +44 -1
- data/lib/decidim/debates/engine.rb +7 -1
- data/lib/decidim/debates/test/factories.rb +62 -6
- data/lib/decidim/debates/version.rb +1 -1
- metadata +62 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 664bbd747df385c87e046c4563b78d9c029958d5b38103f2155cea6a59f86599
|
4
|
+
data.tar.gz: 7b75cd3c7f303891fa3ba81d2f4e88c666cbc8f5adc19e8698eb4d0af92d74e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c96e12f56d599d9f9bf08bdec070277fa38861e46e6ba53baa4dd4bd0686a74acf773c308ccfac2681354a50a2bf3db5ac2e70a0cf3c18a55694d3154db1e42e
|
7
|
+
data.tar.gz: 1a3799201411f850752960df69a95b82d7fa142e80af78525ae23d85fda90aefb56a604d56ed278aa966c3db0ff1f8291cec153e8f6fce93c5d00a602b49a454
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</
|
1
|
+
<% if debate_date.present? %>
|
2
|
+
<div class="card__icondata">
|
3
|
+
<ul class="card-data">
|
4
|
+
<li class="card-data__item">
|
5
|
+
<%= icon "datetime", class: "icon--big", role: "img", aria_label: t("decidim.debates.debates.show.date") %>
|
6
|
+
</li>
|
7
|
+
<%= debate_date %>
|
8
|
+
</ul>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
@@ -1,5 +1,10 @@
|
|
1
1
|
<div class="card__footer">
|
2
2
|
<div class="card__support">
|
3
|
+
<% if presenter.last_comment_by %>
|
4
|
+
<% author = presenter.last_comment_by %>
|
5
|
+
<%= cell "decidim/author", author, from: model, author_name_text: t(".commented_time_ago", time: presenter.last_comment_at), context: { extra_classes: ["author-data--small"] } %>
|
6
|
+
<% end %>
|
7
|
+
|
3
8
|
<%= link_to t("participate", scope: "decidim.debates.debates.debate"), resource_path, class: "card__button button button--sc small" %>
|
4
9
|
</div>
|
5
10
|
</div>
|
@@ -11,14 +11,36 @@ module Decidim
|
|
11
11
|
render
|
12
12
|
end
|
13
13
|
|
14
|
+
def has_state?
|
15
|
+
model.closed?
|
16
|
+
end
|
17
|
+
|
18
|
+
def badge_name
|
19
|
+
I18n.t("decidim.debates.debates.closed") if model.closed?
|
20
|
+
end
|
21
|
+
|
22
|
+
def state_classes
|
23
|
+
return ["muted"] if model.closed?
|
24
|
+
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def presenter
|
29
|
+
present(model)
|
30
|
+
end
|
31
|
+
|
14
32
|
private
|
15
33
|
|
16
34
|
def title
|
17
|
-
|
35
|
+
presenter.title
|
36
|
+
end
|
37
|
+
|
38
|
+
def body
|
39
|
+
decidim_sanitize(present(model).description)
|
18
40
|
end
|
19
41
|
|
20
42
|
def description
|
21
|
-
|
43
|
+
strip_tags(body).truncate(200, separator: /\s/)
|
22
44
|
end
|
23
45
|
|
24
46
|
def resource_icon
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Debates
|
5
|
+
module Admin
|
6
|
+
# A command with all the business logic when an admin closes a debate.
|
7
|
+
class CloseDebate < Rectify::Command
|
8
|
+
# Public: Initializes the command.
|
9
|
+
#
|
10
|
+
# form - A form object with the params.
|
11
|
+
def initialize(form)
|
12
|
+
@form = form
|
13
|
+
end
|
14
|
+
|
15
|
+
# Executes the command. Broadcasts these events:
|
16
|
+
#
|
17
|
+
# - :ok when everything is valid, together with the debate.
|
18
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def call
|
22
|
+
return broadcast(:invalid) if form.invalid?
|
23
|
+
|
24
|
+
close_debate
|
25
|
+
broadcast(:ok, debate)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :form
|
31
|
+
|
32
|
+
def close_debate
|
33
|
+
@debate = Decidim.traceability.perform_action!(
|
34
|
+
:close,
|
35
|
+
form.debate,
|
36
|
+
form.current_user
|
37
|
+
) do
|
38
|
+
form.debate.update!(
|
39
|
+
conclusions: form.conclusions,
|
40
|
+
closed_at: form.closed_at
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
Decidim::EventsManager.publish(
|
45
|
+
event: "decidim.events.debates.debate_closed",
|
46
|
+
event_class: Decidim::Debates::CloseDebateEvent,
|
47
|
+
resource: debate,
|
48
|
+
followers: debate.followers
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -28,10 +28,12 @@ module Decidim
|
|
28
28
|
attr_reader :debate, :form
|
29
29
|
|
30
30
|
def create_debate
|
31
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
32
|
+
parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
|
31
33
|
params = {
|
32
34
|
category: form.category,
|
33
|
-
title:
|
34
|
-
description:
|
35
|
+
title: parsed_title,
|
36
|
+
description: parsed_description,
|
35
37
|
information_updates: form.information_updates,
|
36
38
|
instructions: form.instructions,
|
37
39
|
end_time: form.end_time,
|
@@ -30,12 +30,15 @@ module Decidim
|
|
30
30
|
attr_reader :debate, :form
|
31
31
|
|
32
32
|
def update_debate
|
33
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
34
|
+
parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
|
35
|
+
|
33
36
|
Decidim.traceability.update!(
|
34
37
|
debate,
|
35
38
|
form.current_user,
|
36
39
|
category: form.category,
|
37
|
-
title:
|
38
|
-
description:
|
40
|
+
title: parsed_title,
|
41
|
+
description: parsed_description,
|
39
42
|
information_updates: form.information_updates,
|
40
43
|
instructions: form.instructions,
|
41
44
|
end_time: form.end_time,
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Debates
|
5
|
+
# A command with all the business logic when a user updates a debate.
|
6
|
+
class CloseDebate < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# form - A form object with the params.
|
10
|
+
def initialize(form)
|
11
|
+
@form = form
|
12
|
+
end
|
13
|
+
|
14
|
+
# Executes the command. Broadcasts these events:
|
15
|
+
#
|
16
|
+
# - :ok when everything is valid, together with the debate.
|
17
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def call
|
21
|
+
return broadcast(:invalid) if form.invalid?
|
22
|
+
|
23
|
+
close_debate
|
24
|
+
broadcast(:ok, debate)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :form
|
30
|
+
|
31
|
+
def close_debate
|
32
|
+
@debate = Decidim.traceability.perform_action!(
|
33
|
+
:close,
|
34
|
+
form.debate,
|
35
|
+
form.current_user
|
36
|
+
) do
|
37
|
+
form.debate.update!(attributes)
|
38
|
+
end
|
39
|
+
|
40
|
+
Decidim::EventsManager.publish(
|
41
|
+
event: "decidim.events.debates.debate_closed",
|
42
|
+
event_class: Decidim::Debates::CloseDebateEvent,
|
43
|
+
resource: debate,
|
44
|
+
followers: debate.followers
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def attributes
|
49
|
+
{
|
50
|
+
conclusions: {
|
51
|
+
I18n.locale => form.conclusions
|
52
|
+
},
|
53
|
+
closed_at: form.closed_at
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -20,6 +20,8 @@ module Decidim
|
|
20
20
|
send_notification_to_author_followers
|
21
21
|
send_notification_to_space_followers
|
22
22
|
end
|
23
|
+
|
24
|
+
follow_debate
|
23
25
|
broadcast(:ok, debate)
|
24
26
|
end
|
25
27
|
|
@@ -27,23 +29,19 @@ module Decidim
|
|
27
29
|
|
28
30
|
attr_reader :debate, :form
|
29
31
|
|
30
|
-
def organization
|
31
|
-
@organization = form.current_component.organization
|
32
|
-
end
|
33
|
-
|
34
|
-
def i18n_field(field)
|
35
|
-
organization.available_locales.inject({}) do |i18n, locale|
|
36
|
-
i18n.update(locale => field)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
32
|
def create_debate
|
33
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
34
|
+
parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
|
41
35
|
params = {
|
42
36
|
author: form.current_user,
|
43
37
|
decidim_user_group_id: form.user_group_id,
|
44
38
|
category: form.category,
|
45
|
-
title:
|
46
|
-
|
39
|
+
title: {
|
40
|
+
I18n.locale => parsed_title
|
41
|
+
},
|
42
|
+
description: {
|
43
|
+
I18n.locale => parsed_description
|
44
|
+
},
|
47
45
|
component: form.current_component
|
48
46
|
}
|
49
47
|
|
@@ -78,6 +76,13 @@ module Decidim
|
|
78
76
|
}
|
79
77
|
)
|
80
78
|
end
|
79
|
+
|
80
|
+
def follow_debate
|
81
|
+
follow_form = Decidim::FollowForm
|
82
|
+
.from_params(followable_gid: debate.to_signed_global_id.to_s)
|
83
|
+
.with_context(current_user: debate.author)
|
84
|
+
Decidim::CreateFollow.call(follow_form, debate.author)
|
85
|
+
end
|
81
86
|
end
|
82
87
|
end
|
83
88
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Debates
|
5
|
+
# A command with all the business logic when a user updates a debate.
|
6
|
+
class UpdateDebate < Rectify::Command
|
7
|
+
# Public: Initializes the command.
|
8
|
+
#
|
9
|
+
# form - A form object with the params.
|
10
|
+
def initialize(form)
|
11
|
+
@form = form
|
12
|
+
end
|
13
|
+
|
14
|
+
# Executes the command. Broadcasts these events:
|
15
|
+
#
|
16
|
+
# - :ok when everything is valid, together with the debate.
|
17
|
+
# - :invalid if the form wasn't valid and we couldn't proceed.
|
18
|
+
#
|
19
|
+
# Returns nothing.
|
20
|
+
def call
|
21
|
+
return broadcast(:invalid) if form.invalid?
|
22
|
+
return broadcast(:invalid) unless form.debate.editable_by?(form.current_user)
|
23
|
+
|
24
|
+
update_debate
|
25
|
+
broadcast(:ok, @debate)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :form
|
31
|
+
|
32
|
+
def update_debate
|
33
|
+
@debate = Decidim.traceability.update!(
|
34
|
+
@form.debate,
|
35
|
+
@form.current_user,
|
36
|
+
attributes,
|
37
|
+
visibility: "public-only"
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def attributes
|
42
|
+
parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
|
43
|
+
parsed_description = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.description, current_organization: form.current_organization).rewrite
|
44
|
+
{
|
45
|
+
category: form.category,
|
46
|
+
title: {
|
47
|
+
I18n.locale => parsed_title
|
48
|
+
},
|
49
|
+
description: {
|
50
|
+
I18n.locale => parsed_description
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Debates
|
5
|
+
module Admin
|
6
|
+
# This controller allows an admin to close debates
|
7
|
+
class DebateClosesController < Admin::ApplicationController
|
8
|
+
helper_method :debate
|
9
|
+
|
10
|
+
def edit
|
11
|
+
enforce_permission_to :close, :debate, debate: debate
|
12
|
+
|
13
|
+
@form = form(Admin::CloseDebateForm).from_model(debate)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
enforce_permission_to :close, :debate, debate: debate
|
18
|
+
|
19
|
+
@form = form(Admin::CloseDebateForm).from_params(params)
|
20
|
+
@form.debate = debate
|
21
|
+
|
22
|
+
CloseDebate.call(@form) do
|
23
|
+
on(:ok) do |_debate|
|
24
|
+
flash[:notice] = I18n.t("debates.close.success", scope: "decidim.debates")
|
25
|
+
redirect_to debates_path
|
26
|
+
end
|
27
|
+
|
28
|
+
on(:invalid) do
|
29
|
+
flash.now[:alert] = I18n.t("debates.close.invalid", scope: "decidim.debates")
|
30
|
+
render action: "edit"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def debate
|
38
|
+
@debate ||= Debate.where(component: current_component).find(params[:id])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -5,6 +5,8 @@ module Decidim
|
|
5
5
|
module Admin
|
6
6
|
# This controller allows an admin to manage debates from a Participatory Space
|
7
7
|
class DebatesController < Decidim::Debates::Admin::ApplicationController
|
8
|
+
helper Decidim::ApplicationHelper
|
9
|
+
|
8
10
|
helper_method :debates
|
9
11
|
|
10
12
|
def index
|
@@ -38,13 +40,13 @@ module Decidim
|
|
38
40
|
def edit
|
39
41
|
enforce_permission_to :update, :debate, debate: debate
|
40
42
|
|
41
|
-
@form = form(DebateForm).from_model(debate)
|
43
|
+
@form = form(Decidim::Debates::Admin::DebateForm).from_model(debate)
|
42
44
|
end
|
43
45
|
|
44
46
|
def update
|
45
47
|
enforce_permission_to :update, :debate, debate: debate
|
46
48
|
|
47
|
-
@form = form(DebateForm).from_params(params, current_component: current_component)
|
49
|
+
@form = form(Decidim::Debates::Admin::DebateForm).from_params(params, current_component: current_component)
|
48
50
|
|
49
51
|
UpdateDebate.call(@form, debate) do
|
50
52
|
on(:ok) do
|
@@ -6,11 +6,14 @@ module Decidim
|
|
6
6
|
class DebatesController < Decidim::Debates::ApplicationController
|
7
7
|
helper Decidim::ApplicationHelper
|
8
8
|
helper Decidim::Messaging::ConversationHelper
|
9
|
+
helper Decidim::WidgetUrlsHelper
|
9
10
|
include FormFactory
|
10
11
|
include FilterResource
|
11
12
|
include Paginable
|
13
|
+
include Flaggable
|
14
|
+
include Decidim::Debates::Orderable
|
12
15
|
|
13
|
-
helper_method :debates, :debate, :paginated_debates, :report_form
|
16
|
+
helper_method :debates, :debate, :form_presenter, :paginated_debates, :report_form, :close_debate_form
|
14
17
|
|
15
18
|
def new
|
16
19
|
enforce_permission_to :create, :debate
|
@@ -21,7 +24,7 @@ module Decidim
|
|
21
24
|
def create
|
22
25
|
enforce_permission_to :create, :debate
|
23
26
|
|
24
|
-
@form = form(DebateForm).from_params(params
|
27
|
+
@form = form(DebateForm).from_params(params)
|
25
28
|
|
26
29
|
CreateDebate.call(@form) do
|
27
30
|
on(:ok) do |debate|
|
@@ -36,25 +39,80 @@ module Decidim
|
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
42
|
+
def show
|
43
|
+
raise ActionController::RoutingError, "Not Found" if debate.blank?
|
44
|
+
end
|
45
|
+
|
46
|
+
def edit
|
47
|
+
enforce_permission_to :edit, :debate, debate: debate
|
48
|
+
|
49
|
+
@form = form(DebateForm).from_model(debate)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update
|
53
|
+
enforce_permission_to :edit, :debate, debate: debate
|
54
|
+
|
55
|
+
@form = form(DebateForm).from_params(params)
|
56
|
+
@form.debate = debate
|
57
|
+
|
58
|
+
UpdateDebate.call(@form) do
|
59
|
+
on(:ok) do |debate|
|
60
|
+
flash[:notice] = I18n.t("debates.update.success", scope: "decidim.debates")
|
61
|
+
redirect_to Decidim::ResourceLocatorPresenter.new(debate).path
|
62
|
+
end
|
63
|
+
|
64
|
+
on(:invalid) do
|
65
|
+
flash.now[:alert] = I18n.t("debates.update.invalid", scope: "decidim.debates")
|
66
|
+
render :edit
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def close
|
72
|
+
enforce_permission_to :close, :debate, debate: debate
|
73
|
+
|
74
|
+
@form = form(CloseDebateForm).from_params(params)
|
75
|
+
@form.debate = debate
|
76
|
+
|
77
|
+
CloseDebate.call(@form) do
|
78
|
+
on(:ok) do |debate|
|
79
|
+
flash[:notice] = I18n.t("debates.close.success", scope: "decidim.debates")
|
80
|
+
redirect_back fallback_location: Decidim::ResourceLocatorPresenter.new(debate).path
|
81
|
+
end
|
82
|
+
|
83
|
+
on(:invalid) do
|
84
|
+
flash[:alert] = I18n.t("debates.close.invalid", scope: "decidim.debates")
|
85
|
+
redirect_back fallback_location: Decidim::ResourceLocatorPresenter.new(debate).path
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
39
90
|
private
|
40
91
|
|
92
|
+
def form_presenter
|
93
|
+
@form_presenter ||= present(@form, presenter_class: Decidim::Debates::DebatePresenter)
|
94
|
+
end
|
95
|
+
|
41
96
|
def paginated_debates
|
42
|
-
@paginated_debates ||= paginate(debates)
|
43
|
-
.includes(:category)
|
97
|
+
@paginated_debates ||= paginate(debates).includes(:category)
|
44
98
|
end
|
45
99
|
|
46
100
|
def debates
|
47
|
-
@debates ||= search.results
|
101
|
+
@debates ||= reorder(search.results)
|
48
102
|
end
|
49
103
|
|
50
104
|
def debate
|
51
|
-
@debate ||= debates.
|
105
|
+
@debate ||= debates.find_by(id: params[:id])
|
52
106
|
end
|
53
107
|
|
54
108
|
def report_form
|
55
109
|
@report_form ||= form(Decidim::ReportForm).from_params(reason: "spam")
|
56
110
|
end
|
57
111
|
|
112
|
+
def close_debate_form
|
113
|
+
@close_debate_form ||= form(CloseDebateForm).from_model(debate)
|
114
|
+
end
|
115
|
+
|
58
116
|
def search_klass
|
59
117
|
DebateSearch
|
60
118
|
end
|
@@ -69,9 +127,12 @@ module Decidim
|
|
69
127
|
def default_filter_params
|
70
128
|
{
|
71
129
|
search_text: "",
|
72
|
-
|
73
|
-
|
74
|
-
category_id:
|
130
|
+
origin: %w(official citizens user_group),
|
131
|
+
activity: "all",
|
132
|
+
category_id: default_filter_category_params,
|
133
|
+
scope_id: default_filter_scope_params,
|
134
|
+
status: "all",
|
135
|
+
state: %w(open closed)
|
75
136
|
}
|
76
137
|
end
|
77
138
|
end
|